MessageHandler.c 937 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392
  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. struct timespec TcciQueryDeduct;
  110. }clientTime;
  111. typedef union
  112. {
  113. //Operations Initiated by Central System
  114. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  115. struct
  116. {
  117. //CsMsgValue[0]
  118. unsigned char StatusNotificationReq:1; //bit 0,
  119. unsigned char StatusNotificationConf:1; //bit 1,
  120. unsigned char TriggerMeterValue:1; //bit 2,
  121. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  122. unsigned char isOnCharging:1; //bit 4,
  123. unsigned char :3; //bit5~7
  124. }bits[CONNECTOR_QUANTITY];
  125. }CpinitiateMsg;
  126. CpinitiateMsg cpinitateMsg;
  127. //GetConfiguration Array
  128. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  129. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  130. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  131. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  132. #if 0
  133. static char *ChargePointErrorCodeStr[] = {
  134. MACROSTR(ConnectorLockFailure),
  135. MACROSTR(EVCommunicationError),
  136. MACROSTR(GroundFailure),
  137. MACROSTR(HighTemperature),
  138. MACROSTR(InternalError),
  139. MACROSTR(LocalListConflict),
  140. MACROSTR(NoError),
  141. MACROSTR(OtherError),
  142. MACROSTR(OverCurrentFailure),
  143. MACROSTR(OverVoltage),
  144. MACROSTR(PowerMeterFailure),
  145. MACROSTR(PowerSwitchFailure),
  146. MACROSTR(ReaderFailure),
  147. MACROSTR(ResetFailure),
  148. MACROSTR(UnderVoltage),
  149. MACROSTR(WeakSignal)
  150. };
  151. #endif
  152. static char * ChargePointStatusStr[] = {
  153. MACROSTR(Available),
  154. MACROSTR(Preparing),
  155. MACROSTR(Charging),
  156. MACROSTR(SuspendedEVSE),
  157. MACROSTR(SuspendedEV),
  158. MACROSTR(Finishing),
  159. MACROSTR(Reserved),
  160. MACROSTR(Unavailable),
  161. MACROSTR(Faulted)
  162. };
  163. static char *RegistrationStatusStr[] = {
  164. MACROSTR(Accepted),
  165. MACROSTR(Pending),
  166. MACROSTR(Rejected)
  167. };
  168. static char *AvailabilityTypeStr[] = {
  169. MACROSTR(Inoperative),
  170. MACROSTR(Operative)
  171. };
  172. static char *AvailabilityStatusStr[] = {
  173. MACROSTR(Accepted),
  174. MACROSTR(Rejected),
  175. MACROSTR(Scheduled)
  176. };
  177. static char *ConfigurationStatusStr[] = {
  178. MACROSTR(Accepted),
  179. MACROSTR(Rejected),
  180. MACROSTR(RebootRequired),
  181. MACROSTR(NotSupported)
  182. };
  183. static char *ClearCacheStatusStr[] = {
  184. MACROSTR(Accepted),
  185. MACROSTR(Rejected)
  186. };
  187. static char *ChargingProfilePurposeTypeStr[] = {
  188. MACROSTR(ChargePointMaxProfile),
  189. MACROSTR(TxDefaultProfile),
  190. MACROSTR(TxProfile)
  191. };
  192. static char *ChargingProfileStatusStr[] = {
  193. MACROSTR(Accepted),
  194. MACROSTR(Rejected),
  195. MACROSTR(NotSupported)
  196. };
  197. static char *ClearChargingProfileStatusStr[] = {
  198. MACROSTR(Accepted),
  199. MACROSTR(Unknown)
  200. };
  201. static char *GetCompositeScheduleStatusStr[] = {
  202. MACROSTR(Accepted),
  203. MACROSTR(Rejected)
  204. };
  205. static char *UpdateTypeStr[] = {
  206. MACROSTR(Differential),
  207. MACROSTR(Full)
  208. };
  209. static char *UpdateStatusStr[] = {
  210. MACROSTR(Accepted),
  211. MACROSTR(Failed),
  212. MACROSTR(NotSupported),
  213. MACROSTR(VersionMismatch)
  214. };
  215. static char *RemoteStartStopStatusStr[] = {
  216. MACROSTR(Accepted),
  217. MACROSTR(Rejected)
  218. };
  219. static char *ReservationStatusStr[] = {
  220. MACROSTR(Accepted),
  221. MACROSTR(Faulted),
  222. MACROSTR(Occupied),
  223. MACROSTR(Rejected),
  224. MACROSTR(Unavailable)
  225. };
  226. static char *ResetTypeStr[] = {
  227. MACROSTR(Hard),
  228. MACROSTR(Soft)
  229. };
  230. static char *ResetStatusStr[] = {
  231. MACROSTR(Accepted),
  232. MACROSTR(Rejected)
  233. };
  234. static char * DiagnosticsStatusStr[] = {
  235. MACROSTR(Idle),
  236. MACROSTR(Uploaded),
  237. MACROSTR(UploadFailed),
  238. MACROSTR(Uploading)
  239. };
  240. static char * FirmwareStatusStr[] = {
  241. MACROSTR(Downloaded),
  242. MACROSTR(DownloadFailed),
  243. MACROSTR(Downloading),
  244. MACROSTR(Idle),
  245. MACROSTR(InstallationFailed),
  246. MACROSTR(Installing),
  247. MACROSTR(Installed)
  248. };
  249. static char * MessageTriggerStr[] = {
  250. MACROSTR(BootNotification),
  251. MACROSTR(DiagnosticsStatusNotification),
  252. MACROSTR(FirmwareStatusNotification),
  253. MACROSTR(Heartbeat),
  254. MACROSTR(MeterValues),
  255. MACROSTR(StatusNotification)
  256. };
  257. static char * TriggerMessageStatusStr[] = {
  258. MACROSTR(Accepted),
  259. MACROSTR(Rejected),
  260. MACROSTR(NotImplemented)
  261. };
  262. static char * UnlockStatusStr[] = {
  263. MACROSTR(Unlocked),
  264. MACROSTR(UnlockFailed),
  265. MACROSTR(NotSupported)
  266. };
  267. #if 0
  268. static char * StopTransactionReasonStr[] = {
  269. MACROSTR(EmergencyStop),
  270. MACROSTR(EVDisconnected),
  271. MACROSTR(HardReset),
  272. MACROSTR(Local),
  273. MACROSTR(Other),
  274. MACROSTR(PowerLoss),
  275. MACROSTR(Reboot),
  276. MACROSTR(Remote),
  277. MACROSTR(SoftReset),
  278. MACROSTR(UnlockCommand),
  279. MACROSTR(DeAuthorized)
  280. };
  281. #endif
  282. static char * CancelReservationStatusStr[] = {
  283. MACROSTR(Accepted),
  284. MACROSTR(Rejected)
  285. };
  286. static char * ReadingContextStr[] = {
  287. MACROSTR(Interruption.Begin),
  288. MACROSTR(Interruption.End),
  289. MACROSTR(Other),
  290. MACROSTR(Sample.Clock),
  291. MACROSTR(Sample.Periodic),
  292. MACROSTR(Transaction.Begin),
  293. MACROSTR(Transaction.End),
  294. MACROSTR(Trigger)
  295. };
  296. static char * ValueFormatStr[] = {
  297. MACROSTR(Raw),
  298. MACROSTR(SignedData)
  299. };
  300. static char * MeasurandStr[] = {
  301. MACROSTR(Current.Export),
  302. MACROSTR(Current.Import),
  303. MACROSTR(Current.Offered),
  304. MACROSTR(Energy.Active.Export.Register),
  305. MACROSTR(Energy.Active.Import.Register),
  306. MACROSTR(Energy.Reactive.Export.Register),
  307. MACROSTR(Energy.Reactive.Import.Register),
  308. MACROSTR(Energy.Active.Export.Interval),
  309. MACROSTR(Energy.Active.Import.Interval),
  310. MACROSTR(Energy.Reactive.Export.Interval),
  311. MACROSTR(Energy.Reactive.Import.Interval),
  312. MACROSTR(Frequency),
  313. MACROSTR(Power.Active.Export),
  314. MACROSTR(Power.Active.Import),
  315. MACROSTR(Power.Factor),
  316. MACROSTR(Power.Offered),
  317. MACROSTR(Power.Reactive.ExportMACROSTR),
  318. MACROSTR(Power.Reactive.Import),
  319. MACROSTR(RPM),
  320. MACROSTR(SoC),
  321. MACROSTR(Temperature),
  322. MACROSTR(Voltage)
  323. };
  324. static char * LocationStr[] = {
  325. MACROSTR(Body),
  326. MACROSTR(Cable),
  327. MACROSTR(EV),
  328. MACROSTR(Inlet),
  329. MACROSTR(Outlet)
  330. };
  331. static char * PhaseStr[] = {
  332. MACROSTR(L1),
  333. MACROSTR(L2),
  334. MACROSTR(L3),
  335. MACROSTR(N),
  336. MACROSTR(L1-N),
  337. MACROSTR(L2-N),
  338. MACROSTR(L3-N),
  339. MACROSTR(L1-L2),
  340. MACROSTR(L2-L3),
  341. MACROSTR(L3-L1)
  342. };
  343. static char * UnitOfMeasureStr[] = {
  344. MACROSTR(Wh),
  345. MACROSTR(kWh),
  346. MACROSTR(varh),
  347. MACROSTR(kvarh),
  348. MACROSTR(W),
  349. MACROSTR(kW),
  350. MACROSTR(VA),
  351. MACROSTR(kVA),
  352. MACROSTR(var),
  353. MACROSTR(kvar),
  354. MACROSTR(A),
  355. MACROSTR(V),
  356. MACROSTR(Celsius),
  357. MACROSTR(Fahrenheit),
  358. MACROSTR(K),
  359. MACROSTR(Percent)
  360. };
  361. //=========================================
  362. // TTIA routine
  363. //=========================================
  364. int sendTTIAInfo(uint8_t gun_index)
  365. {
  366. static int sn = 0;
  367. int result = FAIL;
  368. struct hostent *server;
  369. int udp_socket_fd;
  370. struct sockaddr_in dest_addr = {0};
  371. uint8_t tx_buf[80] = {0};
  372. uint8_t logBuf[256]= {0};
  373. uint8_t tx_len, tempIndex, socStart, socEnd;
  374. uint16_t PresentChargedEnergy;
  375. struct tm tmStart, tmEnd;
  376. DEBUG_INFO("sendTTIAInfo...\n");
  377. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  378. {
  379. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  380. {
  381. tempIndex = ((gun_index==2) ? 1: 0);
  382. }
  383. else
  384. {
  385. tempIndex = gun_index;
  386. }
  387. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  388. {
  389. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  390. {
  391. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  392. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  393. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  394. }
  395. }
  396. }
  397. else if(gunType[gun_index] == GUN_TYPE_CCS)
  398. {
  399. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  400. {
  401. tempIndex = ((gun_index==2) ? 1: 0);
  402. }
  403. else
  404. {
  405. tempIndex = gun_index;
  406. }
  407. for (int index = 0; index < CCS_QUANTITY; index++)
  408. {
  409. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  410. {
  411. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  412. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  413. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  414. }
  415. }
  416. }
  417. else if(gunType[gun_index] == GUN_TYPE_GBT)
  418. {
  419. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  420. {
  421. tempIndex = ((gun_index==2) ? 1: 0);
  422. }
  423. else
  424. {
  425. tempIndex = gun_index;
  426. }
  427. for (int index = 0; index < GB_QUANTITY; index++)
  428. {
  429. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  430. {
  431. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  432. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  433. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  434. }
  435. }
  436. }
  437. else if(gunType[gun_index] == GUN_TYPE_DO)
  438. {
  439. tempIndex = gun_index;
  440. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  441. {
  442. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  443. {
  444. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  445. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  446. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  447. }
  448. }
  449. }
  450. else
  451. {
  452. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  453. {
  454. tempIndex = 2;
  455. }
  456. else
  457. {
  458. tempIndex = gun_index;
  459. }
  460. for (int index = 0; index < AC_QUANTITY; index++)
  461. {
  462. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  463. {
  464. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  465. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  466. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  467. }
  468. }// END
  469. }
  470. // Message assembly
  471. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  472. tx_buf[4] = 0x02; // Protocol Version
  473. tx_buf[5] = 0xb0; // Message ID
  474. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  475. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  476. tx_buf[8] = 0x00; // CarID low byte
  477. tx_buf[9] = 0x00; // CarID high byte
  478. tx_buf[10] = 0x00; // ID Storage
  479. tx_buf[11] = 0x00; // Driver lowest byte
  480. tx_buf[12] = 0x00; // Driver 2nd byte
  481. tx_buf[13] = 0x00; // Driver 3rd byte
  482. tx_buf[14] = 0x00; // Driver highest byte
  483. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  484. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  485. tx_buf[17] = 0x00; // Reserve
  486. tx_buf[18] = 60 & 0xff; // Payload length low byte
  487. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  488. // EVSE provider
  489. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  490. // EVSE provider
  491. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  492. // EVSE id
  493. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  494. // Connector id
  495. tx_buf[37] = gun_index;
  496. // EVSE station
  497. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  498. // Vehicle SN
  499. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  500. // Mileage
  501. tx_buf[61] = 0x00; // lowest byte
  502. tx_buf[62] = 0x00; // 2nd byte
  503. tx_buf[63] = 0x00; // highest byte
  504. // Start date time 6 bytes
  505. if((sscanf((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6))
  506. {
  507. struct tm *tmTarget;
  508. struct timeb tbTarget;
  509. tmStart.tm_year -= 1900;
  510. tmStart.tm_mon -= 1;
  511. tmStart.tm_gmtoff = 0;
  512. tbTarget.time = mktime(&tmStart);
  513. tbTarget.timezone = 0;
  514. tbTarget.time += (8*3600);
  515. tmTarget = gmtime(&tbTarget.time);
  516. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  517. tx_buf[65] = (tmTarget->tm_mon+1);
  518. tx_buf[66] = tmTarget->tm_mday;
  519. tx_buf[67] = tmTarget->tm_hour;
  520. tx_buf[68] = tmTarget->tm_min;
  521. tx_buf[69] = tmTarget->tm_sec;
  522. }
  523. // Stop date time 6 bytes
  524. if((sscanf((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmEnd.tm_year, &tmEnd.tm_mon, &tmEnd.tm_mday, &tmEnd.tm_hour, &tmEnd.tm_min, &tmEnd.tm_sec) == 6))
  525. {
  526. struct tm *tmTarget;
  527. struct timeb tbTarget;
  528. tmEnd.tm_year -= 1900;
  529. tmEnd.tm_mon -= 1;
  530. tmEnd.tm_gmtoff = 0;
  531. tbTarget.time = mktime(&tmEnd);
  532. tbTarget.timezone = 0;
  533. tbTarget.time += (8*3600);
  534. tmTarget = gmtime(&tbTarget.time);
  535. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  536. tx_buf[71] = (tmTarget->tm_mon+1);
  537. tx_buf[72] = tmTarget->tm_mday;
  538. tx_buf[73] = tmTarget->tm_hour;
  539. tx_buf[74] = tmTarget->tm_min;
  540. tx_buf[75] = tmTarget->tm_sec;
  541. }
  542. // Session energy 2 bytes
  543. tx_buf[76] = PresentChargedEnergy & 0xff;
  544. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  545. // Start SOC 1 byte
  546. tx_buf[78] = socStart;
  547. // Stop SOC 1 byte
  548. tx_buf[79] = socEnd;
  549. // Open socket
  550. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  551. if(udp_socket_fd == -1)
  552. {
  553. DEBUG_ERROR("UDP socket create failed!\n");
  554. }
  555. else
  556. {
  557. // Get server DNS entry
  558. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  559. if (server == NULL)
  560. {
  561. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  562. }
  563. else
  564. {
  565. // Build the server's Internet address
  566. bzero((char *) &dest_addr, sizeof(dest_addr));
  567. dest_addr.sin_family = AF_INET;
  568. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  569. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  570. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  571. {
  572. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  573. {
  574. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  575. }
  576. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  577. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  578. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  579. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  580. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  581. DEBUG_TTIA_INFO("---------- Header ----------\n");
  582. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  583. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  584. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  585. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  586. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  587. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  588. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  589. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  590. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  591. DEBUG_TTIA_INFO("Len: 0x3C\n");
  592. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  593. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  594. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  595. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  596. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  597. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  598. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  599. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  600. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  601. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  602. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  603. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  604. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  605. DEBUG_TTIA_INFO("=========================================\n");
  606. sn++;
  607. result = PASS;
  608. }
  609. else
  610. {
  611. DEBUG_ERROR("UDP sent out fail.\n");
  612. }
  613. }
  614. }
  615. return result;
  616. }
  617. //=========================================
  618. // Save configuration
  619. //=========================================
  620. int runShellCmd(const char*cmd)
  621. {
  622. int result = FAIL;
  623. char buf[256];
  624. FILE *fp;
  625. fp = popen(cmd, "r");
  626. if(fp != NULL)
  627. {
  628. while(fgets(buf, sizeof(buf), fp) != NULL)
  629. {
  630. DEBUG_INFO("%s\n", buf);
  631. }
  632. result = PASS;
  633. }
  634. pclose(fp);
  635. return result;
  636. }
  637. int StoreUsrConfigData(struct SysConfigData *UsrData)
  638. {
  639. int result = PASS;
  640. int fd,wrd;
  641. unsigned int i,Chk;
  642. unsigned char *ptr, *BufTmp;
  643. int MtdBlockSize = 0x300000;
  644. Chk=0;
  645. ptr=(unsigned char *)UsrData;
  646. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  647. {
  648. memset(BufTmp,0,MtdBlockSize);
  649. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  650. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  651. Chk+=*(BufTmp+i);
  652. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  653. // Output configuration to file.
  654. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  655. if (fd < 0)
  656. {
  657. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  658. free(BufTmp);
  659. return 0;
  660. }
  661. wrd=write(fd, BufTmp, MtdBlockSize);
  662. close(fd);
  663. if(wrd<MtdBlockSize)
  664. {
  665. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  666. free(BufTmp);
  667. return 0;
  668. }
  669. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  670. DEBUG_INFO("Erase /dev/mtd10.\n");
  671. runShellCmd("flash_erase /dev/mtd10 0 0");
  672. DEBUG_INFO("Write /dev/mtd10.\n");
  673. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  674. DEBUG_INFO("Erase /dev/mtd11.\n");
  675. runShellCmd("flash_erase /dev/mtd11 0 0");
  676. DEBUG_INFO("Write /dev/mtd11.\n");
  677. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  678. system("rm -f /mnt/EvseConfig.bin");
  679. DEBUG_INFO("EvseConfig write to flash OK\n");
  680. }
  681. else
  682. {
  683. DEBUG_ERROR("alloc BlockSize NG\r\n");
  684. result = FAIL;
  685. }
  686. if(BufTmp!=NULL)
  687. free(BufTmp);
  688. return result;
  689. }
  690. //=========================================
  691. // Sqlite3 related function
  692. //=========================================
  693. static int selectSqlCount = 0;
  694. static int callback(void *data, int argc, char **argv, char **azColName){
  695. int i;
  696. //printf("%s: ", (const char*)data);
  697. selectSqlCount = argc;
  698. for(i = 0; i<argc; i++){
  699. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  700. }
  701. //printf("\n");
  702. return 0;
  703. }
  704. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  705. //int i;
  706. //printf("%s:\n", (const char*)data);
  707. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  708. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  709. return 0;
  710. }
  711. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  712. //printf("%s:\n", (const char*)data);
  713. //idTag
  714. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  715. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  716. //parentIdTag
  717. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  718. //expir_date
  719. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  720. //status
  721. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  722. //version
  723. if(columenCount > 5)
  724. idTagQuery.listVersionInt = atoi(columnValue[5]);
  725. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  726. return 0;
  727. }
  728. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  729. {
  730. // localversion = argv[5] ? atoi(argv[5]) : 0;
  731. // printf("localversion=%d\n", localversion);
  732. return 0;
  733. }
  734. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  735. {
  736. for (int i = 0; i < n_columns; i++)
  737. {
  738. DEBUG_INFO("%s\t", col_values[i]);
  739. }
  740. DEBUG_INFO("\n");
  741. return 0;
  742. }
  743. int OCPP_cleanLocalCache()
  744. {
  745. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  746. char *errMsg = 0;
  747. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  748. if (SQLITE_OK != rc)
  749. {
  750. DEBUG_INFO("SQL error: %s\n",errMsg);
  751. return FALSE;
  752. }
  753. return TRUE;
  754. }
  755. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  756. {
  757. int isSuccess = TRUE;
  758. int ret = 0;
  759. //const char* data = "Callback function called";
  760. char sql[300];
  761. char zErrMsg[200];
  762. memset(sql, 0, 300);
  763. memset(zErrMsg, 0, 200);
  764. sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
  765. //* Execute SQL statement */
  766. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  767. if( ret != SQLITE_OK )
  768. {
  769. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  770. isSuccess = FALSE;
  771. }
  772. return isSuccess;
  773. }
  774. void OCPP_getIdTagFromLocalCache(char idTag[])
  775. {
  776. int rc = 0;
  777. char sql[100];
  778. char zErrMsg[100];
  779. memset(sql, 0, 100);
  780. memset(zErrMsg, 0, 100);
  781. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  782. memset(&idTagQuery, 0, sizeof(idTagQuery));
  783. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  784. /* Execute SQL statement */
  785. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  786. if( rc != SQLITE_OK )
  787. {
  788. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  789. }
  790. }
  791. void OCPP_getListVerion()
  792. {
  793. int rc = 0;
  794. // const char* data = "Callback function called";
  795. char sql[100];
  796. char zErrMsg[100];
  797. memset(sql, 0, 100);
  798. memset(zErrMsg, 0, 100);
  799. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  800. /* Execute SQL statement */
  801. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  802. if( rc != SQLITE_OK )
  803. {
  804. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  805. }
  806. }
  807. void OCPP_get_TableAuthlocalAllData(void)
  808. {
  809. int rc = 0;
  810. char sql[100];
  811. char zErrMsg[100];
  812. memset(sql, 0, 100);
  813. memset(zErrMsg, 0, 100);
  814. sprintf(sql,"select * from ocpp_auth_local ");
  815. /* Execute SQL statement */
  816. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  817. if( rc != SQLITE_OK )
  818. {
  819. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  820. }
  821. //return ver;
  822. }
  823. int OCPP_cleanLocalList()
  824. {
  825. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  826. char *errMsg = 0;
  827. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  828. if (SQLITE_OK != rc)
  829. {
  830. DEBUG_INFO("%s\n",errMsg);
  831. return FALSE;
  832. }
  833. return TRUE;
  834. }
  835. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  836. {
  837. int isSuccess = FALSE;
  838. int ret = 0;
  839. //const char* data = "Callback function called";
  840. char sql[300];
  841. char zErrMsg[200];
  842. memset(sql, 0, 300);
  843. memset(zErrMsg, 0, 200);
  844. sprintf(sql,"insert or replace into ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ""SELECT * from ocpp_auth_local", idTag, parentTage, expiryDate, status, version);
  845. //* Execute SQL statement */
  846. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  847. if( ret != SQLITE_OK )
  848. {
  849. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  850. return isSuccess;
  851. }
  852. memset(sql, 0, 300);
  853. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  854. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  855. if( ret != SQLITE_OK )
  856. {
  857. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  858. return isSuccess;
  859. }
  860. isSuccess = TRUE;
  861. return isSuccess;
  862. }
  863. void OCPP_getIdTagFromLocalList(char idTag[])
  864. {
  865. int rc = 0;
  866. // const char* data = "Callback function called";
  867. char sql[100];
  868. char zErrMsg[100];
  869. memset(sql, 0, 100);
  870. memset(zErrMsg, 0, 100);
  871. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  872. memset(&idTagQuery, 0, sizeof(idTagQuery));
  873. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  874. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  875. /* Execute SQL statement */
  876. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  877. if( rc != SQLITE_OK )
  878. {
  879. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  880. }
  881. //return ver;
  882. }
  883. void OCPP_deleteIdTagFromLocalList(char idTag[])
  884. {
  885. //int ver = 0;
  886. //int isSuccess = FALSE;
  887. int rc = 0;
  888. char sql[100];
  889. char zErrMsg[100];
  890. memset(sql, 0, 100);
  891. memset(zErrMsg, 0, 100);
  892. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  893. //* Execute SQL statement */
  894. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  895. if( rc != SQLITE_OK )
  896. {
  897. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  898. }
  899. }
  900. int getCurrentYear()
  901. {
  902. int result = 0;
  903. time_t CurrentTime;
  904. struct tm *tm;
  905. CurrentTime = time(NULL);
  906. tm=localtime(&CurrentTime);
  907. result = (tm->tm_year + 1900);
  908. return result;
  909. }
  910. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  911. {
  912. int result = PASS;
  913. char* errMsg = NULL;
  914. char sqlStr[8192];
  915. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  916. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  917. {
  918. result = FAIL;
  919. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  920. }
  921. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  922. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  923. {
  924. result = FAIL;
  925. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  926. }
  927. return result;
  928. }
  929. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  930. {
  931. int isSuccess = TRUE;
  932. int tempIndex;
  933. json_object *EnergyDataTransfer = json_object_new_object();
  934. json_object *periodEnergys = json_object_new_object();
  935. char sql[1024];
  936. char zErrMsg[200];
  937. memset(sql, 0, ARRAY_SIZE(sql));
  938. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  939. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  940. {
  941. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  942. {
  943. tempIndex = ((gun_index==2) ? 1: 0);
  944. }
  945. else
  946. {
  947. tempIndex = gun_index;
  948. }
  949. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  950. {
  951. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  952. {
  953. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  954. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  955. {
  956. uint8_t period[3];
  957. sprintf((char*)period, "%d", idxPeriod);
  958. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  959. }
  960. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  961. } //end of the same index
  962. }//end of for CHAdeMO_QUANTITY
  963. }
  964. else if(gunType[gun_index] == GUN_TYPE_CCS)
  965. {
  966. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  967. {
  968. tempIndex = ((gun_index==2) ? 1: 0);
  969. }
  970. else
  971. {
  972. tempIndex = gun_index;
  973. }
  974. for (int index = 0; index < CCS_QUANTITY; index++)
  975. {
  976. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  977. {
  978. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  979. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  980. {
  981. uint8_t period[3];
  982. sprintf((char*)period, "%d", idxPeriod);
  983. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  984. }
  985. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  986. } //end of the same index
  987. } // end of for CCS_QUANTITY
  988. }
  989. else if(gunType[gun_index] == GUN_TYPE_GBT)
  990. {
  991. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  992. {
  993. tempIndex = ((gun_index==2) ? 1: 0);
  994. }
  995. else
  996. {
  997. tempIndex = gun_index;
  998. }
  999. for (int index = 0; index < GB_QUANTITY; index++)
  1000. {
  1001. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1002. {
  1003. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1004. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1005. {
  1006. uint8_t period[3];
  1007. sprintf((char*)period, "%d", idxPeriod);
  1008. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1009. }
  1010. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1011. } //end of the same index
  1012. } // end of for GB_QUANTITY
  1013. }
  1014. else if(gunType[gun_index] == GUN_TYPE_DO)
  1015. {
  1016. tempIndex = gun_index;
  1017. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1018. {
  1019. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1020. {
  1021. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1022. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1023. {
  1024. uint8_t period[3];
  1025. sprintf((char*)period, "%d", idxPeriod);
  1026. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1027. }
  1028. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1029. } //end of the same index
  1030. }
  1031. }
  1032. else
  1033. {
  1034. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1035. {
  1036. tempIndex = 2;
  1037. }
  1038. else
  1039. {
  1040. tempIndex = gun_index;
  1041. }
  1042. for (int index = 0; index < AC_QUANTITY; index++)
  1043. {
  1044. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1045. {
  1046. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1047. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1048. {
  1049. uint8_t period[3];
  1050. sprintf((char*)period, "%d", idxPeriod);
  1051. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1052. }
  1053. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1054. }//end of the same index
  1055. }//end of for AC_QUANTITY
  1056. }
  1057. sprintf(sql, "insert or replace into ocpp_period_energy (transactionId, connectorId, occurDatetime, periodEnergy) VALUES ('%d', '%d', CURRENT_TIMESTAMP, '%s');", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, (gun_index+1), json_object_to_json_string_ext(EnergyDataTransfer, JSON_C_TO_STRING_PLAIN));
  1058. json_object_put(EnergyDataTransfer);
  1059. //* Execute SQL statement */
  1060. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1061. {
  1062. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1063. isSuccess = FALSE;
  1064. }
  1065. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1066. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1067. {
  1068. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1069. isSuccess = FALSE;
  1070. }
  1071. return isSuccess;
  1072. }
  1073. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1074. {
  1075. int isSuccess = TRUE;
  1076. char sql[512];
  1077. char zErrMsg[200];
  1078. int rows, cols;
  1079. char **resultData;
  1080. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1081. /* Execute SQL statement */
  1082. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1083. {
  1084. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1085. isSuccess = FALSE;
  1086. }
  1087. else
  1088. {
  1089. if((rows > 0) && (atoi(resultData[4]) > 0))
  1090. {
  1091. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1092. }
  1093. else
  1094. {
  1095. DEBUG_WARN("There is not match transaction data.\n");
  1096. isSuccess = FALSE;
  1097. }
  1098. }
  1099. return isSuccess;
  1100. }
  1101. int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice, double amount, char *vemData, char *ROC, char *RRN, char *approvalNo, char *storeId)
  1102. {
  1103. int result = PASS;
  1104. char* errMsg = NULL;
  1105. char sqlStr[8192];
  1106. sprintf(sqlStr, "insert or replace into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '%s', '%s', '%s', '%s', '0');",
  1107. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  1108. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1109. {
  1110. result = FAIL;
  1111. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  1112. }
  1113. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  1114. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1115. {
  1116. result = FAIL;
  1117. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  1118. }
  1119. return result;
  1120. }
  1121. int OCPP_update_deduct_info(int txId, char *creditNo)
  1122. {
  1123. int result = PASS;
  1124. char* errMsg = NULL;
  1125. char sqlStr[8192];
  1126. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  1127. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1128. {
  1129. result = FAIL;
  1130. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  1131. }
  1132. return result;
  1133. }
  1134. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1135. {
  1136. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1137. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  1138. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  1139. atoi(columnValue[1]),
  1140. columnValue[2],
  1141. atoi(columnValue[3])==1?"true":"false",
  1142. atoi(columnValue[4])==1?"true":"false",
  1143. columnValue[5],
  1144. columnValue[9]);
  1145. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1146. return 0;
  1147. }
  1148. void OCPP_query_deduct_info()
  1149. {
  1150. int rc = 0;
  1151. char sql[100];
  1152. char zErrMsg[100];
  1153. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1154. /* Execute SQL statement */
  1155. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1156. if( rc != SQLITE_OK )
  1157. {
  1158. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1159. }
  1160. }
  1161. void reportReaderStatus(int gun_index)
  1162. {
  1163. struct timeval tmnow;
  1164. struct tm *tm;
  1165. char buf[28];//, usec_buf[6];
  1166. gettimeofday(&tmnow, NULL);
  1167. time_t t;
  1168. t = time(NULL);
  1169. /*UTC time and date*/
  1170. tm = gmtime(&t);
  1171. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1172. #if 0 // remove temporally
  1173. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1174. strcat(buf,".");
  1175. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1176. strcat(buf,usec_buf);
  1177. #endif
  1178. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1179. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_ReaderStatus");
  1180. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "{\\\"connectorId\\\":%d,\\\"readerStatus\\\":%d,\\\"timestamp\\\":\\\"%s\\\",\\\"SerialNo\\\":\\\"%s\\\",\\\"creditNo\\\":\\\"%s\\\",\\\"VEMData\\\":\\\"%s\\\"}",
  1181. (gun_index+1),
  1182. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus,
  1183. buf,
  1184. ShmOCPP16Data->TcciCustomData.SerialNo[gun_index],
  1185. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo,
  1186. ShmOCPP16Data->TcciCustomData.VEMData[gun_index]);
  1187. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1188. }
  1189. //==========================================
  1190. // Check time passed since today
  1191. //==========================================
  1192. long long DiffTimebWithNow(struct timeb ST)
  1193. {
  1194. //return milli-second
  1195. struct timeb ET;
  1196. long long StartTime,StopTime;
  1197. ftime(&ET);
  1198. StartTime=(long long)ST.time;
  1199. StopTime=(long long)ET.time;
  1200. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1201. }
  1202. int getTimePassSinceToday(uint8_t gun_index)
  1203. {
  1204. int result = -1;
  1205. static time_t lastTime[4];
  1206. time_t t;
  1207. struct tm *tmStartToday;
  1208. struct timeb tbStartToday;
  1209. t=time(NULL);
  1210. if(difftime(t, lastTime[gun_index])>0)
  1211. {
  1212. tmStartToday=localtime(&t);
  1213. tmStartToday->tm_hour = 0;
  1214. tmStartToday->tm_min = 0;
  1215. tmStartToday->tm_sec = 0;
  1216. tbStartToday.time = mktime(tmStartToday);
  1217. tbStartToday.millitm = 0;
  1218. result = DiffTimebWithNow(tbStartToday)/1000;
  1219. lastTime[gun_index] = t;
  1220. }
  1221. return result;
  1222. }
  1223. void getNowDatetime(uint8_t *data)
  1224. {
  1225. time_t t = time(NULL);
  1226. struct tm tm = *localtime(&t);
  1227. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  1228. }
  1229. int syncDateTimeRTC(uint8_t *data)
  1230. {
  1231. struct ParsingResult
  1232. {
  1233. int result;
  1234. int scanedElement;
  1235. int year;
  1236. int month;
  1237. int mday;
  1238. int hour;
  1239. int min;
  1240. int sec;
  1241. int tz_hour;
  1242. int tz_min;
  1243. float minSec;
  1244. }result;
  1245. struct tm tmOrg;
  1246. struct tm *tmTarget;
  1247. struct timeb tbTarget;
  1248. char buf[128];
  1249. memset(&result, 0x00, sizeof(struct ParsingResult));
  1250. result.result = PASS;
  1251. if(strstr((char*)data, ".") != NULL)
  1252. {
  1253. // Original data with mini second
  1254. if(strstr((char*)data, "Z") != NULL)
  1255. {
  1256. // Original data with Z
  1257. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1258. &result.year,
  1259. &result.month,
  1260. &result.mday,
  1261. &result.hour,
  1262. &result.min,
  1263. &result.sec,
  1264. &result.minSec);
  1265. }
  1266. else
  1267. {
  1268. // Original data without Z
  1269. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1270. &result.year,
  1271. &result.month,
  1272. &result.mday,
  1273. &result.hour,
  1274. &result.min,
  1275. &result.sec,
  1276. &result.minSec,
  1277. &result.tz_hour,
  1278. &result.tz_min);
  1279. }
  1280. }
  1281. else
  1282. {
  1283. // Original data without mini second
  1284. if(strstr((char*)data, "Z") != NULL)
  1285. {
  1286. // Original data with Z
  1287. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1288. &result.year,
  1289. &result.month,
  1290. &result.mday,
  1291. &result.hour,
  1292. &result.min,
  1293. &result.sec);
  1294. }
  1295. else
  1296. {
  1297. // Original data without Z
  1298. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1299. &result.year,
  1300. &result.month,
  1301. &result.mday,
  1302. &result.hour,
  1303. &result.min,
  1304. &result.sec,
  1305. &result.tz_hour,
  1306. &result.tz_min);
  1307. }
  1308. }
  1309. tmOrg.tm_year = result.year - 1900;
  1310. tmOrg.tm_mon = result.month - 1;
  1311. tmOrg.tm_mday = result.mday;
  1312. tmOrg.tm_hour = result.hour;
  1313. tmOrg.tm_min = result.min;
  1314. tmOrg.tm_sec = result.sec;
  1315. tmOrg.tm_gmtoff = 0;
  1316. tbTarget.time = mktime(&tmOrg);
  1317. tbTarget.timezone = 0;
  1318. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1319. tmTarget = gmtime(&tbTarget.time);
  1320. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  1321. //DEBUG_INFO(" org date time: %s\n", data);
  1322. //DEBUG_INFO("parse date time: %s\n", buf);
  1323. system(buf);
  1324. system("/sbin/hwclock -w --systohc");
  1325. if(result.scanedElement < 6)
  1326. result.result = FAIL;
  1327. return result.result;
  1328. }
  1329. //==========================================
  1330. // GetCompositeSchedule logic related function
  1331. //==========================================
  1332. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1333. {
  1334. //return milli-second
  1335. unsigned int StartTime,StopTime;
  1336. StartTime=(unsigned int)ST.time;
  1337. StopTime=(unsigned int)ET.time;
  1338. return (StopTime-StartTime);
  1339. }
  1340. int DiffTimebWithNowSec(struct timeb ST)
  1341. {
  1342. //return milli-second
  1343. struct timeb ET;
  1344. unsigned int StartTime,StopTime;
  1345. ftime(&ET);
  1346. StartTime=(unsigned int)ST.time;
  1347. StopTime=(unsigned int)ET.time;
  1348. return (StopTime-StartTime);
  1349. }
  1350. int getStartStop(uint8_t *start, uint8_t *stop)
  1351. {
  1352. int result = -1;
  1353. struct tm tmStart;
  1354. struct timeb tbStart;
  1355. struct tm tmStop;
  1356. struct timeb tbStop;
  1357. 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) &&
  1358. (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))
  1359. {
  1360. //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);
  1361. //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);
  1362. tmStart.tm_year -= 1900;
  1363. tmStart.tm_mon -= 1;
  1364. tbStart.time = mktime(&tmStart);
  1365. tbStart.millitm = 0;
  1366. tmStop.tm_year -= 1900;
  1367. tmStop.tm_mon -= 1;
  1368. tbStop.time = mktime(&tmStop);
  1369. tbStop.millitm = 0;
  1370. result = DiffTimebSec(tbStart, tbStop);
  1371. //DEBUG_INFO("getStartStop(): %d\n", result);
  1372. }
  1373. else
  1374. {
  1375. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1376. }
  1377. return result;
  1378. }
  1379. int isOvertNow(uint8_t *start)
  1380. {
  1381. int result = NO;
  1382. struct ParsingResult
  1383. {
  1384. int result;
  1385. int scanedElement;
  1386. int year;
  1387. int month;
  1388. int mday;
  1389. int hour;
  1390. int min;
  1391. int sec;
  1392. int tz_hour;
  1393. int tz_min;
  1394. float minSec;
  1395. }parsingResult;
  1396. struct tm tmStart;
  1397. struct timeb tbStart;
  1398. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1399. if(strstr((char*)start, ".") != NULL)
  1400. {
  1401. // Original data with mini second
  1402. if(strstr((char*)start, "Z") != NULL)
  1403. {
  1404. // Original data with Z
  1405. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1406. &parsingResult.year,
  1407. &parsingResult.month,
  1408. &parsingResult.mday,
  1409. &parsingResult.hour,
  1410. &parsingResult.min,
  1411. &parsingResult.sec,
  1412. &parsingResult.minSec);
  1413. }
  1414. else
  1415. {
  1416. // Original data without Z
  1417. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1418. &parsingResult.year,
  1419. &parsingResult.month,
  1420. &parsingResult.mday,
  1421. &parsingResult.hour,
  1422. &parsingResult.min,
  1423. &parsingResult.sec,
  1424. &parsingResult.minSec,
  1425. &parsingResult.tz_hour,
  1426. &parsingResult.tz_min);
  1427. }
  1428. }
  1429. else
  1430. {
  1431. // Original data without mini second
  1432. if(strstr((char*)start, "Z") != NULL)
  1433. {
  1434. // Original data with Z
  1435. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1436. &parsingResult.year,
  1437. &parsingResult.month,
  1438. &parsingResult.mday,
  1439. &parsingResult.hour,
  1440. &parsingResult.min,
  1441. &parsingResult.sec);
  1442. }
  1443. else
  1444. {
  1445. // Original data without Z
  1446. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1447. &parsingResult.year,
  1448. &parsingResult.month,
  1449. &parsingResult.mday,
  1450. &parsingResult.hour,
  1451. &parsingResult.min,
  1452. &parsingResult.sec,
  1453. &parsingResult.tz_hour,
  1454. &parsingResult.tz_min);
  1455. }
  1456. }
  1457. if(parsingResult.scanedElement >= 6)
  1458. {
  1459. tmStart.tm_year = parsingResult.year - 1900;
  1460. tmStart.tm_mon = parsingResult.month - 1;
  1461. tmStart.tm_mday = parsingResult.mday;
  1462. tmStart.tm_hour = parsingResult.hour;
  1463. tmStart.tm_min = parsingResult.min;
  1464. tmStart.tm_sec = parsingResult.sec;
  1465. tmStart.tm_gmtoff = 0;
  1466. tbStart.time = mktime(&tmStart);
  1467. tbStart.timezone = 0;
  1468. tbStart.millitm = 0;
  1469. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1470. if(DiffTimebWithNowSec(tbStart) <= 0)
  1471. result = NO;
  1472. else
  1473. result = YES;
  1474. }
  1475. else
  1476. {
  1477. DEBUG_WARN("Start date parsing error.\n");
  1478. }
  1479. return result;
  1480. }
  1481. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1482. {
  1483. int result = -1;
  1484. struct tm tmStart;
  1485. struct timeb tbStart;
  1486. struct tm tmStop;
  1487. struct timeb tbStop;
  1488. 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) &&
  1489. (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))
  1490. {
  1491. tmStart.tm_year -= 1900;
  1492. tmStart.tm_mon -= 1;
  1493. tbStart.time = mktime(&tmStart);
  1494. tbStart.millitm = 0;
  1495. tmStop.tm_year -= 1900;
  1496. tmStop.tm_mon -= 1;
  1497. tbStop.time = mktime(&tmStop);
  1498. tbStop.millitm = 0;
  1499. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1500. }
  1501. return result;
  1502. }
  1503. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1504. {
  1505. FILE *fp;
  1506. char profileFileName[128];
  1507. char *line = NULL;
  1508. size_t len = 0;
  1509. time_t CurrentTime;
  1510. struct tm *tmComposite;
  1511. struct StructChargingProfile maxProfile;
  1512. struct StructChargingProfile compositeProfile;
  1513. uint8_t limitMax=0;
  1514. int compositePeriodIdx = 0;
  1515. CurrentTime = time(NULL);
  1516. tmComposite=localtime(&CurrentTime);
  1517. 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);
  1518. if(isUnitA)
  1519. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1520. else
  1521. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1522. compositeProfile.ChargingSchedule.Duration = durationReq;
  1523. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1524. {
  1525. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1526. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1527. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1528. }
  1529. compositeProfile.ChargingProfileId = 0;
  1530. compositeProfile.StackLevel = 99 ;
  1531. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1532. maxProfile.ChargingProfileId = -1;
  1533. maxProfile.ChargingSchedule.Duration = -1;
  1534. system("rm -f /tmp/*.json");
  1535. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1536. // Search max profile
  1537. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1538. if((access(profileFileName, F_OK))!=-1)
  1539. {
  1540. fp = fopen(profileFileName, "r");
  1541. while(getline(&line, &len, fp) != -1)
  1542. {
  1543. json_object *obj = NULL;
  1544. obj = json_tokener_parse(line);
  1545. if(is_error(obj))
  1546. {
  1547. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1548. }
  1549. else
  1550. {
  1551. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1552. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1553. )
  1554. {
  1555. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1556. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1557. )
  1558. {
  1559. struct tm tmFrom, tmTo;
  1560. struct timeb tbFrom, tbTo;
  1561. 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) &&
  1562. (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))
  1563. {
  1564. tmFrom.tm_year -= 1900;
  1565. tmFrom.tm_mon -= 1;
  1566. tbFrom.time = mktime(&tmFrom);
  1567. tmTo.tm_year -= 1900;
  1568. tmTo.tm_mon -= 1;
  1569. tbTo.time = mktime(&tmTo);
  1570. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1571. {
  1572. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1573. {
  1574. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1575. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1576. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1577. }
  1578. maxProfile.ChargingProfileId = -1;
  1579. maxProfile.StackLevel = -1;
  1580. if(maxProfile.ChargingProfileId == -1)
  1581. DEBUG_INFO("MaxProfile found.\n");
  1582. else
  1583. DEBUG_INFO("MaxProfile updated.\n");
  1584. // Required item
  1585. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1586. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1587. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1588. if(isUnitA)
  1589. {
  1590. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1591. 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++)
  1592. {
  1593. 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"));
  1594. 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?
  1595. 3:
  1596. 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")));
  1597. 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")));
  1598. }
  1599. }
  1600. else
  1601. {
  1602. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  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(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));
  1610. }
  1611. }
  1612. // Optional item
  1613. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1614. {
  1615. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1616. }
  1617. else
  1618. {
  1619. sprintf((char*)maxProfile.ValidFrom, " ");
  1620. }
  1621. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1622. {
  1623. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1624. }
  1625. else
  1626. {
  1627. sprintf((char*)maxProfile.ValidTo, " ");
  1628. }
  1629. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1630. {
  1631. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1632. }
  1633. else
  1634. {
  1635. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1636. }
  1637. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1638. {
  1639. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1640. }
  1641. else
  1642. {
  1643. maxProfile.TransactionId = -1;
  1644. }
  1645. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1646. {
  1647. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1648. }
  1649. else
  1650. {
  1651. maxProfile.ChargingSchedule.Duration = 86400;
  1652. }
  1653. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1654. {
  1655. 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")));
  1656. }
  1657. else
  1658. {
  1659. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1660. }
  1661. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1662. {
  1663. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1664. }
  1665. else
  1666. {
  1667. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1668. }
  1669. }
  1670. }
  1671. }
  1672. else
  1673. {
  1674. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1675. {
  1676. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1677. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1678. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1679. }
  1680. maxProfile.ChargingProfileId = -1;
  1681. maxProfile.StackLevel = -1;
  1682. if(maxProfile.ChargingProfileId == -1)
  1683. DEBUG_INFO("MaxProfile found.\n");
  1684. else
  1685. DEBUG_INFO("MaxProfile updated.\n");
  1686. // Required item
  1687. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1688. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1689. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1690. if(isUnitA)
  1691. {
  1692. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1693. 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++)
  1694. {
  1695. 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"));
  1696. 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?
  1697. 3:
  1698. 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")));
  1699. 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")));
  1700. }
  1701. }
  1702. else
  1703. {
  1704. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1705. 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++)
  1706. {
  1707. 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"));
  1708. 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?
  1709. 3:
  1710. 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")));
  1711. 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));
  1712. }
  1713. }
  1714. // Optional item
  1715. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1716. {
  1717. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1718. }
  1719. else
  1720. {
  1721. sprintf((char*)maxProfile.ValidFrom, " ");
  1722. }
  1723. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1724. {
  1725. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1726. }
  1727. else
  1728. {
  1729. sprintf((char*)maxProfile.ValidTo, " ");
  1730. }
  1731. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1732. {
  1733. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1734. }
  1735. else
  1736. {
  1737. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1738. }
  1739. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1740. {
  1741. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1742. }
  1743. else
  1744. {
  1745. maxProfile.TransactionId = -1;
  1746. }
  1747. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1748. {
  1749. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1750. }
  1751. else
  1752. {
  1753. maxProfile.ChargingSchedule.Duration = 86400;
  1754. }
  1755. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1756. {
  1757. 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")));
  1758. }
  1759. else
  1760. {
  1761. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1762. }
  1763. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1764. {
  1765. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1766. }
  1767. else
  1768. {
  1769. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1770. }
  1771. }
  1772. }
  1773. }
  1774. json_object_put(obj);
  1775. }
  1776. fclose(fp);
  1777. /*
  1778. if(maxProfile.ChargingProfileId !=-1)
  1779. {
  1780. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1781. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1782. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1783. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1784. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1785. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1786. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1787. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1788. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1789. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1790. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1791. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1792. {
  1793. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1794. {
  1795. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1796. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1797. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1798. }
  1799. }
  1800. }
  1801. else
  1802. DEBUG_INFO("MaxProfile not found.\n");
  1803. DEBUG_INFO("------------------------------------\n");*/
  1804. }
  1805. if(maxProfile.ChargingProfileId != -1)
  1806. {
  1807. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1808. {
  1809. if(maxProfile.ChargingSchedule.Duration != -1)
  1810. {
  1811. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1812. 0:
  1813. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1814. }
  1815. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1816. {
  1817. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1818. {
  1819. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1820. 0:
  1821. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1822. if(idxPeriod > 0)
  1823. {
  1824. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1825. {
  1826. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1827. }
  1828. }
  1829. }
  1830. }
  1831. }
  1832. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1833. {
  1834. if(maxProfile.ChargingSchedule.Duration != -1)
  1835. {
  1836. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1837. }
  1838. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1839. {
  1840. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1841. {
  1842. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1843. if(idxPeriod > 0)
  1844. {
  1845. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1846. {
  1847. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1848. }
  1849. }
  1850. }
  1851. }
  1852. }
  1853. else
  1854. {
  1855. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1856. {
  1857. if(maxProfile.ChargingSchedule.Duration != -1)
  1858. {
  1859. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1860. 0:
  1861. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1862. }
  1863. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1864. {
  1865. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1866. {
  1867. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1868. 0:
  1869. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1870. if(idxPeriod > 0)
  1871. {
  1872. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1873. {
  1874. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1875. }
  1876. }
  1877. }
  1878. }
  1879. }
  1880. else
  1881. {
  1882. if(maxProfile.ChargingSchedule.Duration != -1)
  1883. {
  1884. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1885. 0:
  1886. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1887. }
  1888. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1889. {
  1890. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1891. {
  1892. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1893. 0:
  1894. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1895. if(idxPeriod > 0)
  1896. {
  1897. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1898. {
  1899. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1900. }
  1901. }
  1902. }
  1903. }
  1904. }
  1905. }
  1906. /*
  1907. DEBUG_INFO("MaxProfile after align.\n");
  1908. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1909. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1910. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1911. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1912. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1913. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1914. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1915. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1916. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1917. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1918. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1919. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1920. {
  1921. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1922. {
  1923. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1924. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1925. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1926. }
  1927. }
  1928. DEBUG_INFO("------------------------------------\n");*/
  1929. }
  1930. // Find each profile period quantity
  1931. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1932. {
  1933. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1934. limitMax = idx+1;
  1935. }
  1936. if(maxProfile.ChargingProfileId != -1)
  1937. {
  1938. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1939. {
  1940. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1941. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1942. (maxProfile.ChargingSchedule.Duration > 0))
  1943. {
  1944. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1945. {
  1946. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1947. compositePeriodIdx++;
  1948. }
  1949. else
  1950. {
  1951. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1952. }
  1953. }
  1954. }
  1955. }
  1956. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1957. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  1958. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  1959. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  1960. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1961. {
  1962. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1963. {
  1964. compositeProfile.ChargingProfileId = 1;
  1965. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1966. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1967. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1968. }
  1969. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1970. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1971. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1972. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1973. }
  1974. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  1975. if(line)
  1976. free(line);
  1977. }
  1978. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1979. {
  1980. FILE *fp;
  1981. char profileFileName[128];
  1982. char *line = NULL;
  1983. size_t len = 0;
  1984. time_t CurrentTime;
  1985. struct tm *tmComposite;
  1986. struct StructChargingProfile maxProfile;
  1987. struct StructChargingProfile defaultTxProfile;
  1988. struct StructChargingProfile txProfile;
  1989. struct StructChargingProfile compositeProfile;
  1990. struct StructChargingSchedulePeriod tmpPeriod;
  1991. uint8_t limitMax=0;
  1992. uint8_t limitDef=0;
  1993. uint8_t limitTx=0;
  1994. int compositePeriodIdx = 0;
  1995. CurrentTime = time(NULL);
  1996. tmComposite=localtime(&CurrentTime);
  1997. 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);
  1998. if(isUnitA)
  1999. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2000. else
  2001. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2002. compositeProfile.ChargingSchedule.Duration = durationReq;
  2003. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2004. {
  2005. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2006. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2007. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2008. }
  2009. compositeProfile.ChargingProfileId = 0;
  2010. compositeProfile.StackLevel = 99 ;
  2011. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2012. maxProfile.ChargingProfileId = -1;
  2013. defaultTxProfile.ChargingProfileId = -1;
  2014. txProfile.ChargingProfileId = -1;
  2015. maxProfile.ChargingSchedule.Duration = -1;
  2016. defaultTxProfile.ChargingSchedule.Duration = -1;
  2017. txProfile.ChargingSchedule.Duration = -1;
  2018. system("rm -f /tmp/*.json");
  2019. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2020. /*
  2021. * Search valid charging profile
  2022. */
  2023. //DEBUG_INFO("====================================\n");
  2024. // Search tx profile
  2025. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2026. if((access(profileFileName, F_OK))!=-1)
  2027. {
  2028. fp = fopen(profileFileName, "r");
  2029. while(getline(&line, &len, fp) != -1)
  2030. {
  2031. json_object *obj = NULL;
  2032. obj = json_tokener_parse(line);
  2033. if(is_error(obj))
  2034. {
  2035. DEBUG_ERROR("Parse txProfile from file error.\n");
  2036. }
  2037. else
  2038. {
  2039. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2040. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2041. )
  2042. {
  2043. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2044. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2045. )
  2046. {
  2047. struct tm tmFrom, tmTo;
  2048. struct timeb tbFrom, tbTo;
  2049. 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) &&
  2050. (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))
  2051. {
  2052. tmFrom.tm_year -= 1900;
  2053. tmFrom.tm_mon -= 1;
  2054. tbFrom.time = mktime(&tmFrom);
  2055. tmTo.tm_year -= 1900;
  2056. tmTo.tm_mon -= 1;
  2057. tbTo.time = mktime(&tmTo);
  2058. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2059. {
  2060. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2061. {
  2062. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2063. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2064. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2065. }
  2066. txProfile.ChargingProfileId = -1;
  2067. txProfile.StackLevel = -1;
  2068. if(txProfile.ChargingProfileId == -1)
  2069. DEBUG_INFO("TxProfile found.\n");
  2070. else
  2071. DEBUG_INFO("TxProfile updated.\n");
  2072. // Required item
  2073. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2074. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2075. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2076. if(isUnitA)
  2077. {
  2078. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2079. 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++)
  2080. {
  2081. 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"));
  2082. 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?
  2083. 3:
  2084. 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")));
  2085. 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")));
  2086. }
  2087. }
  2088. else
  2089. {
  2090. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2091. 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++)
  2092. {
  2093. 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"));
  2094. 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?
  2095. 3:
  2096. 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")));
  2097. 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));
  2098. }
  2099. }
  2100. // Optional item
  2101. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2102. {
  2103. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2104. }
  2105. else
  2106. {
  2107. sprintf((char*)txProfile.ValidFrom, " ");
  2108. }
  2109. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2110. {
  2111. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2112. }
  2113. else
  2114. {
  2115. sprintf((char*)txProfile.ValidTo, " ");
  2116. }
  2117. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2118. {
  2119. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2120. }
  2121. else
  2122. {
  2123. sprintf((char*)txProfile.RecurrencyKind, " ");
  2124. }
  2125. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2126. {
  2127. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2128. }
  2129. else
  2130. {
  2131. txProfile.TransactionId = -1;
  2132. }
  2133. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2134. {
  2135. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2136. }
  2137. else
  2138. {
  2139. txProfile.ChargingSchedule.Duration = 86400;
  2140. }
  2141. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2142. {
  2143. 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")));
  2144. }
  2145. else
  2146. {
  2147. 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));
  2148. }
  2149. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2150. {
  2151. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2152. }
  2153. else
  2154. {
  2155. txProfile.ChargingSchedule.MinChargingRate = -1;
  2156. }
  2157. }
  2158. }
  2159. }
  2160. else
  2161. {
  2162. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2163. {
  2164. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2165. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2166. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2167. }
  2168. txProfile.ChargingProfileId = -1;
  2169. txProfile.StackLevel = -1;
  2170. if(txProfile.ChargingProfileId == -1)
  2171. DEBUG_INFO("TxProfile found.\n");
  2172. else
  2173. DEBUG_INFO("TxProfile updated.\n");
  2174. // Required item
  2175. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2176. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2177. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2178. if(isUnitA)
  2179. {
  2180. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2181. 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++)
  2182. {
  2183. 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"));
  2184. 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?
  2185. 3:
  2186. 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")));
  2187. 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")));
  2188. }
  2189. }
  2190. else
  2191. {
  2192. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2193. 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++)
  2194. {
  2195. 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"));
  2196. 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?
  2197. 3:
  2198. 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")));
  2199. 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));
  2200. }
  2201. }
  2202. // Optional item
  2203. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2204. {
  2205. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2206. }
  2207. else
  2208. {
  2209. sprintf((char*)txProfile.ValidFrom, " ");
  2210. }
  2211. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2212. {
  2213. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2214. }
  2215. else
  2216. {
  2217. sprintf((char*)txProfile.ValidTo, " ");
  2218. }
  2219. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2220. {
  2221. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2222. }
  2223. else
  2224. {
  2225. sprintf((char*)txProfile.RecurrencyKind, " ");
  2226. }
  2227. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2228. {
  2229. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2230. }
  2231. else
  2232. {
  2233. txProfile.TransactionId = -1;
  2234. }
  2235. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2236. {
  2237. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2238. }
  2239. else
  2240. {
  2241. txProfile.ChargingSchedule.Duration = 86400;
  2242. }
  2243. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2244. {
  2245. 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")));
  2246. }
  2247. else
  2248. {
  2249. 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));
  2250. }
  2251. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2252. {
  2253. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2254. }
  2255. else
  2256. {
  2257. txProfile.ChargingSchedule.MinChargingRate = -1;
  2258. }
  2259. }
  2260. }
  2261. }
  2262. json_object_put(obj);
  2263. }
  2264. fclose(fp);
  2265. /*
  2266. if(txProfile.ChargingProfileId != -1)
  2267. {
  2268. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2269. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2270. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2271. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2272. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2273. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2274. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2275. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2276. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2277. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2278. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2279. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2280. {
  2281. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2282. {
  2283. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2284. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2285. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2286. }
  2287. }
  2288. }
  2289. else
  2290. DEBUG_INFO("TxProfile not found.\n");*/
  2291. }
  2292. // Search default tx profile
  2293. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2294. if((access(profileFileName, F_OK))==-1)
  2295. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2296. if((access(profileFileName, F_OK))!=-1)
  2297. {
  2298. fp = fopen(profileFileName, "r");
  2299. while(getline(&line, &len, fp) != -1)
  2300. {
  2301. json_object *obj = NULL;
  2302. obj = json_tokener_parse(line);
  2303. if(is_error(obj))
  2304. {
  2305. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2306. }
  2307. else
  2308. {
  2309. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2310. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2311. )
  2312. {
  2313. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2314. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2315. )
  2316. {
  2317. struct tm tmFrom, tmTo;
  2318. struct timeb tbFrom, tbTo;
  2319. 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) &&
  2320. (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))
  2321. {
  2322. tmFrom.tm_year -= 1900;
  2323. tmFrom.tm_mon -= 1;
  2324. tbFrom.time = mktime(&tmFrom);
  2325. tmTo.tm_year -= 1900;
  2326. tmTo.tm_mon -= 1;
  2327. tbTo.time = mktime(&tmTo);
  2328. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2329. {
  2330. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2331. {
  2332. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2333. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2334. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2335. }
  2336. defaultTxProfile.ChargingProfileId = -1;
  2337. defaultTxProfile.StackLevel = -1;
  2338. if(defaultTxProfile.ChargingProfileId == -1)
  2339. DEBUG_INFO("TxDefaultProfile found.\n");
  2340. else
  2341. DEBUG_INFO("TxDefaultProfile updated.\n");
  2342. // Required item
  2343. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2344. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2345. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2346. if(isUnitA)
  2347. {
  2348. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2349. 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++)
  2350. {
  2351. 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"));
  2352. 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?
  2353. 3:
  2354. 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")));
  2355. 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")));
  2356. }
  2357. }
  2358. else
  2359. {
  2360. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2361. 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++)
  2362. {
  2363. 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"));
  2364. 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?
  2365. 3:
  2366. 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")));
  2367. 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));
  2368. }
  2369. }
  2370. // Optional item
  2371. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2372. {
  2373. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2374. }
  2375. else
  2376. {
  2377. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2378. }
  2379. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2380. {
  2381. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2382. }
  2383. else
  2384. {
  2385. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2386. }
  2387. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2388. {
  2389. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2390. }
  2391. else
  2392. {
  2393. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2394. }
  2395. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2396. {
  2397. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2398. }
  2399. else
  2400. {
  2401. defaultTxProfile.TransactionId = -1;
  2402. }
  2403. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2404. {
  2405. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2406. }
  2407. else
  2408. {
  2409. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2410. }
  2411. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2412. {
  2413. 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")));
  2414. }
  2415. else
  2416. {
  2417. 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));
  2418. }
  2419. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2420. {
  2421. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2422. }
  2423. else
  2424. {
  2425. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2426. }
  2427. }
  2428. }
  2429. }
  2430. else
  2431. {
  2432. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2433. {
  2434. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2435. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2436. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2437. }
  2438. defaultTxProfile.ChargingProfileId = -1;
  2439. defaultTxProfile.StackLevel = -1;
  2440. if(defaultTxProfile.ChargingProfileId == -1)
  2441. DEBUG_INFO("TxDefaultProfile found.\n");
  2442. else
  2443. DEBUG_INFO("TxDefaultProfile updated.\n");
  2444. // Required item
  2445. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2446. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2447. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2448. if(isUnitA)
  2449. {
  2450. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2451. 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++)
  2452. {
  2453. 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"));
  2454. 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?
  2455. 3:
  2456. 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")));
  2457. 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")));
  2458. }
  2459. }
  2460. else
  2461. {
  2462. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2463. 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++)
  2464. {
  2465. 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"));
  2466. 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?
  2467. 3:
  2468. 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")));
  2469. 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));
  2470. }
  2471. }
  2472. // Optional item
  2473. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2474. {
  2475. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2476. }
  2477. else
  2478. {
  2479. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2480. }
  2481. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2482. {
  2483. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2484. }
  2485. else
  2486. {
  2487. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2488. }
  2489. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2490. {
  2491. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2492. }
  2493. else
  2494. {
  2495. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2496. }
  2497. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2498. {
  2499. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2500. }
  2501. else
  2502. {
  2503. defaultTxProfile.TransactionId = -1;
  2504. }
  2505. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2506. {
  2507. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2508. }
  2509. else
  2510. {
  2511. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2512. }
  2513. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2514. {
  2515. 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")));
  2516. }
  2517. else
  2518. {
  2519. 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));
  2520. }
  2521. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2522. {
  2523. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2524. }
  2525. else
  2526. {
  2527. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2528. }
  2529. }
  2530. }
  2531. }
  2532. json_object_put(obj);
  2533. }
  2534. fclose(fp);
  2535. /*
  2536. if(defaultTxProfile.ChargingProfileId != -1)
  2537. {
  2538. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2539. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2540. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2541. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2542. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2543. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2544. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2545. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2546. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2547. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2548. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2549. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2550. {
  2551. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2552. {
  2553. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2554. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2555. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2556. }
  2557. }
  2558. }
  2559. else
  2560. DEBUG_INFO("TxDefaultProfile not found.\n");
  2561. DEBUG_INFO("------------------------------------\n");*/
  2562. }
  2563. // Search max profile
  2564. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2565. if((access(profileFileName, F_OK))!=-1)
  2566. {
  2567. fp = fopen(profileFileName, "r");
  2568. while(getline(&line, &len, fp) != -1)
  2569. {
  2570. json_object *obj = NULL;
  2571. obj = json_tokener_parse(line);
  2572. if(is_error(obj))
  2573. {
  2574. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2575. }
  2576. else
  2577. {
  2578. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2579. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2580. )
  2581. {
  2582. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2583. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2584. )
  2585. {
  2586. struct tm tmFrom, tmTo;
  2587. struct timeb tbFrom, tbTo;
  2588. 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) &&
  2589. (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))
  2590. {
  2591. tmFrom.tm_year -= 1900;
  2592. tmFrom.tm_mon -= 1;
  2593. tbFrom.time = mktime(&tmFrom);
  2594. tmTo.tm_year -= 1900;
  2595. tmTo.tm_mon -= 1;
  2596. tbTo.time = mktime(&tmTo);
  2597. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2598. {
  2599. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2600. {
  2601. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2602. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2603. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2604. }
  2605. maxProfile.ChargingProfileId = -1;
  2606. maxProfile.StackLevel = -1;
  2607. if(maxProfile.ChargingProfileId == -1)
  2608. DEBUG_INFO("MaxProfile found.\n");
  2609. else
  2610. DEBUG_INFO("MaxProfile updated.\n");
  2611. // Required item
  2612. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2613. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2614. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2615. if(isUnitA)
  2616. {
  2617. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2618. 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++)
  2619. {
  2620. 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"));
  2621. 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?
  2622. 3:
  2623. 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")));
  2624. 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")));
  2625. }
  2626. }
  2627. else
  2628. {
  2629. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2630. 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++)
  2631. {
  2632. 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"));
  2633. 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?
  2634. 3:
  2635. 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")));
  2636. 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));
  2637. }
  2638. }
  2639. // Optional item
  2640. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2641. {
  2642. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2643. }
  2644. else
  2645. {
  2646. sprintf((char*)maxProfile.ValidFrom, " ");
  2647. }
  2648. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2649. {
  2650. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2651. }
  2652. else
  2653. {
  2654. sprintf((char*)maxProfile.ValidTo, " ");
  2655. }
  2656. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2657. {
  2658. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2659. }
  2660. else
  2661. {
  2662. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2663. }
  2664. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2665. {
  2666. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2667. }
  2668. else
  2669. {
  2670. maxProfile.TransactionId = -1;
  2671. }
  2672. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2673. {
  2674. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2675. }
  2676. else
  2677. {
  2678. maxProfile.ChargingSchedule.Duration = 86400;
  2679. }
  2680. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2681. {
  2682. 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")));
  2683. }
  2684. else
  2685. {
  2686. 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));
  2687. }
  2688. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2689. {
  2690. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2691. }
  2692. else
  2693. {
  2694. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2695. }
  2696. }
  2697. }
  2698. }
  2699. else
  2700. {
  2701. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2702. {
  2703. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2704. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2705. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2706. }
  2707. maxProfile.ChargingProfileId = -1;
  2708. maxProfile.StackLevel = -1;
  2709. if(maxProfile.ChargingProfileId == -1)
  2710. DEBUG_INFO("MaxProfile found.\n");
  2711. else
  2712. DEBUG_INFO("MaxProfile updated.\n");
  2713. // Required item
  2714. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2715. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2716. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2717. if(isUnitA)
  2718. {
  2719. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2720. 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++)
  2721. {
  2722. 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"));
  2723. 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?
  2724. 3:
  2725. 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")));
  2726. 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")));
  2727. }
  2728. }
  2729. else
  2730. {
  2731. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2732. 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++)
  2733. {
  2734. 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"));
  2735. 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?
  2736. 3:
  2737. 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")));
  2738. 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));
  2739. }
  2740. }
  2741. // Optional item
  2742. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2743. {
  2744. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2745. }
  2746. else
  2747. {
  2748. sprintf((char*)maxProfile.ValidFrom, " ");
  2749. }
  2750. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2751. {
  2752. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2753. }
  2754. else
  2755. {
  2756. sprintf((char*)maxProfile.ValidTo, " ");
  2757. }
  2758. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2759. {
  2760. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2761. }
  2762. else
  2763. {
  2764. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2765. }
  2766. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2767. {
  2768. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2769. }
  2770. else
  2771. {
  2772. maxProfile.TransactionId = -1;
  2773. }
  2774. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2775. {
  2776. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2777. }
  2778. else
  2779. {
  2780. maxProfile.ChargingSchedule.Duration = 86400;
  2781. }
  2782. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2783. {
  2784. 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")));
  2785. }
  2786. else
  2787. {
  2788. 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));
  2789. }
  2790. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2791. {
  2792. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2793. }
  2794. else
  2795. {
  2796. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2797. }
  2798. }
  2799. }
  2800. }
  2801. json_object_put(obj);
  2802. }
  2803. fclose(fp);
  2804. /*
  2805. if(maxProfile.ChargingProfileId !=-1)
  2806. {
  2807. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2808. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2809. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2810. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2811. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2812. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2813. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2814. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2815. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2816. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2817. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2818. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2819. {
  2820. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2821. {
  2822. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2823. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2824. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2825. }
  2826. }
  2827. }
  2828. else
  2829. DEBUG_INFO("MaxProfile not found.\n");
  2830. DEBUG_INFO("------------------------------------\n");*/
  2831. }
  2832. /*
  2833. * Align found profile start schedule & periods
  2834. */
  2835. //DEBUG_INFO("====================================\n");
  2836. /*
  2837. // For local test usage, force modify found profile start schedule info
  2838. 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);
  2839. 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);
  2840. 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);
  2841. */
  2842. if(txProfile.ChargingProfileId != -1)
  2843. {
  2844. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2845. {
  2846. if(txProfile.ChargingSchedule.Duration != -1)
  2847. {
  2848. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2849. 0:
  2850. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2851. }
  2852. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2853. {
  2854. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2855. {
  2856. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2857. 0:
  2858. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2859. if(idxPeriod > 0)
  2860. {
  2861. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2862. {
  2863. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2864. }
  2865. }
  2866. }
  2867. }
  2868. }
  2869. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2870. {
  2871. if(txProfile.ChargingSchedule.Duration != -1)
  2872. {
  2873. 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?
  2874. 0:
  2875. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2876. }
  2877. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2878. {
  2879. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2880. {
  2881. 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?
  2882. 0:
  2883. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2884. if(idxPeriod > 0)
  2885. {
  2886. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2887. {
  2888. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2889. }
  2890. }
  2891. }
  2892. }
  2893. }
  2894. else
  2895. {
  2896. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2897. {
  2898. if(txProfile.ChargingSchedule.Duration != -1)
  2899. {
  2900. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2901. 0:
  2902. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2903. }
  2904. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2905. {
  2906. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2907. {
  2908. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2909. 0:
  2910. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2911. if(idxPeriod > 0)
  2912. {
  2913. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2914. {
  2915. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2916. }
  2917. }
  2918. }
  2919. }
  2920. }
  2921. else
  2922. {
  2923. if(txProfile.ChargingSchedule.Duration != -1)
  2924. {
  2925. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2926. 0:
  2927. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2928. }
  2929. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2930. {
  2931. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2932. {
  2933. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2934. 0:
  2935. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2936. if(idxPeriod > 0)
  2937. {
  2938. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2939. {
  2940. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2941. }
  2942. }
  2943. }
  2944. }
  2945. }
  2946. }
  2947. /*
  2948. DEBUG_INFO("txProfile after align.\n");
  2949. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2950. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2951. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2952. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2953. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2954. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2955. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2956. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2957. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2958. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2959. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2960. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2961. {
  2962. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2963. {
  2964. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2965. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2966. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2967. }
  2968. }*/
  2969. }
  2970. if(defaultTxProfile.ChargingProfileId != -1)
  2971. {
  2972. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2973. {
  2974. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2975. {
  2976. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2977. 0:
  2978. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2979. }
  2980. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2981. {
  2982. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2983. {
  2984. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2985. 0:
  2986. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2987. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2988. {
  2989. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2990. }
  2991. if(idxPeriod > 0)
  2992. {
  2993. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2994. {
  2995. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2996. }
  2997. }
  2998. }
  2999. }
  3000. }
  3001. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  3002. {
  3003. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3004. {
  3005. 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?
  3006. 0:
  3007. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3008. }
  3009. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3010. {
  3011. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3012. {
  3013. 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?
  3014. 0:
  3015. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3016. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  3017. {
  3018. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3019. }
  3020. if(idxPeriod > 0)
  3021. {
  3022. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3023. {
  3024. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3025. }
  3026. }
  3027. }
  3028. }
  3029. }
  3030. else
  3031. {
  3032. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3033. {
  3034. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3035. {
  3036. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3037. 0:
  3038. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3039. }
  3040. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3041. {
  3042. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3043. {
  3044. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3045. 0:
  3046. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3047. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  3048. {
  3049. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3050. }
  3051. if(idxPeriod > 0)
  3052. {
  3053. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3054. {
  3055. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3056. }
  3057. }
  3058. }
  3059. }
  3060. }
  3061. else
  3062. {
  3063. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3064. {
  3065. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3066. 0:
  3067. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3068. }
  3069. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3070. {
  3071. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3072. {
  3073. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3074. 0:
  3075. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3076. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  3077. {
  3078. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3079. }
  3080. if(idxPeriod > 0)
  3081. {
  3082. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3083. {
  3084. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3085. }
  3086. }
  3087. }
  3088. }
  3089. }
  3090. }
  3091. /*
  3092. DEBUG_INFO("defaultTxProfile after align.\n");
  3093. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3094. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3095. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3096. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3097. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3098. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3099. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3100. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3101. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3102. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3103. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3104. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3105. {
  3106. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3107. {
  3108. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3109. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3110. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3111. }
  3112. }
  3113. DEBUG_INFO("------------------------------------\n");*/
  3114. }
  3115. if(maxProfile.ChargingProfileId != -1)
  3116. {
  3117. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3118. {
  3119. if(maxProfile.ChargingSchedule.Duration != -1)
  3120. {
  3121. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3122. 0:
  3123. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3124. }
  3125. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3126. {
  3127. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3128. {
  3129. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3130. 0:
  3131. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3132. if(idxPeriod > 0)
  3133. {
  3134. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3135. {
  3136. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3137. }
  3138. }
  3139. }
  3140. }
  3141. }
  3142. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3143. {
  3144. if(maxProfile.ChargingSchedule.Duration != -1)
  3145. {
  3146. 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?
  3147. 0:
  3148. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3149. }
  3150. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3151. {
  3152. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3153. {
  3154. 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?
  3155. 0:
  3156. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3157. if(idxPeriod > 0)
  3158. {
  3159. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3160. {
  3161. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3162. }
  3163. }
  3164. }
  3165. }
  3166. }
  3167. else
  3168. {
  3169. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3170. {
  3171. if(maxProfile.ChargingSchedule.Duration != -1)
  3172. {
  3173. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3174. 0:
  3175. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3176. }
  3177. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3178. {
  3179. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3180. {
  3181. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3182. 0:
  3183. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3184. if(idxPeriod > 0)
  3185. {
  3186. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3187. {
  3188. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3189. }
  3190. }
  3191. }
  3192. }
  3193. }
  3194. else
  3195. {
  3196. if(maxProfile.ChargingSchedule.Duration != -1)
  3197. {
  3198. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3199. 0:
  3200. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3201. }
  3202. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3203. {
  3204. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3205. {
  3206. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3207. 0:
  3208. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3209. if(idxPeriod > 0)
  3210. {
  3211. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3212. {
  3213. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3214. }
  3215. }
  3216. }
  3217. }
  3218. }
  3219. }
  3220. /*
  3221. DEBUG_INFO("MaxProfile after align.\n");
  3222. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3223. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3224. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3225. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3226. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3227. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3228. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3229. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3230. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3231. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3232. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3233. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3234. {
  3235. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3236. {
  3237. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3238. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3239. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3240. }
  3241. }
  3242. DEBUG_INFO("------------------------------------\n");*/
  3243. }
  3244. /*
  3245. * Merge to conposite schedule
  3246. */
  3247. //DEBUG_INFO("====================================\n");
  3248. // Find each profile period quantity
  3249. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3250. {
  3251. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3252. limitMax = idx+1;
  3253. }
  3254. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3255. {
  3256. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3257. limitDef = idx+1;
  3258. }
  3259. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3260. {
  3261. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3262. limitTx = idx+1;
  3263. }
  3264. // TxProfile found, composite schedule based on it
  3265. if(txProfile.ChargingProfileId != -1)
  3266. {
  3267. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3268. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3269. {
  3270. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3271. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3272. (txProfile.ChargingSchedule.Duration > 0))
  3273. {
  3274. if(maxProfile.ChargingProfileId != -1)
  3275. {
  3276. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3277. {
  3278. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3279. {
  3280. if((maxProfile.ChargingSchedule.Duration > 0))
  3281. {
  3282. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3283. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3284. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3285. }
  3286. else
  3287. {
  3288. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3289. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3290. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3291. }
  3292. }
  3293. if(idxMaxPeriod == (limitMax-1))
  3294. {
  3295. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3296. {
  3297. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3298. {
  3299. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3300. compositePeriodIdx++;
  3301. }
  3302. else
  3303. {
  3304. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3305. }
  3306. }
  3307. }
  3308. }
  3309. }
  3310. else
  3311. {
  3312. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3313. {
  3314. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3315. compositePeriodIdx++;
  3316. }
  3317. else
  3318. {
  3319. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3320. }
  3321. }
  3322. }
  3323. if(idxTxPeriod == (limitTx-1))
  3324. {
  3325. if(defaultTxProfile.ChargingProfileId != -1)
  3326. {
  3327. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3328. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3329. {
  3330. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3331. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3332. (defaultTxProfile.ChargingSchedule.Duration>0))
  3333. {
  3334. if(maxProfile.ChargingProfileId != -1)
  3335. {
  3336. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3337. {
  3338. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3339. {
  3340. if((maxProfile.ChargingSchedule.Duration > 0))
  3341. {
  3342. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3343. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3344. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3345. }
  3346. else
  3347. {
  3348. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3349. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3350. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3351. }
  3352. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3353. {
  3354. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3355. {
  3356. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3357. compositePeriodIdx++;
  3358. }
  3359. else
  3360. {
  3361. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3362. }
  3363. }
  3364. // Delete duplicate period
  3365. if(compositePeriodIdx > 1)
  3366. {
  3367. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3368. {
  3369. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3370. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3371. compositePeriodIdx -= 1;
  3372. }
  3373. }
  3374. }
  3375. else
  3376. {
  3377. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3378. {
  3379. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3380. compositePeriodIdx++;
  3381. }
  3382. else
  3383. {
  3384. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3385. }
  3386. break;
  3387. }
  3388. }
  3389. }
  3390. else
  3391. {
  3392. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3393. {
  3394. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3395. compositePeriodIdx++;
  3396. }
  3397. else
  3398. {
  3399. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3400. }
  3401. }
  3402. }
  3403. }
  3404. }
  3405. }
  3406. }
  3407. }
  3408. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3409. else if(defaultTxProfile.ChargingProfileId != -1)
  3410. {
  3411. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3412. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3413. {
  3414. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3415. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3416. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3417. {
  3418. if(maxProfile.ChargingProfileId != -1)
  3419. {
  3420. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3421. {
  3422. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3423. {
  3424. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3425. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3426. if((maxProfile.ChargingSchedule.Duration > 0))
  3427. {
  3428. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3429. }
  3430. else
  3431. {
  3432. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3433. }
  3434. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3435. {
  3436. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3437. {
  3438. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3439. compositePeriodIdx++;
  3440. }
  3441. else
  3442. {
  3443. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3444. }
  3445. }
  3446. // Delete duplicate period
  3447. if(compositePeriodIdx > 1)
  3448. {
  3449. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3450. {
  3451. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3452. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3453. compositePeriodIdx -= 1;
  3454. }
  3455. }
  3456. }
  3457. else
  3458. {
  3459. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3460. {
  3461. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3462. compositePeriodIdx++;
  3463. }
  3464. else
  3465. {
  3466. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3467. }
  3468. break;
  3469. }
  3470. }
  3471. }
  3472. else
  3473. {
  3474. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3475. {
  3476. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3477. compositePeriodIdx++;
  3478. }
  3479. else
  3480. {
  3481. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3482. }
  3483. }
  3484. }
  3485. }
  3486. }
  3487. // Fill other period by MaxProfile
  3488. if(maxProfile.ChargingProfileId != -1)
  3489. {
  3490. if(compositePeriodIdx==0)
  3491. {
  3492. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3493. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3494. {
  3495. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3496. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3497. (maxProfile.ChargingSchedule.Duration > 0))
  3498. {
  3499. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3500. {
  3501. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3502. compositePeriodIdx++;
  3503. }
  3504. else
  3505. {
  3506. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3507. }
  3508. }
  3509. }
  3510. }
  3511. else
  3512. {
  3513. int lastCompositePeriodIdx = compositePeriodIdx;
  3514. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3515. {
  3516. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3517. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3518. (maxProfile.ChargingSchedule.Duration > 0))
  3519. {
  3520. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3521. {
  3522. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3523. {
  3524. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3525. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3526. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3527. }
  3528. else
  3529. {
  3530. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3531. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3532. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3533. }
  3534. }
  3535. if(tmpPeriod.Limit != -1)
  3536. {
  3537. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3538. {
  3539. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3540. {
  3541. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3542. compositePeriodIdx++;
  3543. }
  3544. else
  3545. {
  3546. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3547. }
  3548. }
  3549. // Delete duplicate period
  3550. if(compositePeriodIdx > 1)
  3551. {
  3552. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3553. {
  3554. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3555. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3556. compositePeriodIdx -= 1;
  3557. }
  3558. }
  3559. }
  3560. }
  3561. }
  3562. }
  3563. }
  3564. compositeProfile.ChargingSchedule.Duration = durationReq;
  3565. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3566. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3567. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3568. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3569. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3570. {
  3571. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3572. {
  3573. compositeProfile.ChargingProfileId = 1;
  3574. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3575. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3576. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3577. }
  3578. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3579. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3580. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3581. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3582. }
  3583. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3584. if(line)
  3585. free(line);
  3586. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3587. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3588. }
  3589. //==========================================
  3590. // Init all share memory
  3591. //==========================================
  3592. int InitShareMemory()
  3593. {
  3594. int result = PASS;
  3595. int MeterSMId;
  3596. //creat ShmSysConfigAndInfo
  3597. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3598. {
  3599. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3600. result = FAIL;
  3601. }
  3602. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3603. {
  3604. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3605. result = FAIL;
  3606. }
  3607. else
  3608. {}
  3609. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3610. {
  3611. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3612. result = FAIL;
  3613. }
  3614. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3615. {
  3616. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3617. result = FAIL;
  3618. }
  3619. else
  3620. {}
  3621. //creat ShmPsuData
  3622. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3623. {
  3624. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3625. result = FAIL;
  3626. }
  3627. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3628. {
  3629. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3630. result = FAIL;
  3631. }
  3632. else
  3633. {}
  3634. //creat ShmOCPP16Data
  3635. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3636. {
  3637. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3638. result = FAIL;
  3639. }
  3640. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3641. {
  3642. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3643. result = FAIL;
  3644. }
  3645. else
  3646. {}
  3647. /****************************** For Initial Settings************************************************/
  3648. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3649. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3650. // allocate Configuration memory address
  3651. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3652. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3653. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3654. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3655. //offline MeterValue Interval
  3656. TempMeterValueInterval = 0;
  3657. return result;
  3658. }
  3659. int ProcessShareMemory()
  3660. {
  3661. int result = PASS;
  3662. if(InitShareMemory() == FAIL)
  3663. {
  3664. DEBUG_ERROR("InitShareMemory NG\n");
  3665. if(ShmStatusCodeData!=NULL)
  3666. {
  3667. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3668. }
  3669. result = FAIL;
  3670. }
  3671. // Model name parsing
  3672. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3673. {
  3674. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3675. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3676. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3677. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3678. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3679. ) // 'D' means DC
  3680. {
  3681. // DO series
  3682. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3683. {
  3684. SystemInitial += 1;
  3685. gunTotalNumber += 1;
  3686. gunType[gun_index] = GUN_TYPE_DO;
  3687. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3688. {
  3689. case Gun_Type_Chademo:
  3690. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3691. break;
  3692. case Gun_Type_CCS_2:
  3693. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3694. break;
  3695. case Gun_Type_GB:
  3696. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3697. break;
  3698. case Gun_Type_AC:
  3699. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3700. break;
  3701. default:
  3702. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3703. break;
  3704. }
  3705. }
  3706. }
  3707. else
  3708. {
  3709. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3710. {
  3711. SystemInitial += 1;
  3712. gunTotalNumber += 1;
  3713. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3714. {
  3715. case Gun_Type_Chademo:
  3716. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3717. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3718. break;
  3719. case Gun_Type_CCS_2:
  3720. gunType[gun_index] = GUN_TYPE_CCS;
  3721. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3722. break;
  3723. case Gun_Type_GB:
  3724. gunType[gun_index] = GUN_TYPE_GBT;
  3725. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3726. break;
  3727. case Gun_Type_AC:
  3728. gunType[gun_index] = GUN_TYPE_AC;
  3729. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3730. break;
  3731. default:
  3732. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3733. break;
  3734. }
  3735. }
  3736. }
  3737. }
  3738. else
  3739. {
  3740. DEBUG_ERROR("Model name parsing fail.\n");
  3741. result = FAIL;
  3742. }
  3743. if(result != PASS)sleep(5);
  3744. return result;
  3745. }
  3746. void checkRemoteStart(uint8_t connectorIdInt)
  3747. {
  3748. uint8_t tempIndex;
  3749. int result = PASS;
  3750. char cmdBuf[512];
  3751. //check Transaction active
  3752. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3753. {
  3754. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3755. {
  3756. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3757. }
  3758. else
  3759. {
  3760. tempIndex = connectorIdInt -1;
  3761. }
  3762. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3763. {
  3764. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3765. {
  3766. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3767. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3768. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3769. {
  3770. //Reserved
  3771. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3772. }
  3773. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3774. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3775. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3776. {
  3777. //Reserved
  3778. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3779. result = FAIL;
  3780. goto end;
  3781. }
  3782. else
  3783. {
  3784. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3785. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3786. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3787. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3788. {
  3789. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  3790. result = FAIL;
  3791. goto end;
  3792. }
  3793. }//END FOR ELSE
  3794. }
  3795. }// END FOR CHAdeMO_QUANTITY
  3796. }
  3797. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3798. {
  3799. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3800. {
  3801. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3802. }
  3803. else
  3804. {
  3805. tempIndex = connectorIdInt -1;
  3806. }
  3807. for (int index = 0; index < CCS_QUANTITY; index++)
  3808. {
  3809. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3810. {
  3811. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3812. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3813. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3814. {
  3815. //Reserved
  3816. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3817. }
  3818. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3819. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3820. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3821. {
  3822. //Reserved
  3823. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3824. result = FAIL;
  3825. goto end;
  3826. }
  3827. else
  3828. {
  3829. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3830. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3831. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3832. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3833. {
  3834. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3835. result = FAIL;
  3836. goto end;
  3837. }
  3838. }// END FOR ELSE
  3839. }
  3840. }// END FOR CCS_QUANTITY
  3841. }
  3842. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3843. {
  3844. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3845. {
  3846. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3847. }
  3848. else
  3849. {
  3850. tempIndex = connectorIdInt -1;
  3851. }
  3852. for (int index = 0; index < GB_QUANTITY; index++)
  3853. {
  3854. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3855. {
  3856. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3857. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3858. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3859. {
  3860. //Reserved
  3861. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3862. }
  3863. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3864. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3865. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3866. {
  3867. //Reserved
  3868. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3869. result = FAIL;
  3870. goto end;
  3871. }
  3872. else
  3873. {
  3874. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3875. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3876. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3877. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3878. {
  3879. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  3880. result = FAIL;
  3881. goto end;
  3882. }
  3883. }// END FOR ELSE
  3884. }
  3885. } // END FOR GB_QUANTITY
  3886. }
  3887. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3888. {
  3889. tempIndex = connectorIdInt -1;
  3890. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3891. {
  3892. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3893. {
  3894. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3895. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3896. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3897. {
  3898. //Reserved
  3899. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3900. }
  3901. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3902. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3903. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3904. {
  3905. //Reserved
  3906. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3907. result = FAIL;
  3908. goto end;
  3909. }
  3910. else
  3911. {
  3912. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3913. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3914. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3915. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3916. {
  3917. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  3918. result = FAIL;
  3919. goto end;
  3920. }
  3921. }// END FOR ELSE
  3922. }
  3923. } // END FOR GB_QUANTITY
  3924. }
  3925. else
  3926. {
  3927. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3928. {
  3929. tempIndex = 2;
  3930. }
  3931. else
  3932. {
  3933. tempIndex = connectorIdInt -1;
  3934. }
  3935. for (int index = 0; index < AC_QUANTITY; index++)
  3936. {
  3937. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3938. {
  3939. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3940. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3941. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3942. {
  3943. //Reserved
  3944. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3945. }
  3946. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3947. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3948. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3949. {
  3950. //Reserved
  3951. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3952. result = FAIL;
  3953. goto end;
  3954. }
  3955. else
  3956. {
  3957. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3958. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3959. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3960. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3961. {
  3962. DEBUG_WARN("AC connector not allow start cause busy.\n");
  3963. result = FAIL;
  3964. goto end;
  3965. }
  3966. }//END FOR ELSE
  3967. }
  3968. }// END FOR AC_QUANTITY
  3969. }
  3970. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3971. {
  3972. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3973. {
  3974. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  3975. {
  3976. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3977. system(cmdBuf);
  3978. }
  3979. }
  3980. else
  3981. {
  3982. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3983. result = FAIL;
  3984. }
  3985. }
  3986. end:
  3987. if(result == PASS)
  3988. {
  3989. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3990. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3991. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3992. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3993. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3994. }
  3995. }
  3996. void CheckSystemValue(void)
  3997. {
  3998. char filenmae[100]={0};
  3999. char str[100]={0};
  4000. int tempIndex = 0;
  4001. //===============================
  4002. // send Heartbeat
  4003. //===============================
  4004. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4005. {
  4006. //parameter for test
  4007. sendHeartbeatRequest(0);
  4008. //===========================
  4009. // Reset Waiting Time
  4010. //===========================
  4011. HeartBeatWithNOResponse += 1;
  4012. }
  4013. //===============================
  4014. // Credit deduct report
  4015. //===============================
  4016. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4017. {
  4018. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4019. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4020. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4021. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4022. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4023. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4024. }
  4025. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4026. {
  4027. OCPP_query_deduct_info();
  4028. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4029. }
  4030. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4031. {
  4032. // ClockAlign MeterValue
  4033. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4034. {
  4035. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4036. {
  4037. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4038. {
  4039. tempIndex = ((gun_index==2) ? 1: 0);
  4040. }
  4041. else
  4042. {
  4043. tempIndex = gun_index;
  4044. }
  4045. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4046. {
  4047. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4048. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4049. {
  4050. reqClockAlignMeter[gun_index] = 1;
  4051. }
  4052. }// End for CHAdeMO
  4053. }
  4054. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4055. {
  4056. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4057. {
  4058. tempIndex = ((gun_index==2) ? 1: 0);
  4059. }
  4060. else
  4061. {
  4062. tempIndex = gun_index;
  4063. }
  4064. for (int index = 0; index < CCS_QUANTITY; index++)
  4065. {
  4066. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4067. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4068. {
  4069. reqClockAlignMeter[gun_index] = 1;
  4070. }
  4071. } // End for CCS
  4072. }
  4073. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4074. {
  4075. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4076. {
  4077. tempIndex = ((gun_index==2) ? 1: 0);
  4078. }
  4079. else
  4080. {
  4081. tempIndex = gun_index;
  4082. }
  4083. for (int index = 0; index < GB_QUANTITY; index++)
  4084. {
  4085. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4086. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4087. {
  4088. reqClockAlignMeter[gun_index] = 1;
  4089. }
  4090. }// End for GB
  4091. }
  4092. else if(gunType[gun_index] == GUN_TYPE_DO)
  4093. {
  4094. tempIndex = gun_index;
  4095. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4096. {
  4097. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4098. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4099. {
  4100. reqClockAlignMeter[gun_index] = 1;
  4101. }
  4102. }
  4103. }
  4104. else
  4105. {
  4106. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4107. {
  4108. tempIndex = 2;
  4109. }
  4110. else
  4111. {
  4112. tempIndex = gun_index;
  4113. }
  4114. for (int index = 0; index < AC_QUANTITY; index++)
  4115. {
  4116. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4117. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4118. {
  4119. reqClockAlignMeter[gun_index] = 1;
  4120. }
  4121. }//End for AC
  4122. }
  4123. }
  4124. }
  4125. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4126. {
  4127. //==========================================
  4128. // Check remote start without connector id
  4129. //==========================================
  4130. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4131. {
  4132. int connectorIdInt = -1;
  4133. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4134. {
  4135. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4136. {
  4137. connectorIdInt = (gun_index+1);
  4138. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4139. checkRemoteStart(connectorIdInt);
  4140. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4141. break;
  4142. }
  4143. }
  4144. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4145. {
  4146. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4147. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4148. }
  4149. }
  4150. //==========================================
  4151. // csu trigger DataTransferReq
  4152. //==========================================
  4153. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4154. {
  4155. sendDataTransferRequest(gun_index);
  4156. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4157. }
  4158. //==========================================
  4159. // CSU Trigger Authorize Request
  4160. //==========================================
  4161. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4162. {
  4163. sendAuthorizeRequest(0);
  4164. authorizeRetryTimes = authorizeRetryTimes + 1;
  4165. if(authorizeRetryTimes < 3)
  4166. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4167. }
  4168. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4169. {
  4170. authorizeRetryTimes = 0;
  4171. SetOcppConnStatus(FALSE);
  4172. server_sign = FALSE;
  4173. }
  4174. 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))
  4175. {
  4176. sendAuthorizeRequest(0);
  4177. }
  4178. //==========================================
  4179. // Charger start transaction
  4180. //==========================================
  4181. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4182. {
  4183. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4184. sendStartTransactionRequest(gun_index);
  4185. refreshStartTimer(&clientTime.StartTransaction);
  4186. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4187. storeTempStopTransaction(gun_index);
  4188. }
  4189. //==========================================
  4190. // Charger stop transaction
  4191. //==========================================
  4192. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4193. {
  4194. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4195. sendStopTransactionRequest(gun_index);
  4196. OCPP_updatePeriodEnergy(gun_index);
  4197. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4198. refreshStartTimer(&clientTime.StopTransaction);
  4199. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4200. }
  4201. //==========================================
  4202. // Charger status report
  4203. //==========================================
  4204. //--- Check Mode Change ---//
  4205. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4206. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4207. {
  4208. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4209. {
  4210. tempIndex = ((gun_index==2) ? 1: 0);
  4211. }
  4212. else
  4213. {
  4214. tempIndex = gun_index;
  4215. }
  4216. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4217. {
  4218. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4219. {
  4220. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4221. {
  4222. // Sent unplug message for California pricing logic
  4223. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  4224. {
  4225. uint8_t ts[20];
  4226. getNowDatetime(ts);
  4227. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4228. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4229. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4230. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4231. }
  4232. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4233. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4234. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4235. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4236. {
  4237. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4238. if((access(filenmae,F_OK))!=-1)
  4239. {
  4240. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4241. sprintf(str,"rm -f %s",filenmae);
  4242. system(str);
  4243. }
  4244. }
  4245. }
  4246. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4247. #if 1 // for TempStopTransaction
  4248. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4249. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4250. {
  4251. checkTempStopTransaction(gun_index);
  4252. }
  4253. #endif
  4254. }
  4255. }
  4256. }
  4257. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4258. {
  4259. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4260. {
  4261. tempIndex = ((gun_index==2) ? 1: 0);
  4262. }
  4263. else
  4264. {
  4265. tempIndex = gun_index;
  4266. }
  4267. for (int index = 0; index < CCS_QUANTITY; index++)
  4268. {
  4269. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4270. {
  4271. 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]*/ )
  4272. {
  4273. // Sent unplug message for California pricing logic
  4274. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  4275. {
  4276. uint8_t ts[20];
  4277. getNowDatetime(ts);
  4278. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4279. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4280. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4281. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4282. }
  4283. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4284. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4285. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4286. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4287. {
  4288. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4289. if((access(filenmae,F_OK))!=-1)
  4290. {
  4291. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4292. sprintf(str,"rm -f %s",filenmae);
  4293. system(str);
  4294. }
  4295. }
  4296. }
  4297. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4298. #if 1 // for TempStopTransaction
  4299. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4300. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4301. {
  4302. checkTempStopTransaction(gun_index);
  4303. }
  4304. #endif
  4305. }
  4306. }
  4307. }
  4308. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4309. {
  4310. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4311. {
  4312. tempIndex = ((gun_index==2) ? 1: 0);
  4313. }
  4314. else
  4315. {
  4316. tempIndex = gun_index;
  4317. }
  4318. for (int index = 0; index < GB_QUANTITY; index++)
  4319. {
  4320. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4321. {
  4322. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4323. {
  4324. // Sent unplug message for California pricing logic
  4325. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  4326. {
  4327. uint8_t ts[20];
  4328. getNowDatetime(ts);
  4329. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4330. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4331. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4332. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4333. }
  4334. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4335. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4336. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4337. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4338. {
  4339. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4340. if((access(filenmae,F_OK))!=-1)
  4341. {
  4342. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4343. sprintf(str,"rm -f %s",filenmae);
  4344. system(str);
  4345. }
  4346. }
  4347. }
  4348. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4349. #if 1 // for TempStopTransaction
  4350. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4351. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4352. {
  4353. checkTempStopTransaction(gun_index);
  4354. }
  4355. #endif
  4356. }
  4357. }
  4358. }
  4359. else if(gunType[gun_index] == GUN_TYPE_DO)
  4360. {
  4361. tempIndex = gun_index;
  4362. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4363. {
  4364. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4365. {
  4366. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4367. {
  4368. // Sent unplug message for California pricing logic
  4369. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  4370. {
  4371. uint8_t ts[20];
  4372. getNowDatetime(ts);
  4373. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4374. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4375. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4376. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4377. }
  4378. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4379. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4380. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4381. 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
  4382. {
  4383. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4384. if((access(filenmae,F_OK))!=-1)
  4385. {
  4386. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4387. sprintf(str,"rm -f %s",filenmae);
  4388. system(str);
  4389. }
  4390. }
  4391. }
  4392. 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);
  4393. #if 1 // for TempStopTransaction
  4394. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4395. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4396. {
  4397. checkTempStopTransaction(gun_index);
  4398. }
  4399. #endif
  4400. }
  4401. }
  4402. }
  4403. else
  4404. {
  4405. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4406. {
  4407. tempIndex = 2;
  4408. }
  4409. else
  4410. {
  4411. tempIndex = gun_index;
  4412. }
  4413. for (int index = 0; index < AC_QUANTITY; index++)
  4414. {
  4415. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4416. {
  4417. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4418. {
  4419. // Sent unplug message for California pricing logic
  4420. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  4421. {
  4422. uint8_t ts[20];
  4423. getNowDatetime(ts);
  4424. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4425. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4426. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4427. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4428. }
  4429. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4430. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4431. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4432. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4433. {
  4434. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4435. if((access(filenmae,F_OK))!=-1)
  4436. {
  4437. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4438. sprintf(str,"rm -f %s",filenmae);
  4439. system(str);
  4440. }
  4441. }
  4442. }
  4443. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4444. #if 1 // for TempStopTransaction
  4445. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4446. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4447. {
  4448. checkTempStopTransaction(gun_index);
  4449. }
  4450. #endif
  4451. }
  4452. }// END
  4453. }
  4454. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4455. (
  4456. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4457. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4458. )
  4459. )
  4460. {
  4461. if(SystemInitial > 0)
  4462. SystemInitial -= 1;
  4463. sendStatusNotificationRequest(gun_index);
  4464. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4465. }
  4466. //==============================================
  4467. // TCCI reader status report
  4468. //==============================================
  4469. if(ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1)
  4470. {
  4471. reportReaderStatus(gun_index);
  4472. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4473. }
  4474. //==============================================
  4475. // CSU Trigger Smart Charging Profile
  4476. //==============================================
  4477. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4478. {
  4479. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4480. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4481. }
  4482. //==============================================
  4483. // Meter report
  4484. //==============================================
  4485. // Trigger MeterValue
  4486. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4487. {
  4488. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4489. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4490. }
  4491. // Clock-aligned Meter value
  4492. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4493. {
  4494. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4495. reqClockAlignMeter[gun_index] = 0;
  4496. }
  4497. // Sample period MeterValue
  4498. 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))))
  4499. {
  4500. //check Transaction active
  4501. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4502. {
  4503. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4504. {
  4505. tempIndex = ((gun_index==2) ? 1: 0);
  4506. }
  4507. else
  4508. {
  4509. tempIndex = gun_index;
  4510. }
  4511. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4512. {
  4513. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4514. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4515. {
  4516. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4517. {
  4518. reqSampleMeter[gun_index] = 1;
  4519. }
  4520. }
  4521. }// End for CHAdeMO
  4522. }
  4523. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4524. {
  4525. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4526. {
  4527. tempIndex = ((gun_index==2) ? 1: 0);
  4528. }
  4529. else
  4530. {
  4531. tempIndex = gun_index;
  4532. }
  4533. for (int index = 0; index < CCS_QUANTITY; index++)
  4534. {
  4535. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4536. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4537. {
  4538. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4539. {
  4540. reqSampleMeter[gun_index] = 1;
  4541. }
  4542. }
  4543. } // End for CCS
  4544. }
  4545. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4546. {
  4547. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4548. {
  4549. tempIndex = ((gun_index==2) ? 1: 0);
  4550. }
  4551. else
  4552. {
  4553. tempIndex = gun_index;
  4554. }
  4555. for (int index = 0; index < GB_QUANTITY; index++)
  4556. {
  4557. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4558. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4559. {
  4560. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4561. {
  4562. reqSampleMeter[gun_index] = 1;
  4563. }
  4564. }
  4565. }// End for GB
  4566. }
  4567. else if(gunType[gun_index] == GUN_TYPE_DO)
  4568. {
  4569. tempIndex = gun_index;
  4570. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4571. {
  4572. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4573. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4574. {
  4575. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4576. {
  4577. reqSampleMeter[gun_index] = 1;
  4578. }
  4579. }
  4580. }
  4581. }
  4582. else
  4583. {
  4584. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4585. {
  4586. tempIndex = 2;
  4587. }
  4588. else
  4589. {
  4590. tempIndex = gun_index;
  4591. }
  4592. for (int index = 0; index < AC_QUANTITY; index++)
  4593. {
  4594. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4595. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4596. {
  4597. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4598. {
  4599. reqSampleMeter[gun_index] = 1;
  4600. }
  4601. }
  4602. }//End for AC
  4603. }
  4604. if(reqSampleMeter[gun_index] == 1)
  4605. {
  4606. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4607. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4608. storeTempStopTransaction(gun_index);
  4609. reqSampleMeter[gun_index] = 0;
  4610. }
  4611. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4612. }
  4613. //==============================================
  4614. // Check Connector reserved
  4615. //==============================================
  4616. //===============================
  4617. // Check if Reserve is expired
  4618. //===============================
  4619. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4620. {
  4621. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4622. {
  4623. DEBUG_INFO("reserve expired.\n");
  4624. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4625. }
  4626. }//END OF Check if Reserve is expired
  4627. //==========================================
  4628. // csu trigger FirmwareStatusNotificationReq
  4629. //==========================================
  4630. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4631. {
  4632. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  4633. }
  4634. //==========================================
  4635. // csu trigger DiagnosticsStatusNotificationReq
  4636. //==========================================
  4637. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4638. {
  4639. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  4640. }
  4641. //==========================================
  4642. // csu trigger CancelReservationConf
  4643. //==========================================
  4644. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4645. {
  4646. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  4647. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4648. }
  4649. //==========================================
  4650. // csu trigger ChangeAvailabilityConf
  4651. //==========================================
  4652. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4653. {
  4654. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  4655. }
  4656. //==========================================
  4657. // csu trigger UnlockConnectorConf
  4658. //==========================================
  4659. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4660. {
  4661. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  4662. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4663. }
  4664. //==========================================
  4665. // csu trigger ReserveNowConf
  4666. //==========================================
  4667. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4668. {
  4669. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  4670. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4671. }
  4672. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  4673. {
  4674. sendSignCertificateRequest();
  4675. }
  4676. }
  4677. }
  4678. //==========================================
  4679. // send request routine
  4680. //==========================================
  4681. int sendAuthorizeRequest(int gun_index)
  4682. {
  4683. mtrace();
  4684. int result = FAIL;
  4685. char message[100]={0};
  4686. char guid[37];
  4687. char tempdata[65]={0};
  4688. DEBUG_INFO("sendAuthorizeRequest...\n");
  4689. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4690. //Local Authorize
  4691. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  4692. {
  4693. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4694. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4695. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4696. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4697. result = PASS;
  4698. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4699. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4700. authorizeRetryTimes = 0;
  4701. return result;
  4702. }
  4703. 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))||
  4704. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4705. {
  4706. // Query from cache
  4707. DEBUG_INFO("Authorize from cache.\n");
  4708. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4709. // Query from list
  4710. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4711. {
  4712. DEBUG_INFO("Authorize from list.\n");
  4713. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4714. }
  4715. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4716. {
  4717. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4718. {
  4719. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4720. }
  4721. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4722. {
  4723. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4724. }
  4725. if(!GetOcppConnStatus())
  4726. {
  4727. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4728. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4729. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4730. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4731. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4732. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4733. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4734. authorizeRetryTimes = 0;
  4735. return result;
  4736. }
  4737. }
  4738. else
  4739. {
  4740. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4741. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4742. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4743. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4744. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  4745. else
  4746. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4747. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4748. result = PASS;
  4749. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4750. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4751. authorizeRetryTimes = 0;
  4752. return result;
  4753. }
  4754. }
  4755. //initialize struct Authorize
  4756. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  4757. //get data from shared memory
  4758. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4759. random_uuid(guid);
  4760. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  4761. LWS_Send(message);
  4762. sprintf(tempdata, "Authorize,%d", gun_index);
  4763. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4764. {
  4765. result = PASS;
  4766. DEBUG_INFO("Authorize mapItem pass\n");
  4767. }
  4768. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4769. return result;
  4770. }
  4771. int sendBootNotificationRequest(void)
  4772. {
  4773. mtrace();
  4774. int result = FAIL;
  4775. char message[500]={0}, payload[700]={0};
  4776. char guid[37]={0};
  4777. char tempdata[65]={0};
  4778. // Fill BootNotification fields
  4779. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  4780. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4781. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4782. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4783. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4784. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4785. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4786. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4787. ShmOCPP16Data->ChargeBoxId
  4788. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4789. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4790. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4791. ,ShmOCPP16Data->BootNotification.CpFwVersion
  4792. ,ShmOCPP16Data->BootNotification.CpIccid
  4793. ,ShmOCPP16Data->BootNotification.CpImsi);
  4794. random_uuid(guid);
  4795. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4796. LWS_Send(message);
  4797. sprintf(tempdata, "BootNotification,0");
  4798. 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*/)
  4799. {
  4800. result = PASS;
  4801. }
  4802. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4803. strcpy(queuedata,message);
  4804. return result;
  4805. }
  4806. int sendDataTransferRequest(int gun_index)
  4807. {
  4808. mtrace();
  4809. char message[1000]={0};
  4810. char guid[37]={0};
  4811. char tempdata[65]={0};
  4812. int result = FAIL;
  4813. random_uuid(guid);
  4814. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4815. MESSAGE_TYPE_CALL,
  4816. guid,
  4817. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4818. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4819. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4820. LWS_Send(message);
  4821. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4822. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4823. {
  4824. result = PASS;
  4825. DEBUG_INFO("DataTransfer mapItem pass\n");
  4826. }
  4827. return result;
  4828. }
  4829. int sendDiagnosticsStatusNotificationRequest(char *status)
  4830. {
  4831. mtrace();
  4832. int result = FAIL;
  4833. char message[110]={0};
  4834. char guid[37]={0};
  4835. char tempdata[65]={0};
  4836. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4837. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4838. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4839. random_uuid(guid);
  4840. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4841. LWS_SendNow(message);
  4842. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4843. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4844. {
  4845. result = PASS;
  4846. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4847. }
  4848. //#ifdef SystemLogMessage
  4849. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4850. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4851. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4852. //#endif
  4853. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4854. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4855. //record status
  4856. if(strcmp(status,"Idle")==0)
  4857. {
  4858. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4859. }
  4860. else if(strcmp(status,"Uploaded")==0)
  4861. {
  4862. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4863. }
  4864. else if(strcmp(status,"UploadFailed")==0)
  4865. {
  4866. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4867. }
  4868. else if(strcmp(status,"Uploading")==0)
  4869. {
  4870. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4871. }
  4872. return result;
  4873. }
  4874. int sendFirmwareStatusNotificationRequest(char *status)
  4875. {
  4876. mtrace();
  4877. int result = FAIL;
  4878. char message[110]={0};
  4879. char guid[37]={0};
  4880. char tempdata[65]={0};
  4881. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4882. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4883. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4884. random_uuid(guid);
  4885. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4886. LWS_SendNow(message);
  4887. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4888. 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*/)
  4889. {
  4890. result = PASS;
  4891. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4892. }
  4893. //#ifdef SystemLogMessage
  4894. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4895. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4896. //#endif
  4897. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4898. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4899. //record status
  4900. if(strcmp(status,"Downloaded")==0)
  4901. {
  4902. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4903. }
  4904. else if(strcmp(status,"DownloadFailed")==0)
  4905. {
  4906. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4907. }
  4908. else if(strcmp(status,"Downloading")==0)
  4909. {
  4910. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4911. }
  4912. else if(strcmp(status,"Idle")==0)
  4913. {
  4914. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4915. }
  4916. else if(strcmp(status,"InstallationFailed")==0)
  4917. {
  4918. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4919. }
  4920. else if(strcmp(status,"Installing")==0)
  4921. {
  4922. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4923. }
  4924. else if(strcmp(status,"Installed")==0)
  4925. {
  4926. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4927. }
  4928. return result;
  4929. }
  4930. int sendHeartbeatRequest(int gun_index)
  4931. {
  4932. mtrace();
  4933. int result = FAIL;
  4934. char message[80]={0};
  4935. char guid[37]={0};
  4936. char tempdata[65]={0};
  4937. random_uuid(guid);
  4938. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4939. , MESSAGE_TYPE_CALL
  4940. , guid );
  4941. LWS_Send(message);
  4942. sprintf(tempdata, "Heartbeat,%d", 0);
  4943. 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*/)
  4944. {
  4945. result = PASS;
  4946. }
  4947. return result;
  4948. }
  4949. int sendStartTransactionRequest(int gun_index)
  4950. {
  4951. mtrace();
  4952. int result = FAIL;
  4953. char message[250]={0};
  4954. char guid[37]={0};
  4955. struct timeval tmnow;
  4956. struct tm *tm;
  4957. char buf[28];//, usec_buf[6];
  4958. char tempdata[65]={0};
  4959. int tempIndex = 0;
  4960. DEBUG_INFO("sendStartTransactionRequest...\n");
  4961. gettimeofday(&tmnow, NULL);
  4962. time_t t;
  4963. t = time(NULL);
  4964. /*UTC time and date*/
  4965. tm = gmtime(&t);
  4966. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4967. #if 0 // remove temporally
  4968. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4969. strcat(buf,".");
  4970. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4971. strcat(buf,usec_buf);
  4972. #endif
  4973. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4974. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4975. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4976. // clear StartTransaction Response
  4977. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4978. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4979. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4980. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4981. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4982. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4983. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4984. {
  4985. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4986. {
  4987. tempIndex = ((gun_index==2) ? 1: 0);
  4988. }
  4989. else
  4990. {
  4991. tempIndex = gun_index;
  4992. }
  4993. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4994. {
  4995. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4996. {
  4997. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4998. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4999. }
  5000. }
  5001. }
  5002. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5003. {
  5004. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5005. {
  5006. tempIndex = ((gun_index==2) ? 1: 0);
  5007. }
  5008. else
  5009. {
  5010. tempIndex = gun_index;
  5011. }
  5012. for (int index = 0; index < CCS_QUANTITY; index++)
  5013. {
  5014. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5015. {
  5016. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5017. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  5018. }
  5019. }
  5020. }
  5021. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5022. {
  5023. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5024. {
  5025. tempIndex = ((gun_index==2) ? 1: 0);
  5026. }
  5027. else
  5028. {
  5029. tempIndex = gun_index;
  5030. }
  5031. for (int index = 0; index < GB_QUANTITY; index++)
  5032. {
  5033. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5034. {
  5035. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5036. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5037. }
  5038. }
  5039. }
  5040. else if(gunType[gun_index] == GUN_TYPE_DO)
  5041. {
  5042. tempIndex = gun_index;
  5043. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5044. {
  5045. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5046. {
  5047. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5048. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5049. }
  5050. }
  5051. }
  5052. else
  5053. {
  5054. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5055. {
  5056. tempIndex = 2;
  5057. }
  5058. else
  5059. {
  5060. tempIndex = gun_index;
  5061. }
  5062. for (int index = 0; index < AC_QUANTITY; index++)
  5063. {
  5064. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5065. {
  5066. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5067. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5068. }
  5069. }
  5070. }
  5071. random_uuid(guid);
  5072. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5073. {
  5074. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5075. , gun_index +1
  5076. , MESSAGE_TYPE_CALL
  5077. , guid
  5078. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5079. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5080. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5081. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5082. }
  5083. else
  5084. {
  5085. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5086. , gun_index +1
  5087. , MESSAGE_TYPE_CALL
  5088. , guid
  5089. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5090. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5091. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5092. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  5093. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5094. }
  5095. #if 1
  5096. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5097. 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*/)
  5098. {
  5099. result = PASS;
  5100. }
  5101. #endif
  5102. strcpy(queuedata, message);
  5103. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5104. OCPP_insert_transaction_msg(YES, queuedata);
  5105. return result;
  5106. }
  5107. int sendStatusNotificationRequest(int gun_index)
  5108. {
  5109. mtrace();
  5110. int result = FAIL;
  5111. char message[600]={0};
  5112. char guid[37];
  5113. int currentStatus = 0;
  5114. struct timeval tmnow;
  5115. struct tm *tm;
  5116. char buf[28];//, usec_buf[6];
  5117. char tempdata[65]={0};
  5118. int tempIndex = 0;
  5119. uint8_t isStateChanged = TRUE;
  5120. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5121. gettimeofday(&tmnow, NULL);
  5122. time_t t;
  5123. t = time(NULL);
  5124. /*UTC time and date*/
  5125. tm = gmtime(&t);
  5126. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5127. #if 0 // remove temporally
  5128. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5129. strcat(buf,".");
  5130. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5131. strcat(buf,usec_buf);
  5132. #endif
  5133. //printf("%s",buf);
  5134. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5135. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5136. // it's option
  5137. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5138. /*
  5139. enum _SYSTEM_STATUS
  5140. {
  5141. S_BOOTING = 0,
  5142. S_IDLE, = 1
  5143. S_AUTHORIZING, =2
  5144. S_REASSIGN_CHECK, =3
  5145. S_REASSIGN, =4
  5146. S_PRECHARGE, =5
  5147. S_PREPARING_FOR_EV, =6
  5148. S_PREPARING_FOR_EVSE, =7
  5149. S_CHARGING, =8
  5150. S_TERMINATING, =9
  5151. S_COMPLETE, =10
  5152. S_ALARM, =11
  5153. S_FAULT =12
  5154. }
  5155. */
  5156. //check Transaction active
  5157. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5158. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5159. {
  5160. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5161. {
  5162. tempIndex = ((gun_index==2) ? 1: 0);
  5163. }
  5164. else
  5165. {
  5166. tempIndex = gun_index;
  5167. }
  5168. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5169. {
  5170. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5171. {
  5172. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5173. {
  5174. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5175. {
  5176. currentStatus = Preparing; //OCPP Status: Preparing
  5177. }
  5178. else
  5179. {
  5180. currentStatus = Available; //OCPP Status: Available
  5181. }
  5182. }
  5183. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5184. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5185. ) //S_PRECHARGE
  5186. {
  5187. currentStatus = Preparing; //OCPP Status: Preparing
  5188. }
  5189. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5190. {
  5191. currentStatus = Charging; //OCPP Status: Charging
  5192. }
  5193. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5194. {
  5195. currentStatus = Finishing; //OCPP Status: Finishing
  5196. }
  5197. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5198. {
  5199. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5200. }
  5201. 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
  5202. {
  5203. currentStatus = Unavailable; //OCPP Status: Unavailable
  5204. }
  5205. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5206. {
  5207. currentStatus = Faulted; //OCPP Status: Faulted
  5208. }
  5209. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5210. {
  5211. currentStatus = Reserved; //OCPP Status: Reserved
  5212. }
  5213. } //end of the same index
  5214. }//end of for CHAdeMO_QUANTITY
  5215. }
  5216. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5217. {
  5218. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5219. {
  5220. tempIndex = ((gun_index==2) ? 1: 0);
  5221. }
  5222. else
  5223. {
  5224. tempIndex = gun_index;
  5225. }
  5226. for (int index = 0; index < CCS_QUANTITY; index++)
  5227. {
  5228. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5229. {
  5230. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5231. {
  5232. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5233. {
  5234. currentStatus = Preparing; //OCPP Status: Preparing
  5235. }
  5236. else
  5237. {
  5238. currentStatus = Available; //OCPP Status: Available
  5239. }
  5240. }
  5241. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5242. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5243. ) //S_PRECHARGE
  5244. {
  5245. currentStatus = Preparing; //OCPP Status: Preparing
  5246. }
  5247. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5248. {
  5249. currentStatus = Charging; //OCPP Status: Charging
  5250. }
  5251. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5252. {
  5253. currentStatus = Finishing; //OCPP Status: Finishing
  5254. }
  5255. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5256. {
  5257. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5258. }
  5259. 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
  5260. {
  5261. currentStatus = Unavailable; //OCPP Status : Unavailable
  5262. }
  5263. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5264. {
  5265. currentStatus = Faulted; //OCPP Status: Faulted
  5266. }
  5267. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5268. {
  5269. currentStatus = Reserved; //OCPP Status: Reserved
  5270. }
  5271. } //end of the same index
  5272. } // end of for CCS_QUANTITY
  5273. }
  5274. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5275. {
  5276. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5277. {
  5278. tempIndex = ((gun_index==2) ? 1: 0);
  5279. }
  5280. else
  5281. {
  5282. tempIndex = gun_index;
  5283. }
  5284. for (int index = 0; index < GB_QUANTITY; index++)
  5285. {
  5286. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5287. {
  5288. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5289. {
  5290. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5291. {
  5292. currentStatus = Preparing; //OCPP Status: Preparing
  5293. }
  5294. else
  5295. {
  5296. currentStatus = Available; //OCPP Status: Available
  5297. }
  5298. }
  5299. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5300. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5301. ) //S_PRECHARGE
  5302. {
  5303. currentStatus = Preparing; //OCPP Status: Preparing
  5304. }
  5305. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5306. {
  5307. currentStatus = Charging; //OCPP Status: Charging
  5308. }
  5309. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5310. {
  5311. currentStatus = Finishing; //OCPP Status: Finishing
  5312. }
  5313. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5314. {
  5315. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5316. }
  5317. 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
  5318. {
  5319. currentStatus = Unavailable; //OCPP Status: Unavailable
  5320. }
  5321. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5322. {
  5323. currentStatus = Faulted; //OCPP Status: Faulted
  5324. }
  5325. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5326. {
  5327. currentStatus = Reserved; //OCPP Status: Reserved
  5328. }
  5329. } //end of the same index
  5330. } // end of for GB_QUANTITY
  5331. }
  5332. else if(gunType[gun_index] == GUN_TYPE_DO)
  5333. {
  5334. tempIndex = gun_index;
  5335. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5336. {
  5337. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5338. {
  5339. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5340. {
  5341. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5342. {
  5343. currentStatus = Preparing; //OCPP Status: Preparing
  5344. }
  5345. else
  5346. {
  5347. currentStatus = Available; //OCPP Status: Available
  5348. }
  5349. }
  5350. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5351. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5352. ) //S_PRECHARGE
  5353. {
  5354. currentStatus = Preparing; //OCPP Status: Preparing
  5355. }
  5356. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5357. {
  5358. currentStatus = Charging; //OCPP Status: Charging
  5359. }
  5360. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5361. {
  5362. currentStatus = Finishing; //OCPP Status: Finishing
  5363. }
  5364. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5365. {
  5366. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5367. }
  5368. 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
  5369. {
  5370. currentStatus = Unavailable; //OCPP Status: Unavailable
  5371. }
  5372. 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
  5373. {
  5374. currentStatus = Faulted; //OCPP Status: Faulted
  5375. }
  5376. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5377. {
  5378. currentStatus = Reserved; //OCPP Status: Reserved
  5379. }
  5380. } //end of the same index
  5381. }
  5382. }
  5383. else
  5384. {
  5385. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5386. {
  5387. tempIndex = 2;
  5388. }
  5389. else
  5390. {
  5391. tempIndex = gun_index;
  5392. }
  5393. for (int index = 0; index < AC_QUANTITY; index++)
  5394. {
  5395. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5396. {
  5397. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5398. {
  5399. 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))
  5400. {
  5401. currentStatus = Preparing; //OCPP Status: Preparing
  5402. }
  5403. else
  5404. {
  5405. currentStatus = Available; //OCPP Status: Available
  5406. }
  5407. }
  5408. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5409. {
  5410. currentStatus = Preparing; //OCPP Status: Preparing
  5411. }
  5412. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5413. {
  5414. currentStatus = Charging; //OCPP Status: Charging
  5415. }
  5416. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5417. {
  5418. currentStatus = Finishing; //OCPP Status: Finishing
  5419. }
  5420. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5421. {
  5422. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5423. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5424. else
  5425. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5426. }
  5427. 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
  5428. {
  5429. currentStatus = Unavailable; //OCPP Status: Unavailable
  5430. }
  5431. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5432. {
  5433. currentStatus = Faulted; //OCPP Status: Faulted
  5434. }
  5435. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5436. {
  5437. currentStatus = Reserved; //OCPP Status: Reserved
  5438. }
  5439. }//end of the same index
  5440. }//end of for AC_QUANTITY
  5441. }
  5442. //it's option
  5443. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5444. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5445. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5446. {
  5447. isStateChanged = FALSE;
  5448. }
  5449. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5450. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5451. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5452. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5453. random_uuid(guid);
  5454. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5455. , MESSAGE_TYPE_CALL
  5456. , guid
  5457. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5458. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5459. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5460. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5461. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5462. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5463. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5464. if((server_sign == TRUE) && isStateChanged)
  5465. {
  5466. LWS_Send(message);
  5467. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5468. 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*/)
  5469. {
  5470. //DEBUG_ERROR("statusNotification mapitem pass");
  5471. result = PASS;
  5472. }
  5473. }
  5474. else
  5475. {
  5476. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5477. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5478. result = PASS;
  5479. }
  5480. return result;
  5481. }
  5482. int sendStopTransactionRequest(int gun_index)
  5483. {
  5484. mtrace();
  5485. int result = FAIL;
  5486. //char message[1500]={0};
  5487. char guid[37]={0};
  5488. char tempdata[65]={0};
  5489. int tempIndex = 0;
  5490. char TempStopTransaction[256];
  5491. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5492. //int idx_sample=0;
  5493. DEBUG_INFO("sendStopTransactionRequest \n");
  5494. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5495. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5496. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5497. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5498. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5499. {
  5500. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5501. {
  5502. tempIndex = ((gun_index==2) ? 1: 0);
  5503. }
  5504. else
  5505. {
  5506. tempIndex = gun_index;
  5507. }
  5508. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5509. {
  5510. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5511. {
  5512. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5513. }
  5514. }// END OF CHAdeMO_QUANTITY
  5515. }
  5516. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5517. {
  5518. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5519. {
  5520. tempIndex = ((gun_index==2) ? 1: 0);
  5521. }
  5522. else
  5523. {
  5524. tempIndex = gun_index;
  5525. }
  5526. for (int index = 0; index < CCS_QUANTITY; index++)
  5527. {
  5528. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5529. {
  5530. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5531. }
  5532. }// END OF CCS_QUANTITY
  5533. }
  5534. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5535. {
  5536. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5537. {
  5538. tempIndex = ((gun_index==2) ? 1: 0);
  5539. }
  5540. else
  5541. {
  5542. tempIndex = gun_index;
  5543. }
  5544. for (int index = 0; index < GB_QUANTITY; index++)
  5545. {
  5546. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5547. {
  5548. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5549. }
  5550. }// END OF GB_QUANTITY
  5551. }
  5552. else if(gunType[gun_index] == GUN_TYPE_DO)
  5553. {
  5554. tempIndex = gun_index;
  5555. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5556. {
  5557. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5558. {
  5559. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5560. }
  5561. }// END OF GB_QUANTITY
  5562. }
  5563. else
  5564. {
  5565. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5566. {
  5567. tempIndex = 2;
  5568. }
  5569. else
  5570. {
  5571. tempIndex = gun_index;
  5572. }
  5573. for (int index = 0; index < AC_QUANTITY; index++)
  5574. {
  5575. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5576. {
  5577. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5578. }
  5579. }// END OF AC_QUANTITY
  5580. }
  5581. //====================================== Stop Transaction Time =====================================================
  5582. struct timeval tmnow;
  5583. struct tm *tm;
  5584. char buf[28];//, usec_buf[6];
  5585. gettimeofday(&tmnow, NULL);
  5586. time_t t;
  5587. t = time(NULL);
  5588. /*UTC time and date*/
  5589. tm = gmtime(&t);
  5590. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  5592. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  5593. random_uuid(guid);
  5594. /***********************************transactionData******************************************************/
  5595. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5596. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5597. //=================================
  5598. // Transaction_Begin
  5599. //=================================
  5600. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5601. {
  5602. //============================================ Energy.Active.Import.Interval ================================
  5603. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5604. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5605. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5606. 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*/]);
  5607. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5608. 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))
  5609. {
  5610. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5611. }
  5612. else
  5613. {
  5614. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5615. }
  5616. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5617. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5618. }
  5619. //=================================
  5620. // Transaction_End
  5621. //=================================
  5622. // ================================= Current.Import L1 ===============================================
  5623. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5624. {
  5625. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5626. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5627. {
  5628. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5629. {
  5630. tempIndex = ((gun_index==2) ? 1: 0);
  5631. }
  5632. else
  5633. {
  5634. tempIndex = gun_index;
  5635. }
  5636. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5637. {
  5638. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5639. {
  5640. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5641. }
  5642. }// End of for CHAdeMO_QUANTITY
  5643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5644. }
  5645. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5646. {
  5647. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5648. {
  5649. tempIndex = ((gun_index==2) ? 1: 0);
  5650. }
  5651. else
  5652. {
  5653. tempIndex = gun_index;
  5654. }
  5655. for (int index = 0; index < CCS_QUANTITY; index++)
  5656. {
  5657. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5658. {
  5659. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5660. }
  5661. }// End of for CCS_QUANTITY
  5662. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5663. }
  5664. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5665. {
  5666. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5667. {
  5668. tempIndex = ((gun_index==2) ? 1: 0);
  5669. }
  5670. else
  5671. {
  5672. tempIndex = gun_index;
  5673. }
  5674. for (int index = 0; index < GB_QUANTITY; index++)
  5675. {
  5676. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5677. {
  5678. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5679. }
  5680. }// End of for GB_QUANTITY
  5681. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5682. }
  5683. else if(gunType[gun_index] == GUN_TYPE_DO)
  5684. {
  5685. tempIndex = gun_index;
  5686. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5687. {
  5688. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5689. {
  5690. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5691. }
  5692. }
  5693. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5694. }
  5695. else
  5696. {
  5697. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5698. {
  5699. tempIndex = 2;
  5700. }
  5701. else
  5702. {
  5703. tempIndex = gun_index;
  5704. }
  5705. for (int index = 0; index < AC_QUANTITY; index++)
  5706. {
  5707. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5708. {
  5709. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5710. }
  5711. }// End of for AC_QUANTITY
  5712. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5713. }
  5714. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5715. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5716. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5717. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5718. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5719. }
  5720. // ================================= Energy.Active.Import.Interval ==============================================
  5721. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5722. {
  5723. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5724. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5725. {
  5726. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5727. {
  5728. tempIndex = ((gun_index==2) ? 1: 0);
  5729. }
  5730. else
  5731. {
  5732. tempIndex = gun_index;
  5733. }
  5734. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5735. {
  5736. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5737. {
  5738. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5739. }
  5740. }// END OF CHAdeMO_QUANTITY
  5741. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5742. }
  5743. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5744. {
  5745. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5746. {
  5747. tempIndex = ((gun_index==2) ? 1: 0);
  5748. }
  5749. else
  5750. {
  5751. tempIndex = gun_index;
  5752. }
  5753. for (int index = 0; index < CCS_QUANTITY; index++)
  5754. {
  5755. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5756. {
  5757. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5758. }
  5759. }// END OF CCS_QUANTITY
  5760. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5761. }
  5762. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5763. {
  5764. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5765. {
  5766. tempIndex = ((gun_index==2) ? 1: 0);
  5767. }
  5768. else
  5769. {
  5770. tempIndex = gun_index;
  5771. }
  5772. for (int index = 0; index < GB_QUANTITY; index++)
  5773. {
  5774. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5775. {
  5776. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5777. }
  5778. }// END OF GB_QUANTITY
  5779. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5780. }
  5781. else if(gunType[gun_index] == GUN_TYPE_DO)
  5782. {
  5783. tempIndex = gun_index;
  5784. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5785. {
  5786. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5787. {
  5788. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5789. }
  5790. }
  5791. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5792. }
  5793. else
  5794. {
  5795. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5796. {
  5797. tempIndex = 2;
  5798. }
  5799. else
  5800. {
  5801. tempIndex = gun_index;
  5802. }
  5803. for (int index = 0; index < AC_QUANTITY; index++)
  5804. {
  5805. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5806. {
  5807. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5808. }
  5809. }// END OF AC_QUANTITY
  5810. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5811. }
  5812. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5813. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5814. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5815. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5816. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5817. }
  5818. //=================================== Power.Active.Import ==================================================
  5819. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5820. {
  5821. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5822. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5823. {
  5824. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5825. {
  5826. tempIndex = ((gun_index==2) ? 1: 0);
  5827. }
  5828. else
  5829. {
  5830. tempIndex = gun_index;
  5831. }
  5832. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5833. {
  5834. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5835. {
  5836. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5837. }
  5838. } // End for CHAdeMO_QUANTITY
  5839. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5840. }
  5841. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5842. {
  5843. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5844. {
  5845. tempIndex = ((gun_index==2) ? 1: 0);
  5846. }
  5847. else
  5848. {
  5849. tempIndex = gun_index;
  5850. }
  5851. for (int index = 0; index < CCS_QUANTITY; index++)
  5852. {
  5853. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5854. {
  5855. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5856. }
  5857. } // END for CCS_QUANTITY
  5858. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5859. }
  5860. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5861. {
  5862. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5863. {
  5864. tempIndex = ((gun_index==2) ? 1: 0);
  5865. }
  5866. else
  5867. {
  5868. tempIndex = gun_index;
  5869. }
  5870. for (int index = 0; index < GB_QUANTITY; index++)
  5871. {
  5872. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5873. {
  5874. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5875. }
  5876. }// END for GB_QUANTITY
  5877. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5878. }
  5879. else if(gunType[gun_index] == GUN_TYPE_DO)
  5880. {
  5881. tempIndex = gun_index;
  5882. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5883. {
  5884. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5885. {
  5886. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5887. }
  5888. }
  5889. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5890. }
  5891. else
  5892. {
  5893. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5894. {
  5895. tempIndex = 2;
  5896. }
  5897. else
  5898. {
  5899. tempIndex = gun_index;
  5900. }
  5901. for (int index = 0; index < AC_QUANTITY; index++)
  5902. {
  5903. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5904. {
  5905. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5906. }
  5907. } // END for AC_QUANTITY
  5908. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5909. }
  5910. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5911. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5912. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5913. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5914. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5915. }
  5916. //============================ Voltage L1 ====================================
  5917. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5918. {
  5919. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5920. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5921. {
  5922. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5923. {
  5924. tempIndex = ((gun_index==2) ? 1: 0);
  5925. }
  5926. else
  5927. {
  5928. tempIndex = gun_index;
  5929. }
  5930. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5931. {
  5932. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5933. {
  5934. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5935. }
  5936. } // END OF FOR CHAdeMO_QUANTITY
  5937. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5938. }
  5939. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5940. {
  5941. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5942. {
  5943. tempIndex = ((gun_index==2) ? 1: 0);
  5944. }
  5945. else
  5946. {
  5947. tempIndex = gun_index;
  5948. }
  5949. for (int index = 0; index < CCS_QUANTITY; index++)
  5950. {
  5951. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5952. {
  5953. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5954. }
  5955. } // END OF FOR CCS_QUANTITY
  5956. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5957. }
  5958. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5959. {
  5960. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5961. {
  5962. tempIndex = ((gun_index==2) ? 1: 0);
  5963. }
  5964. else
  5965. {
  5966. tempIndex = gun_index;
  5967. }
  5968. for (int index = 0; index < GB_QUANTITY; index++)
  5969. {
  5970. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5971. {
  5972. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5973. }
  5974. } // END OF FOR GB_QUANTITY
  5975. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5976. }
  5977. else if(gunType[gun_index] == GUN_TYPE_DO)
  5978. {
  5979. tempIndex = gun_index;
  5980. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5981. {
  5982. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5983. {
  5984. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5985. }
  5986. }
  5987. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5988. }
  5989. else
  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[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  6004. }
  6005. } // END OF FOR AC_QUANTITY
  6006. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  6007. }
  6008. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6009. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  6010. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  6011. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  6012. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6013. }
  6014. //====================== End SoC ================================
  6015. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6016. {
  6017. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6018. 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))
  6019. {
  6020. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6021. {
  6022. tempIndex = ((gun_index==2) ? 1: 0);
  6023. }
  6024. else
  6025. {
  6026. tempIndex = gun_index;
  6027. }
  6028. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6029. {
  6030. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6031. {
  6032. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6033. {
  6034. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  6035. }
  6036. }
  6037. }
  6038. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6039. {
  6040. for (int index = 0; index < CCS_QUANTITY; index++)
  6041. {
  6042. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6043. {
  6044. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6045. }
  6046. }
  6047. }
  6048. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6049. {
  6050. for (int index = 0; index < GB_QUANTITY; index++)
  6051. {
  6052. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6053. {
  6054. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6055. }
  6056. }
  6057. }
  6058. else if(gunType[gun_index] == GUN_TYPE_DO)
  6059. {
  6060. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6061. {
  6062. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6063. {
  6064. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6065. }
  6066. }
  6067. }
  6068. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6070. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6071. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6072. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6073. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6074. } // END FOR DC CASE
  6075. }
  6076. // ================================= Current.Import L2 ===============================================
  6077. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6078. {
  6079. // AC 3 phse L2 current
  6080. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6081. {
  6082. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6083. {
  6084. tempIndex = 2;
  6085. }
  6086. else
  6087. {
  6088. tempIndex = gun_index;
  6089. }
  6090. for (int index = 0; index < AC_QUANTITY; index++)
  6091. {
  6092. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6093. {
  6094. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6095. }
  6096. }// End of for AC_QUANTITY
  6097. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6098. }
  6099. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6102. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6103. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6104. }
  6105. // ================================= Current.Import L3 ===============================================
  6106. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6107. {
  6108. // AC 3 phse L3 current
  6109. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6110. {
  6111. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6112. {
  6113. tempIndex = 2;
  6114. }
  6115. else
  6116. {
  6117. tempIndex = gun_index;
  6118. }
  6119. for (int index = 0; index < AC_QUANTITY; index++)
  6120. {
  6121. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6122. {
  6123. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6124. }
  6125. }// End of for AC_QUANTITY
  6126. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6127. }
  6128. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6129. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6130. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6131. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6132. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6133. }
  6134. //============================ Voltage L2 ====================================
  6135. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6136. {
  6137. // AC 3 phse L2 voltage
  6138. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6139. {
  6140. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6141. {
  6142. tempIndex = 2;
  6143. }
  6144. else
  6145. {
  6146. tempIndex = gun_index;
  6147. }
  6148. for (int index = 0; index < AC_QUANTITY; index++)
  6149. {
  6150. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6151. {
  6152. 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
  6153. }
  6154. } // END OF FOR AC_QUANTITY
  6155. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6156. }
  6157. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6158. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6159. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6160. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6161. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6162. }
  6163. //============================ Voltage L3 ====================================
  6164. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6165. {
  6166. // AC 3 phse L3 voltage
  6167. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6168. {
  6169. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6170. {
  6171. tempIndex = 2;
  6172. }
  6173. else
  6174. {
  6175. tempIndex = gun_index;
  6176. }
  6177. for (int index = 0; index < AC_QUANTITY; index++)
  6178. {
  6179. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6180. {
  6181. 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
  6182. }
  6183. } // END OF FOR AC_QUANTITY
  6184. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6185. }
  6186. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6189. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6191. }
  6192. //====================== Start SoC ================================
  6193. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6194. {
  6195. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6196. 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))
  6197. {
  6198. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6199. {
  6200. tempIndex = ((gun_index==2) ? 1: 0);
  6201. }
  6202. else
  6203. {
  6204. tempIndex = gun_index;
  6205. }
  6206. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6207. {
  6208. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6209. {
  6210. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6211. {
  6212. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6213. }
  6214. }
  6215. }
  6216. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6217. {
  6218. for (int index = 0; index < CCS_QUANTITY; index++)
  6219. {
  6220. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6221. {
  6222. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6223. }
  6224. }
  6225. }
  6226. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6227. {
  6228. for (int index = 0; index < GB_QUANTITY; index++)
  6229. {
  6230. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6231. {
  6232. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6233. }
  6234. }
  6235. }
  6236. else if(gunType[gun_index] == GUN_TYPE_DO)
  6237. {
  6238. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6239. {
  6240. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6241. {
  6242. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6243. }
  6244. }
  6245. }
  6246. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6247. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6248. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6249. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6250. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6251. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6252. } // END FOR DC CASE
  6253. }
  6254. //================================================ Message create ====================================================
  6255. json_object *StopTransaction = json_object_new_object();
  6256. json_object *transactionDatas = json_object_new_array();
  6257. json_object *sampledValues = json_object_new_array();
  6258. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6259. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6260. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6261. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6262. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6263. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6264. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6265. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6266. {
  6267. json_object *transactionData = json_object_new_object();
  6268. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6269. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6270. {
  6271. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6272. {
  6273. json_object *sampledValue = json_object_new_object();
  6274. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6275. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6276. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6277. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6278. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6279. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6280. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6281. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6282. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6283. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6284. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6285. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6286. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6287. json_object_array_add(sampledValues, sampledValue);
  6288. }
  6289. }
  6290. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6291. json_object_array_add(transactionDatas, transactionData);
  6292. }
  6293. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6294. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6295. ,MESSAGE_TYPE_CALL
  6296. ,guid
  6297. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6298. json_object_put(StopTransaction);
  6299. #if 1 // for TempStopTransaction
  6300. //Delete TempStopTransaction
  6301. if((access(TempStopTransaction,F_OK))!=-1)
  6302. {
  6303. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6304. }
  6305. #endif
  6306. #if 1
  6307. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6308. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6309. {
  6310. result = PASS;
  6311. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6312. }
  6313. #endif
  6314. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6315. OCPP_insert_transaction_msg(NO, queuedata);
  6316. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6317. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6318. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6319. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6320. {
  6321. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6322. }
  6323. //for test
  6324. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6325. return result;
  6326. }
  6327. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6328. {
  6329. mtrace();
  6330. int result = FAIL;
  6331. char guid[37]={0};
  6332. char tempdata[65]={0};
  6333. int tempIndex = 0;
  6334. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6335. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6336. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6337. //set value
  6338. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6339. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6340. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6341. -1);
  6342. random_uuid(guid);
  6343. //UTC Date time
  6344. struct timeval tmnow;
  6345. struct tm *tm;
  6346. char buf[28];//, usec_buf[6];
  6347. gettimeofday(&tmnow, NULL);
  6348. time_t t;
  6349. t = time(NULL);
  6350. /*UTC time and date*/
  6351. tm = gmtime(&t);
  6352. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6353. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6354. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6355. //********************************(1)Current.Import L1************************************************/
  6356. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6357. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6358. (dataType == ReadingContext_Trigger))
  6359. {
  6360. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6361. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6362. {
  6363. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6364. {
  6365. tempIndex = ((gun_index==2) ? 1: 0);
  6366. }
  6367. else
  6368. {
  6369. tempIndex = gun_index;
  6370. }
  6371. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6372. {
  6373. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6374. {
  6375. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6376. }
  6377. }
  6378. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6379. }
  6380. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6381. {
  6382. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6383. {
  6384. tempIndex = ((gun_index==2) ? 1: 0);
  6385. }
  6386. else
  6387. {
  6388. tempIndex = gun_index;
  6389. }
  6390. for (int index = 0; index < CCS_QUANTITY; index++)
  6391. {
  6392. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6393. {
  6394. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6395. }
  6396. }
  6397. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6398. }
  6399. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6400. {
  6401. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6402. {
  6403. tempIndex = ((gun_index==2) ? 1: 0);
  6404. }
  6405. else
  6406. {
  6407. tempIndex = gun_index;
  6408. }
  6409. for (int index = 0; index < GB_QUANTITY; index++)
  6410. {
  6411. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6412. {
  6413. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6414. }
  6415. }
  6416. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6417. }
  6418. else if(gunType[gun_index] == GUN_TYPE_DO)
  6419. {
  6420. tempIndex = gun_index;
  6421. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6422. {
  6423. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6424. {
  6425. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6426. }
  6427. }
  6428. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6429. }
  6430. else
  6431. {
  6432. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6433. {
  6434. tempIndex = 2;
  6435. }
  6436. else
  6437. {
  6438. tempIndex = gun_index;
  6439. }
  6440. for (int index = 0; index < AC_QUANTITY; index++)
  6441. {
  6442. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6443. {
  6444. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6445. }
  6446. }
  6447. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6448. }
  6449. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6450. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6451. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6452. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6453. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6454. }
  6455. //********************************(2)Energy.Active.Import.Register ************************************************/
  6456. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6457. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6458. (dataType == ReadingContext_Trigger))
  6459. {
  6460. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6461. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6462. {
  6463. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6464. {
  6465. tempIndex = ((gun_index==2) ? 1: 0);
  6466. }
  6467. else
  6468. {
  6469. tempIndex = gun_index;
  6470. }
  6471. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6472. {
  6473. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6474. {
  6475. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6476. }
  6477. }
  6478. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6479. }
  6480. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6481. {
  6482. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6483. {
  6484. tempIndex = ((gun_index==2) ? 1: 0);
  6485. }
  6486. else
  6487. {
  6488. tempIndex = gun_index;
  6489. }
  6490. for (int index = 0; index < CCS_QUANTITY; index++)
  6491. {
  6492. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6493. {
  6494. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6495. }
  6496. }
  6497. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6498. }
  6499. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6500. {
  6501. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6502. {
  6503. tempIndex = ((gun_index==2) ? 1: 0);
  6504. }
  6505. else
  6506. {
  6507. tempIndex = gun_index;
  6508. }
  6509. for (int index = 0; index < GB_QUANTITY; index++)
  6510. {
  6511. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6512. {
  6513. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6514. }
  6515. }
  6516. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6517. }
  6518. else if(gunType[gun_index] == GUN_TYPE_DO)
  6519. {
  6520. tempIndex = gun_index;
  6521. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6522. {
  6523. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6524. {
  6525. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6526. }
  6527. }
  6528. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6529. }
  6530. else
  6531. {
  6532. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6533. {
  6534. tempIndex = 2;
  6535. }
  6536. else
  6537. {
  6538. tempIndex = gun_index;
  6539. }
  6540. for (int index = 0; index < AC_QUANTITY; index++)
  6541. {
  6542. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6543. {
  6544. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6545. }
  6546. }
  6547. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6548. }
  6549. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6550. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6551. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6552. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6553. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6554. }
  6555. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6556. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6557. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6558. (dataType == ReadingContext_Trigger))
  6559. {
  6560. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6561. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6562. {
  6563. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6564. {
  6565. tempIndex = ((gun_index==2) ? 1: 0);
  6566. }
  6567. else
  6568. {
  6569. tempIndex = gun_index;
  6570. }
  6571. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6572. {
  6573. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6574. {
  6575. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6576. }
  6577. } // END OF FOR CHAdeMO_QUANTITY
  6578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6579. }
  6580. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6581. {
  6582. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6583. {
  6584. tempIndex = ((gun_index==2) ? 1: 0);
  6585. }
  6586. else
  6587. {
  6588. tempIndex = gun_index;
  6589. }
  6590. for (int index = 0; index < CCS_QUANTITY; index++)
  6591. {
  6592. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6593. {
  6594. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6595. }
  6596. } // END OF CCS_QUANTITY
  6597. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6598. }
  6599. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6600. {
  6601. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6602. {
  6603. tempIndex = ((gun_index==2) ? 1: 0);
  6604. }
  6605. else
  6606. {
  6607. tempIndex = gun_index;
  6608. }
  6609. for (int index = 0; index < GB_QUANTITY; index++)
  6610. {
  6611. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6612. {
  6613. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6614. }
  6615. } // END OF GB_QUANTITY
  6616. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6617. }
  6618. else if(gunType[gun_index] == GUN_TYPE_DO)
  6619. {
  6620. tempIndex = gun_index;
  6621. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6622. {
  6623. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6624. {
  6625. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6626. }
  6627. }
  6628. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6629. }
  6630. else
  6631. {
  6632. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6633. {
  6634. tempIndex = 2;
  6635. }
  6636. else
  6637. {
  6638. tempIndex = gun_index;
  6639. }
  6640. for (int index = 0; index < AC_QUANTITY; index++)
  6641. {
  6642. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6643. {
  6644. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6645. }
  6646. }
  6647. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6648. }
  6649. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6650. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6651. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6652. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6653. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6654. }
  6655. //********************************(4)Power.Active.Import************************************************/
  6656. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6657. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6658. (dataType == ReadingContext_Trigger))
  6659. {
  6660. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6661. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6662. {
  6663. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6664. {
  6665. tempIndex = ((gun_index==2) ? 1: 0);
  6666. }
  6667. else
  6668. {
  6669. tempIndex = gun_index;
  6670. }
  6671. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6672. {
  6673. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6674. {
  6675. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6676. }
  6677. } // END OF FOR
  6678. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6679. }
  6680. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6681. {
  6682. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6683. {
  6684. tempIndex = ((gun_index==2) ? 1: 0);
  6685. }
  6686. else
  6687. {
  6688. tempIndex = gun_index;
  6689. }
  6690. for (int index = 0; index < CCS_QUANTITY; index++)
  6691. {
  6692. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6693. {
  6694. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6695. }
  6696. }
  6697. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6698. }
  6699. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6700. {
  6701. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6702. {
  6703. tempIndex = ((gun_index==2) ? 1: 0);
  6704. }
  6705. else
  6706. {
  6707. tempIndex = gun_index;
  6708. }
  6709. for (int index = 0; index < GB_QUANTITY; index++)
  6710. {
  6711. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6712. {
  6713. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6714. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6715. }
  6716. }
  6717. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6718. }
  6719. else if(gunType[gun_index] == GUN_TYPE_DO)
  6720. {
  6721. tempIndex = gun_index;
  6722. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6723. {
  6724. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6725. {
  6726. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6727. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6728. }
  6729. }
  6730. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6731. }
  6732. else
  6733. {
  6734. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6735. {
  6736. tempIndex = 2;
  6737. }
  6738. else
  6739. {
  6740. tempIndex = gun_index;
  6741. }
  6742. for (int index = 0; index < AC_QUANTITY; index++)
  6743. {
  6744. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6745. {
  6746. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6747. }
  6748. }
  6749. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6750. }
  6751. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6752. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6753. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6754. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6755. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6756. }
  6757. //***********************************************(5)VOLTAGE L1******************************************************/
  6758. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6759. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6760. (dataType == ReadingContext_Trigger))
  6761. {
  6762. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6763. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6764. {
  6765. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6766. {
  6767. tempIndex = ((gun_index==2) ? 1: 0);
  6768. }
  6769. else
  6770. {
  6771. tempIndex = gun_index;
  6772. }
  6773. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6774. {
  6775. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6776. {
  6777. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6778. }
  6779. }
  6780. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6781. }
  6782. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6783. {
  6784. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6785. {
  6786. tempIndex = ((gun_index==2) ? 1: 0);
  6787. }
  6788. else
  6789. {
  6790. tempIndex = gun_index;
  6791. }
  6792. for (int index = 0; index < CCS_QUANTITY; index++)
  6793. {
  6794. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6795. {
  6796. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6797. }
  6798. }
  6799. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6800. }
  6801. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6802. {
  6803. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6804. {
  6805. tempIndex = ((gun_index==2) ? 1: 0);
  6806. }
  6807. else
  6808. {
  6809. tempIndex = gun_index;
  6810. }
  6811. for (int index = 0; index < GB_QUANTITY; index++)
  6812. {
  6813. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6814. {
  6815. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6816. }
  6817. }
  6818. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6819. }
  6820. else if(gunType[gun_index] == GUN_TYPE_DO)
  6821. {
  6822. tempIndex = gun_index;
  6823. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6824. {
  6825. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6826. {
  6827. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6828. }
  6829. }
  6830. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6831. }
  6832. else
  6833. {
  6834. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6835. {
  6836. tempIndex = 2;
  6837. }
  6838. else
  6839. {
  6840. tempIndex = gun_index;
  6841. }
  6842. for (int index = 0; index < AC_QUANTITY; index++)
  6843. {
  6844. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6845. {
  6846. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6847. }
  6848. }
  6849. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6850. }
  6851. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6852. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6853. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6854. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6855. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6856. }
  6857. //***********************************************(6)SOC******************************************************/
  6858. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6859. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6860. (dataType == ReadingContext_Trigger))
  6861. {
  6862. 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))
  6863. {
  6864. //idx_sample=5;
  6865. //sampledValue = NULL;
  6866. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6867. {
  6868. tempIndex = ((gun_index==2) ? 1: 0);
  6869. }
  6870. else
  6871. {
  6872. tempIndex = gun_index;
  6873. }
  6874. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6875. {
  6876. //tempIndex = ((gun_index==2) ? 1: 0);
  6877. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6878. {
  6879. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6880. {
  6881. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6882. }
  6883. }
  6884. }
  6885. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6886. {
  6887. //tempIndex = ((gun_index==2) ? 1: 0);
  6888. for (int index = 0; index < CCS_QUANTITY; index++)
  6889. {
  6890. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6891. {
  6892. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6893. }
  6894. }
  6895. }
  6896. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6897. {
  6898. //tempIndex = ((gun_index==2) ? 1: 0);
  6899. for (int index = 0; index < GB_QUANTITY; index++)
  6900. {
  6901. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6902. {
  6903. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6904. }
  6905. }
  6906. }
  6907. else if(gunType[gun_index] == GUN_TYPE_DO)
  6908. {
  6909. //tempIndex = ((gun_index==2) ? 1: 0);
  6910. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6911. {
  6912. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6913. {
  6914. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6915. }
  6916. }
  6917. }
  6918. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6919. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6920. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6921. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6922. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6923. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6924. }
  6925. }
  6926. //********************************(7)Current.Import L2************************************************/
  6927. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6928. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6929. (dataType == ReadingContext_Trigger))
  6930. {
  6931. // Only for AC 3 phase
  6932. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6933. {
  6934. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6935. {
  6936. tempIndex = 2;
  6937. }
  6938. else
  6939. {
  6940. tempIndex = gun_index;
  6941. }
  6942. for (int index = 0; index < AC_QUANTITY; index++)
  6943. {
  6944. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6945. {
  6946. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6947. }
  6948. }
  6949. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6950. }
  6951. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6952. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6953. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6954. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6955. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6956. }
  6957. //********************************(8)Current.Import L3************************************************/
  6958. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6959. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6960. (dataType == ReadingContext_Trigger))
  6961. {
  6962. // Only for AC 3 phase
  6963. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6964. {
  6965. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6966. {
  6967. tempIndex = 2;
  6968. }
  6969. else
  6970. {
  6971. tempIndex = gun_index;
  6972. }
  6973. for (int index = 0; index < AC_QUANTITY; index++)
  6974. {
  6975. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6976. {
  6977. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6978. }
  6979. }
  6980. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6981. }
  6982. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6983. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6984. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6985. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6986. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6987. }
  6988. //***********************************************(9)VOLTAGE L2******************************************************/
  6989. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6990. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6991. (dataType == ReadingContext_Trigger))
  6992. {
  6993. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6994. {
  6995. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6996. {
  6997. tempIndex = 2;
  6998. }
  6999. else
  7000. {
  7001. tempIndex = gun_index;
  7002. }
  7003. for (int index = 0; index < AC_QUANTITY; index++)
  7004. {
  7005. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7006. {
  7007. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7008. }
  7009. }
  7010. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7011. }
  7012. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7013. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7014. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7015. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7016. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7017. }
  7018. //***********************************************(10)VOLTAGE L3******************************************************/
  7019. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7020. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7021. (dataType == ReadingContext_Trigger))
  7022. {
  7023. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7024. {
  7025. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7026. {
  7027. tempIndex = 2;
  7028. }
  7029. else
  7030. {
  7031. tempIndex = gun_index;
  7032. }
  7033. for (int index = 0; index < AC_QUANTITY; index++)
  7034. {
  7035. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7036. {
  7037. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7038. }
  7039. }
  7040. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7041. }
  7042. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7043. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7044. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7045. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7046. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7047. }
  7048. //***********************************************(11)Current.Offered******************************************************/
  7049. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7050. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7051. (dataType == ReadingContext_Trigger))
  7052. {
  7053. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7054. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7055. {
  7056. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7057. {
  7058. tempIndex = ((gun_index==2) ? 1: 0);
  7059. }
  7060. else
  7061. {
  7062. tempIndex = gun_index;
  7063. }
  7064. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7065. {
  7066. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7067. {
  7068. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7069. }
  7070. } // END OF FOR CHAdeMO_QUANTITY
  7071. }
  7072. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7073. {
  7074. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7075. {
  7076. tempIndex = ((gun_index==2) ? 1: 0);
  7077. }
  7078. else
  7079. {
  7080. tempIndex = gun_index;
  7081. }
  7082. for (int index = 0; index < CCS_QUANTITY; index++)
  7083. {
  7084. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7085. {
  7086. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7087. }
  7088. } // END OF CCS_QUANTITY
  7089. }
  7090. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7091. {
  7092. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7093. {
  7094. tempIndex = ((gun_index==2) ? 1: 0);
  7095. }
  7096. else
  7097. {
  7098. tempIndex = gun_index;
  7099. }
  7100. for (int index = 0; index < GB_QUANTITY; index++)
  7101. {
  7102. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7103. {
  7104. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7105. }
  7106. } // END OF GB_QUANTITY
  7107. }
  7108. else if(gunType[gun_index] == GUN_TYPE_DO)
  7109. {
  7110. tempIndex = gun_index;
  7111. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7112. {
  7113. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7114. {
  7115. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7116. }
  7117. }
  7118. }
  7119. else
  7120. {
  7121. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7122. {
  7123. tempIndex = 2;
  7124. }
  7125. else
  7126. {
  7127. tempIndex = gun_index;
  7128. }
  7129. for (int index = 0; index < AC_QUANTITY; index++)
  7130. {
  7131. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7132. {
  7133. uint16_t currentOffer;
  7134. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7135. {
  7136. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7137. }
  7138. else
  7139. {
  7140. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7141. }
  7142. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7143. }
  7144. }
  7145. }
  7146. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7147. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7148. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7149. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7150. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7151. }
  7152. //***********************************************(12)Power.Offered******************************************************/
  7153. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7154. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7155. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7156. {
  7157. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7158. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7159. {
  7160. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7161. {
  7162. tempIndex = ((gun_index==2) ? 1: 0);
  7163. }
  7164. else
  7165. {
  7166. tempIndex = gun_index;
  7167. }
  7168. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7169. {
  7170. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7171. {
  7172. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7173. }
  7174. } // END OF FOR CHAdeMO_QUANTITY
  7175. }
  7176. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7177. {
  7178. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7179. {
  7180. tempIndex = ((gun_index==2) ? 1: 0);
  7181. }
  7182. else
  7183. {
  7184. tempIndex = gun_index;
  7185. }
  7186. for (int index = 0; index < CCS_QUANTITY; index++)
  7187. {
  7188. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7189. {
  7190. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7191. }
  7192. } // END OF CCS_QUANTITY
  7193. }
  7194. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7195. {
  7196. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7197. {
  7198. tempIndex = ((gun_index==2) ? 1: 0);
  7199. }
  7200. else
  7201. {
  7202. tempIndex = gun_index;
  7203. }
  7204. for (int index = 0; index < GB_QUANTITY; index++)
  7205. {
  7206. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7207. {
  7208. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7209. }
  7210. } // END OF GB_QUANTITY
  7211. }
  7212. else if(gunType[gun_index] == GUN_TYPE_DO)
  7213. {
  7214. tempIndex = gun_index;
  7215. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7216. {
  7217. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7218. {
  7219. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7220. }
  7221. }
  7222. }
  7223. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7224. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7225. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7226. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7227. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7228. }
  7229. // Message create ====================================================================================================
  7230. if(TRUE)
  7231. {
  7232. json_object *MeterValueReq = json_object_new_object();
  7233. json_object *MeterValues = json_object_new_array();
  7234. json_object *sampledValues = json_object_new_array();
  7235. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7236. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7237. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7238. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7239. {
  7240. json_object *MeterValue = json_object_new_object();
  7241. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7242. {
  7243. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7244. {
  7245. json_object *sampledValue = json_object_new_object();
  7246. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7247. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7248. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7249. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7250. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7251. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7252. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7253. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7254. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7255. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7256. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7257. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7258. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7259. json_object_array_add(sampledValues, sampledValue);
  7260. }
  7261. }
  7262. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7263. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7264. json_object_array_add(MeterValues, MeterValue);
  7265. }
  7266. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7267. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7268. ,gun_index + 1
  7269. ,MESSAGE_TYPE_CALL
  7270. ,guid
  7271. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7272. json_object_put(MeterValueReq);
  7273. }
  7274. // Put request guid to hash map
  7275. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7276. 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*/)
  7277. {
  7278. result = PASS;
  7279. //DEBUG_INFO("MeterValues mapitem pass\n");
  7280. }
  7281. if((dataType != ReadingContext_Trigger) &&
  7282. (dataType != ReadingContext_Sample_Clock) &&
  7283. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7284. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7285. else
  7286. {
  7287. if(FirstHeartBeat)
  7288. LWS_Send(queuedata +2);
  7289. }
  7290. return result;
  7291. }
  7292. int sendLogStatusNotificationRequest(char *status)
  7293. {
  7294. mtrace();
  7295. int result = PASS;
  7296. char message[4096]={0};
  7297. char guid[37]={0};
  7298. char tempdata[128]={0};
  7299. json_object *LogStatusNotification = json_object_new_object();
  7300. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7301. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7302. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7303. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7304. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7305. random_uuid(guid);
  7306. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7307. json_object_put(LogStatusNotification);
  7308. LWS_Send(message);
  7309. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7310. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7311. {
  7312. result = PASS;
  7313. }
  7314. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7315. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7316. return result;
  7317. }
  7318. int sendSecurityEventNotificationRequest()
  7319. {
  7320. mtrace();
  7321. int result = PASS;
  7322. char message[4096]={0};
  7323. char guid[37]={0};
  7324. char tempdata[128]={0};
  7325. json_object *SecurityEventNotification = json_object_new_object();
  7326. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7327. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7328. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7329. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7330. random_uuid(guid);
  7331. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7332. json_object_put(SecurityEventNotification);
  7333. LWS_Send(message);
  7334. sprintf(tempdata, "SecurityEventNotification,0");
  7335. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7336. {
  7337. result = PASS;
  7338. }
  7339. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7340. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7341. return result;
  7342. }
  7343. int sendSignCertificateRequest()
  7344. {
  7345. mtrace();
  7346. int result = PASS;
  7347. char message[4096]={0};
  7348. char guid[37]={0};
  7349. char tempdata[128]={0};
  7350. json_object *SignCertificate = json_object_new_object();
  7351. DEBUG_INFO("sendSignCertificateRequest...\n");
  7352. // Read csr file content
  7353. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7354. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7355. char *line = NULL;
  7356. size_t len = 0;
  7357. while(getline(&line, &len, fp) != -1)
  7358. {
  7359. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7360. {
  7361. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7362. }
  7363. }
  7364. fclose(fp);
  7365. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7366. random_uuid(guid);
  7367. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7368. json_object_put(SignCertificate);
  7369. LWS_Send(message);
  7370. sprintf(tempdata, "SignCertificate,0");
  7371. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7372. {
  7373. result = PASS;
  7374. }
  7375. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7376. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7377. return result;
  7378. }
  7379. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7380. {
  7381. mtrace();
  7382. int result = PASS;
  7383. char message[110]={0};
  7384. char guid[37]={0};
  7385. char tempdata[65]={0};
  7386. json_object *FirmwareStatusNotification = json_object_new_object();
  7387. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7388. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7389. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7390. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7391. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7392. random_uuid(guid);
  7393. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7394. json_object_put(FirmwareStatusNotification);
  7395. LWS_Send(message);
  7396. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7397. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7398. {
  7399. result = PASS;
  7400. }
  7401. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7402. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7403. return result;
  7404. }
  7405. //==========================================
  7406. // send confirm routine
  7407. //==========================================
  7408. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7409. {
  7410. mtrace();
  7411. int result = FAIL;
  7412. char message[100]={0};
  7413. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7414. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7415. LWS_Send(message);
  7416. result = TRUE;
  7417. return result;
  7418. }
  7419. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7420. {
  7421. mtrace();
  7422. int result = FAIL;
  7423. char message[100]={0};
  7424. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7425. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7426. LWS_Send(message);
  7427. result = TRUE;
  7428. return result;
  7429. }
  7430. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7431. {
  7432. mtrace();
  7433. int result = FAIL;
  7434. char message[100]={0};
  7435. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7436. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7437. LWS_Send(message);
  7438. result = TRUE;
  7439. return result;
  7440. }
  7441. int sendClearCacheConfirmation(char *uuid,char *payload)
  7442. {
  7443. mtrace();
  7444. int result = FAIL;
  7445. char message[500]={0};
  7446. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7447. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7448. LWS_Send(message);
  7449. return result;
  7450. }
  7451. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7452. {
  7453. mtrace();
  7454. int result = FAIL;
  7455. char message[500]={0};
  7456. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7457. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7458. LWS_Send(message);
  7459. return result;
  7460. }
  7461. int sendDataTransferConfirmation(char *uuid,char *payload)
  7462. {
  7463. mtrace();
  7464. char statusStr[20]={0};
  7465. char dataStr[10]={0};
  7466. char sstr[20]={0};
  7467. int c = 0;
  7468. char *loc;
  7469. int result = FAIL;
  7470. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7471. /**********************status**************************/
  7472. loc = strstr(payload, "status");
  7473. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7474. c = 0;
  7475. while (loc[3+strlen("status")+c] != '\"')
  7476. {
  7477. sstr[c] = loc[3+strlen("status")+c];
  7478. c++;
  7479. }
  7480. sstr[c] = '\0';
  7481. strcpy(statusStr, sstr);
  7482. /**********************data**************************/
  7483. loc = strstr(payload, "data");
  7484. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7485. c = 0;
  7486. while (loc[3+strlen("data")+c] != '\"')
  7487. {
  7488. sstr[c] = loc[3+strlen("data")+c];
  7489. c++;
  7490. }
  7491. sstr[c] = '\0';
  7492. strcpy(dataStr, sstr);
  7493. return result;
  7494. }
  7495. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7496. {
  7497. mtrace();
  7498. int result = FAIL;
  7499. char message[1000]={0};
  7500. int CompositeScheduleIndex = 0;
  7501. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7502. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7503. if(nPeriod == 0)
  7504. {
  7505. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7506. {
  7507. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7508. ,MESSAGE_TYPE_CALLRESULT
  7509. ,uuid
  7510. ,payload
  7511. ,connectorIdInt);
  7512. }
  7513. else
  7514. {
  7515. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7516. ,MESSAGE_TYPE_CALLRESULT
  7517. ,uuid
  7518. ,payload
  7519. ,connectorIdInt
  7520. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7521. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7522. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7523. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7524. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7525. }
  7526. }
  7527. else
  7528. {
  7529. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7530. ,MESSAGE_TYPE_CALLRESULT
  7531. ,uuid
  7532. ,payload
  7533. ,connectorIdInt
  7534. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7535. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7536. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7537. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7538. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7539. {
  7540. if (idx_sample == 0)
  7541. {
  7542. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7543. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7544. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7545. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7546. }
  7547. else
  7548. {
  7549. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7550. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7551. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7552. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7553. }
  7554. }
  7555. sprintf(message + strlen(message), "]}}]");
  7556. }
  7557. LWS_Send(message);
  7558. result = TRUE;
  7559. return result;
  7560. }
  7561. int sendGetConfigurationConfirmation(char *uuid)
  7562. {
  7563. mtrace();
  7564. int result = FAIL;
  7565. int MaxKeySupported = 0;
  7566. int sentConfigurationNumber= 0;
  7567. int sentunConfigurationNumber= 0;
  7568. char message[1024*10]={0};
  7569. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7570. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7571. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7572. ,MESSAGE_TYPE_CALLRESULT
  7573. ,uuid );
  7574. //configuration key
  7575. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7576. {
  7577. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7578. {
  7579. if (sentConfigurationNumber == 0)
  7580. {
  7581. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7582. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7583. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7584. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7585. }
  7586. else
  7587. {
  7588. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7589. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7590. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7591. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7592. }
  7593. sentConfigurationNumber = sentConfigurationNumber + 1;
  7594. }
  7595. }
  7596. sprintf(message + strlen(message), "]");
  7597. if(UnknownKeynum != 0)
  7598. {
  7599. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7600. //unkown key
  7601. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7602. {
  7603. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7604. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7605. if(sentunConfigurationNumber == 0)
  7606. {
  7607. sprintf(message + strlen(message), "\"%s\""
  7608. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7609. }
  7610. else
  7611. {
  7612. sprintf(message + strlen(message), ",\"%s\""
  7613. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7614. }
  7615. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7616. }
  7617. sprintf(message + strlen(message), "]");
  7618. }
  7619. sprintf(message + strlen(message), "}]");
  7620. LWS_Send(message);
  7621. return result;
  7622. }
  7623. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7624. {
  7625. mtrace();
  7626. int result = FAIL;
  7627. char message[400]={0};
  7628. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7629. if(strcmp(payload,"")==0)
  7630. {
  7631. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7632. }
  7633. else
  7634. {
  7635. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7636. }
  7637. LWS_Send(message);
  7638. result = TRUE;
  7639. return result;
  7640. }
  7641. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7642. {
  7643. mtrace();
  7644. int result = FAIL;
  7645. char message[80]={0};
  7646. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7647. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  7648. LWS_Send(message);
  7649. result = TRUE;
  7650. return result;
  7651. }
  7652. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7653. {
  7654. mtrace();
  7655. int result = FAIL;
  7656. char message[80]={0};
  7657. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7658. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7659. LWS_Send(message);
  7660. result = TRUE;
  7661. return result;
  7662. }
  7663. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7664. {
  7665. mtrace();
  7666. int result = FAIL;
  7667. char message[80]={0};
  7668. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7669. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7670. LWS_Send(message);
  7671. result = TRUE;
  7672. return result;
  7673. }
  7674. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7675. {
  7676. mtrace();
  7677. int result = FAIL;
  7678. char message[80]={0};
  7679. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7680. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7681. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7682. LWS_Send(message);
  7683. result = TRUE;
  7684. return result;
  7685. }
  7686. int sendResetConfirmation(char *uuid,char *payload)
  7687. {
  7688. mtrace();
  7689. int result = FAIL;
  7690. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7691. char message[80]={0};
  7692. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  7693. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7694. LWS_Send(message);
  7695. result = TRUE;
  7696. return result;
  7697. }
  7698. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7699. {
  7700. mtrace();
  7701. int result = FAIL;
  7702. char message[500]={0};
  7703. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7704. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7705. LWS_Send(message);
  7706. result = TRUE;
  7707. return result;
  7708. }
  7709. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7710. {
  7711. mtrace();
  7712. int result = FAIL;
  7713. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7714. char message[80]={0};
  7715. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7716. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7717. LWS_Send(message);
  7718. result = TRUE;
  7719. return result;
  7720. }
  7721. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7722. {
  7723. mtrace();
  7724. int result = FAIL;
  7725. char message[80]={0};
  7726. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7727. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7728. LWS_Send(message);
  7729. result = TRUE;
  7730. return result;
  7731. }
  7732. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7733. {
  7734. mtrace();
  7735. int result = FAIL;
  7736. char message[80]={0};
  7737. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7738. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7739. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7740. LWS_Send(message);
  7741. result = TRUE;
  7742. return result;
  7743. }
  7744. int sendUpdateFirmwareConfirmation(char *uuid)
  7745. {
  7746. mtrace();
  7747. int result = FAIL;
  7748. char message[60]={0};
  7749. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7750. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7751. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7752. LWS_Send(message);
  7753. result = TRUE;
  7754. return result;
  7755. }
  7756. int sendCertificateSignedConfirmation(char *uuid)
  7757. {
  7758. mtrace();
  7759. int result = PASS;
  7760. char message[4096]={0};
  7761. json_object *CertificateSigned = json_object_new_object();
  7762. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7763. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  7764. sprintf(message,"[%d,\"%s\",%s]"
  7765. ,MESSAGE_TYPE_CALLRESULT
  7766. ,uuid
  7767. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7768. json_object_put(CertificateSigned);
  7769. LWS_Send(message);
  7770. return result;
  7771. }
  7772. int sendDeleteCertificateConfirmation(char *uuid)
  7773. {
  7774. mtrace();
  7775. int result = PASS;
  7776. char message[4096]={0};
  7777. json_object *DeleteCertificate = json_object_new_object();
  7778. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7779. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  7780. sprintf(message,"[%d,\"%s\",%s]"
  7781. ,MESSAGE_TYPE_CALLRESULT
  7782. ,uuid
  7783. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7784. json_object_put(DeleteCertificate);
  7785. LWS_Send(message);
  7786. return result;
  7787. }
  7788. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7789. {
  7790. mtrace();
  7791. int result = PASS;
  7792. char message[4096]={0};
  7793. json_object *ExtendedTriggerMessage = json_object_new_object();
  7794. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7795. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  7796. sprintf(message,"[%d,\"%s\",%s]"
  7797. ,MESSAGE_TYPE_CALLRESULT
  7798. ,uuid
  7799. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7800. json_object_put(ExtendedTriggerMessage);
  7801. LWS_Send(message);
  7802. return result;
  7803. }
  7804. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7805. {
  7806. mtrace();
  7807. int result = PASS;
  7808. char message[4096]={0};
  7809. json_object *GetInstalledCertificateIds = json_object_new_object();
  7810. json_object *certificateHashDataDatas = json_object_new_array();
  7811. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7812. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  7813. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7814. {
  7815. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7816. {
  7817. json_object *certificateHashData = json_object_new_object();
  7818. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7819. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7820. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7821. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7822. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7823. }
  7824. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7825. }
  7826. else
  7827. {
  7828. json_object_put(certificateHashDataDatas);
  7829. }
  7830. sprintf(message,"[%d,\"%s\",%s]"
  7831. ,MESSAGE_TYPE_CALLRESULT
  7832. ,uuid
  7833. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7834. json_object_put(GetInstalledCertificateIds);
  7835. LWS_Send(message);
  7836. return result;
  7837. }
  7838. int sendGetLogConfirmation(char *uuid)
  7839. {
  7840. mtrace();
  7841. int result = PASS;
  7842. char message[4096]={0};
  7843. json_object *GetLog = json_object_new_object();
  7844. DEBUG_INFO("sendGetLogConfirmation...\n");
  7845. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  7846. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  7847. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  7848. sprintf(message,"[%d,\"%s\",%s]"
  7849. ,MESSAGE_TYPE_CALLRESULT
  7850. ,uuid
  7851. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7852. json_object_put(GetLog);
  7853. LWS_Send(message);
  7854. return result;
  7855. }
  7856. int sendInstallCertificateConfirmation(char *uuid)
  7857. {
  7858. mtrace();
  7859. int result = PASS;
  7860. char message[4096]={0};
  7861. json_object *InstallCertificate = json_object_new_object();
  7862. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7863. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  7864. sprintf(message,"[%d,\"%s\",%s]"
  7865. ,MESSAGE_TYPE_CALLRESULT
  7866. ,uuid
  7867. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7868. json_object_put(InstallCertificate);
  7869. LWS_Send(message);
  7870. return result;
  7871. }
  7872. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7873. {
  7874. mtrace();
  7875. int result = PASS;
  7876. char message[4096]={0};
  7877. json_object *SignedUpdateFirmware = json_object_new_object();
  7878. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7879. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  7880. sprintf(message,"[%d,\"%s\",%s]"
  7881. ,MESSAGE_TYPE_CALLRESULT
  7882. ,uuid
  7883. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7884. json_object_put(SignedUpdateFirmware);
  7885. LWS_Send(message);
  7886. return result;
  7887. }
  7888. int sendUnknownConfirmation(char *uuid)
  7889. {
  7890. mtrace();
  7891. int result = PASS;
  7892. char message[256]={0};
  7893. DEBUG_INFO("sendUnknownConfirmation...\n");
  7894. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7895. LWS_Send(message);
  7896. return result;
  7897. }
  7898. //==========================================
  7899. // Handle server request routine Start
  7900. //==========================================
  7901. int handleCancelReservationRequest(char *uuid, char *payload)
  7902. {
  7903. mtrace();
  7904. int result = FAIL;
  7905. int gunNO = 0;
  7906. int reservationIdInt = -1;
  7907. char comfirmstr[20];
  7908. DEBUG_INFO("handleCancelReservationRequest...\n");
  7909. json_object *CancelReservation;
  7910. CancelReservation = json_tokener_parse(payload);
  7911. if(!is_error(CancelReservation))
  7912. {
  7913. // Required data
  7914. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7915. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7916. }
  7917. json_object_put(CancelReservation);
  7918. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7919. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7920. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7921. if(reservationIdInt != -1)
  7922. {
  7923. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7924. //check Transaction active
  7925. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7926. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7927. {
  7928. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7929. {
  7930. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7931. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7932. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7933. {
  7934. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7935. }
  7936. else
  7937. {
  7938. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7939. }
  7940. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7941. goto end;
  7942. }
  7943. }
  7944. for (int index = 0; index < CCS_QUANTITY; index++)
  7945. {
  7946. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7947. {
  7948. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7949. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7950. if(gunType[2] == GUN_TYPE_CCS)
  7951. {
  7952. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7953. }
  7954. else
  7955. {
  7956. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7957. }
  7958. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7959. goto end;
  7960. }
  7961. }
  7962. for (int index = 0; index < GB_QUANTITY; index++)
  7963. {
  7964. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7965. {
  7966. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7967. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7968. if(gunType[2] == GUN_TYPE_GBT)
  7969. {
  7970. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7971. }
  7972. else
  7973. {
  7974. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7975. }
  7976. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7977. goto end;
  7978. }
  7979. }
  7980. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7981. {
  7982. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7983. {
  7984. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7985. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7986. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7987. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7988. goto end;
  7989. }
  7990. }
  7991. for (int index = 0; index < AC_QUANTITY; index++)
  7992. {
  7993. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7994. {
  7995. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7996. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7997. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7998. {
  7999. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8000. }
  8001. else
  8002. {
  8003. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8004. }
  8005. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8006. goto end;
  8007. }
  8008. }
  8009. }
  8010. //The reservationId does NOT match the reservationId
  8011. sendCancelReservationConfirmation(uuid, comfirmstr);
  8012. end:
  8013. // Fill in ocpp packet uuid
  8014. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8015. return result;
  8016. }
  8017. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8018. {
  8019. mtrace();
  8020. int result = FAIL;
  8021. int gunIndex = -1;
  8022. char typeStr[16]={0};
  8023. char comfirmstr[20];
  8024. int specificId = FALSE;
  8025. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8026. json_object *ChangeAvailability;
  8027. ChangeAvailability = json_tokener_parse(payload);
  8028. if(!is_error(ChangeAvailability))
  8029. {
  8030. // Required data
  8031. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8032. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8033. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8034. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8035. }
  8036. json_object_put(ChangeAvailability);
  8037. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8038. {
  8039. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8040. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8041. }
  8042. else if(gunIndex == 0)
  8043. {
  8044. for(int i=0; i < gunTotalNumber; i++)
  8045. {
  8046. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8047. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8048. }
  8049. }
  8050. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8051. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8052. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8053. {
  8054. specificId = TRUE;
  8055. }
  8056. if(specificId == FALSE)
  8057. goto end;
  8058. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8059. {
  8060. //----------------------gunIndex is 0 ------------------------------------------------//
  8061. if(gunIndex == 0)
  8062. {
  8063. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8064. {
  8065. for(int i=0; i < gunTotalNumber; i++)
  8066. {
  8067. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8068. {
  8069. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8070. {
  8071. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8072. {
  8073. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8074. goto end;
  8075. }
  8076. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8077. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8078. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8079. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8080. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8081. {
  8082. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8083. goto end;
  8084. }
  8085. }
  8086. }//END FOR CHAdeMO_QUANTITY
  8087. for (int index = 0; index < CCS_QUANTITY; index++)
  8088. {
  8089. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8090. {
  8091. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8092. {
  8093. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8094. goto end;
  8095. }
  8096. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8097. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8098. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8099. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8100. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8101. {
  8102. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8103. goto end;
  8104. }
  8105. }
  8106. }//END FOR CCS_QUANTITY
  8107. for (int index = 0; index < GB_QUANTITY; index++)
  8108. {
  8109. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8110. {
  8111. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8112. {
  8113. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8114. goto end;
  8115. }
  8116. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8117. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8118. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8119. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8120. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8121. {
  8122. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8123. goto end;
  8124. }
  8125. }
  8126. }// END FOR GB_QUANTITY
  8127. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8128. {
  8129. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8130. {
  8131. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8132. {
  8133. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8134. goto end;
  8135. }
  8136. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8137. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8138. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8139. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8140. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8141. {
  8142. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8143. goto end;
  8144. }
  8145. }
  8146. }// END FOR GENERAL_GUN_QUANTITY
  8147. for (int index = 0; index < AC_QUANTITY; index++)
  8148. {
  8149. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8150. {
  8151. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8152. {
  8153. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8154. goto end;
  8155. }
  8156. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8157. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8158. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8159. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8160. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8161. {
  8162. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8163. goto end;
  8164. }
  8165. }
  8166. }//END FOR AC_QUANTITY
  8167. }// END FOR gunTotalNumber
  8168. }
  8169. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8170. {
  8171. for(int i=0; i < gunTotalNumber; i++)
  8172. {
  8173. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8174. {
  8175. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8176. goto end;
  8177. }
  8178. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8179. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8180. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8181. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8182. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8183. {
  8184. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8185. goto end;
  8186. }
  8187. }
  8188. }
  8189. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8190. goto end;
  8191. }
  8192. //----------------------gunIndex is not 0 ------------------------------------------------//
  8193. //check Transaction active
  8194. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8195. {
  8196. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8197. {
  8198. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8199. {
  8200. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8201. goto end;
  8202. }
  8203. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8204. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8205. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8206. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8207. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8208. {
  8209. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8210. goto end;
  8211. }
  8212. else
  8213. {
  8214. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8215. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8216. goto end;
  8217. }
  8218. }
  8219. }//END FOR CHAdeMO_QUANTITY
  8220. for (int index = 0; index < CCS_QUANTITY; index++)
  8221. {
  8222. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8223. {
  8224. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8225. {
  8226. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8227. goto end;
  8228. }
  8229. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8230. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8231. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8232. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8233. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8234. {
  8235. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8236. goto end;
  8237. }
  8238. else
  8239. {
  8240. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8241. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8242. goto end;
  8243. }
  8244. }
  8245. }//END FOR CCS_QUANTITY
  8246. for (int index = 0; index < GB_QUANTITY; index++)
  8247. {
  8248. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8249. {
  8250. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8251. {
  8252. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8253. goto end;
  8254. }
  8255. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8256. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8257. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8258. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8259. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8260. {
  8261. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8262. goto end;
  8263. }
  8264. else
  8265. {
  8266. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8267. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8268. goto end;
  8269. }
  8270. }
  8271. }// END FOR GB_QUANTITY
  8272. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8273. {
  8274. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8275. {
  8276. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8277. {
  8278. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8279. goto end;
  8280. }
  8281. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8282. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8283. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8284. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8285. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8286. {
  8287. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8288. goto end;
  8289. }
  8290. else
  8291. {
  8292. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8293. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8294. goto end;
  8295. }
  8296. }
  8297. }// END FOR GENERAL_GUN_QUANTITY
  8298. for (int index = 0; index < AC_QUANTITY; index++)
  8299. {
  8300. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8301. {
  8302. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8303. {
  8304. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8305. goto end;
  8306. }
  8307. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8308. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8309. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8310. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8311. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8312. {
  8313. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8314. goto end;
  8315. }
  8316. else
  8317. {
  8318. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8319. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8320. goto end;
  8321. }
  8322. }
  8323. }//END FOR AC_QUANTITY
  8324. }//END FOR AvailabilityTypeStr[Inoperative]
  8325. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8326. {
  8327. //----------------------gunIndex is 0 ------------------------------------------------//
  8328. if(gunIndex == 0)
  8329. {
  8330. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8331. {
  8332. for(int i=0; i < gunTotalNumber; i++)
  8333. {
  8334. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8335. {
  8336. 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
  8337. {
  8338. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8339. goto end;
  8340. }
  8341. }//END FOR CHAdeMO_QUANTITY
  8342. for (int index = 0; index < CCS_QUANTITY; index++)
  8343. {
  8344. 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
  8345. {
  8346. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8347. goto end;
  8348. }
  8349. }//END FOR CCS_QUANTITY
  8350. for (int index = 0; index < GB_QUANTITY; index++)
  8351. {
  8352. 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
  8353. {
  8354. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8355. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8356. goto end;
  8357. }
  8358. }// END FOR GB_QUANTITY
  8359. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8360. {
  8361. 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
  8362. {
  8363. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8364. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8365. goto end;
  8366. }
  8367. }// END FOR GENERAL_GUN_QUANTITY
  8368. for (int index = 0; index < AC_QUANTITY; index++)
  8369. {
  8370. 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
  8371. {
  8372. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8373. goto end;
  8374. }
  8375. }//END FOR CHAdeMO_QUANTITY
  8376. }// END FOR gunTotalNumber
  8377. }
  8378. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8379. {
  8380. for(int i=0; i < gunTotalNumber; i++)
  8381. {
  8382. for (int index = 0; index < AC_QUANTITY; index++)
  8383. {
  8384. 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
  8385. {
  8386. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8387. goto end;
  8388. }
  8389. }//END FOR CHAdeMO_QUANTITY
  8390. } // END FOR gunTotalNumber
  8391. }
  8392. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8393. goto end;
  8394. }
  8395. //----------------------gunIndex is not 0 ------------------------------------------------//
  8396. //check Transaction active
  8397. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8398. {
  8399. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8400. {
  8401. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8402. goto end;
  8403. }
  8404. }//END FOR CHAdeMO_QUANTITY
  8405. for (int index = 0; index < CCS_QUANTITY; index++)
  8406. {
  8407. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8408. {
  8409. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8410. goto end;
  8411. }
  8412. }//END FOR CCS_QUANTITY
  8413. for (int index = 0; index < GB_QUANTITY; index++)
  8414. {
  8415. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8416. {
  8417. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8418. goto end;
  8419. }
  8420. }// END FOR GB_QUANTITY
  8421. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8422. {
  8423. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8424. {
  8425. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8426. goto end;
  8427. }
  8428. }// END FOR GENERAL_GUN_QUANTITY
  8429. for (int index = 0; index < AC_QUANTITY; index++)
  8430. {
  8431. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8432. {
  8433. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8434. goto end;
  8435. }
  8436. }//END FOR AC_QUANTITY
  8437. }//END FOR AvailabilityTypeStr[Operative]
  8438. end:
  8439. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8440. {
  8441. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8442. }
  8443. else
  8444. {
  8445. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8446. }
  8447. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8448. {
  8449. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8450. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8451. }
  8452. else if(gunIndex == 0)
  8453. {
  8454. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8455. {
  8456. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8457. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8458. }
  8459. }
  8460. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8461. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8462. return result;
  8463. }
  8464. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8465. {
  8466. mtrace();
  8467. int valueInvalid = NO;
  8468. int result = FAIL;
  8469. char keystr[40]={0};
  8470. char valuestr[501]={0}; //value should be limited in 500 bytes
  8471. char comfirmstr[20]={0};
  8472. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8473. json_object *ChangeConfiguration;
  8474. ChangeConfiguration = json_tokener_parse(payload);
  8475. if(!is_error(ChangeConfiguration))
  8476. {
  8477. // Required data
  8478. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8479. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8480. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8481. {
  8482. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8483. }
  8484. else
  8485. {
  8486. valueInvalid = YES;
  8487. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8488. }
  8489. }
  8490. json_object_put(ChangeConfiguration);
  8491. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  8492. {
  8493. DEBUG_ERROR("Payload is null or value is invalid.\n");
  8494. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8495. }
  8496. else
  8497. {
  8498. int status = setKeyValue(keystr, valuestr);
  8499. switch(status)
  8500. {
  8501. case ConfigurationStatus_Accepted:
  8502. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8503. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8504. StoreConfigurationTable();
  8505. break;
  8506. case RebootRequired:
  8507. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8508. StoreConfigurationTable();
  8509. break;
  8510. case NotSupported:
  8511. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8512. break;
  8513. case ConfigurationStatus_Rejected:
  8514. default:
  8515. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8516. break;
  8517. }
  8518. }
  8519. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8520. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8521. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8522. {
  8523. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8524. SetOcppConnStatus(FALSE);
  8525. }
  8526. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8527. {
  8528. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8529. }
  8530. return result;
  8531. }
  8532. int handleClearCacheRequest(char *uuid, char *payload)
  8533. {
  8534. mtrace();
  8535. int result = FAIL;
  8536. char comfirmstr[20];
  8537. char rmFileCmd[100]={0};
  8538. struct stat stats;
  8539. DEBUG_INFO("handleClearCacheRequest...\n");
  8540. stat("/Storage/OCPP", &stats);
  8541. // Check for directory existence
  8542. if (S_ISDIR(stats.st_mode) == 1)
  8543. {}
  8544. else
  8545. {
  8546. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8547. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  8548. system(rmFileCmd);
  8549. }
  8550. if(OCPP_cleanLocalCache())
  8551. {
  8552. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8553. }
  8554. else
  8555. {
  8556. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8557. }
  8558. sendClearCacheConfirmation(uuid, comfirmstr);
  8559. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8560. return result;
  8561. }
  8562. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8563. {
  8564. mtrace();
  8565. int result = FAIL;
  8566. int resultRename;
  8567. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8568. char chargingProfilePurposeStr[26]={0};
  8569. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8570. char tempchargingProfilePurposeStr[26]={0};
  8571. char str[100]={0};
  8572. char fname[200]={0};
  8573. char comfirmstr[20]={0};
  8574. char word[1600]={0};
  8575. int clearflag = FALSE;
  8576. int chargingProfileIdIsNULL = FALSE;
  8577. int connectorIsNULL = FALSE;
  8578. int chargingProfilePurposeIsNULL = FALSE;
  8579. int stackLevelIsNULL = FALSE;
  8580. //int GotoEnd = FALSE;
  8581. FILE *fptr1, *fptr2;
  8582. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  8583. int n_chargingProfile=0;
  8584. int isEmptyFile = FALSE;
  8585. char sLineWord[1600]={0};
  8586. char chargingProfiles[10][100]={0};
  8587. int ChargeProfileCount = 0;
  8588. int ch;
  8589. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8590. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8591. json_object *ClearChargingProfile;
  8592. ClearChargingProfile = json_tokener_parse(payload);
  8593. if(!is_error(ClearChargingProfile))
  8594. {
  8595. // Optional data
  8596. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8597. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8598. else
  8599. chargingProfileIdIsNULL = TRUE;
  8600. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8601. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8602. else
  8603. connectorIsNULL = TRUE;
  8604. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8605. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8606. else
  8607. chargingProfilePurposeIsNULL = TRUE;
  8608. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8609. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8610. else
  8611. stackLevelIsNULL = TRUE;
  8612. }
  8613. json_object_put(ClearChargingProfile);
  8614. if(connectorIsNULL == FALSE)
  8615. {
  8616. switch(connectorIdInt)
  8617. {
  8618. case 0:
  8619. if(chargingProfilePurposeIsNULL == TRUE)
  8620. {
  8621. int l = 0;
  8622. strcpy(fname, ChargePointMaxProfile_JSON);
  8623. if((access(fname,F_OK))!=-1)
  8624. {
  8625. strcpy(chargingProfiles[l], fname);
  8626. l = l + 1;
  8627. }
  8628. strcpy(fname, TxDefaultProfile_0_JSON);
  8629. if((access(fname,F_OK))!=-1)
  8630. {
  8631. strcpy(chargingProfiles[l], fname);
  8632. l = l + 1;
  8633. }
  8634. ChargeProfileCount = l;
  8635. }
  8636. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8637. {
  8638. strcpy(fname, ChargePointMaxProfile_JSON);
  8639. if((access(fname,F_OK))!=-1)
  8640. {
  8641. strcpy(chargingProfiles[0], fname);
  8642. ChargeProfileCount = 1;
  8643. }
  8644. }
  8645. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8646. {
  8647. strcpy(fname, TxDefaultProfile_0_JSON);
  8648. if((access(fname,F_OK))!=-1)
  8649. {
  8650. strcpy(chargingProfiles[0], fname);
  8651. ChargeProfileCount = 1;
  8652. }
  8653. }
  8654. break;
  8655. default:
  8656. if(chargingProfilePurposeIsNULL == TRUE)
  8657. {
  8658. int m = 0;
  8659. memset(fname, 0, ARRAY_SIZE(fname));
  8660. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8661. if((access(fname,F_OK))!=-1)
  8662. {
  8663. strcpy(chargingProfiles[m], fname);
  8664. m = m + 1;
  8665. }
  8666. memset(fname, 0, ARRAY_SIZE(fname));
  8667. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8668. if((access(fname,F_OK))!=-1)
  8669. {
  8670. strcpy(chargingProfiles[m], fname);
  8671. m = m + 1;
  8672. }
  8673. ChargeProfileCount = m;
  8674. }
  8675. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8676. {
  8677. //strcpy(fname, TxDefaultProfile_1_JSON);
  8678. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8679. if((access(fname,F_OK))!=-1)
  8680. {
  8681. strcpy(chargingProfiles[0], fname);
  8682. ChargeProfileCount = 1;
  8683. }
  8684. }
  8685. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8686. {
  8687. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8688. if((access(fname,F_OK))!=-1)
  8689. {
  8690. strcpy(chargingProfiles[0], fname);
  8691. ChargeProfileCount = 1;
  8692. }
  8693. //strcpy(fname, TxProfile_1_JSON);
  8694. }
  8695. //strcpy(fname, ChargePointMaxProfile_JSON );
  8696. break;
  8697. }
  8698. }
  8699. else // Check all Charging Profiles
  8700. {
  8701. int i = 0;
  8702. char fnametemp[200]={0};
  8703. ChargeProfileCount = 0;
  8704. //Check ChargePointMaxProfile.json exit
  8705. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8706. {
  8707. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  8708. i = i + 1;
  8709. }
  8710. //Check TxDefaultProfile_0.json exit
  8711. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8712. {
  8713. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  8714. i = i + 1;
  8715. }
  8716. //Check TxDefaultProfile_%d.json
  8717. for(int j=1; j <= gunTotalNumber; j++)
  8718. {
  8719. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8720. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8721. if((access(fnametemp,F_OK))!=-1)
  8722. {
  8723. strcpy(chargingProfiles[i], fnametemp);
  8724. i = i + 1;
  8725. }
  8726. }
  8727. //Check TxProfile_%d.json
  8728. for(int j=1; j <= gunTotalNumber; j++)
  8729. {
  8730. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8731. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8732. if((access(fnametemp,F_OK))!=-1)
  8733. {
  8734. strcpy(chargingProfiles[i], fnametemp);
  8735. i = i + 1;
  8736. }
  8737. }
  8738. ChargeProfileCount = i;
  8739. }// End connectorIsNULL is TRUE
  8740. if(ChargeProfileCount == 0)
  8741. {
  8742. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8743. goto end;
  8744. }
  8745. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8746. {
  8747. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8748. goto end;
  8749. }
  8750. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8751. {
  8752. memset(str, 0, ARRAY_SIZE(str));
  8753. // clear temp file
  8754. sprintf(str,"rm -f %s",temp);
  8755. system(str);
  8756. for(int k=0; k < ChargeProfileCount; k++)
  8757. {
  8758. memset(str, 0, ARRAY_SIZE(str));
  8759. //clear file in C
  8760. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8761. system(str);
  8762. }
  8763. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8764. goto end;
  8765. }
  8766. else if(connectorIsNULL == TRUE)
  8767. {
  8768. for(int k=0; k < ChargeProfileCount; k++)
  8769. {
  8770. fptr1 = fopen(chargingProfiles[k], "r");
  8771. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  8772. //Check Charging Profile Count
  8773. while(fscanf(fptr1, "%s", word) != EOF)
  8774. {
  8775. //DEBUG_INFO("word=%s\n",word);
  8776. if(strstr(word, "chargingProfileId")!= NULL)
  8777. {
  8778. //DEBUG_INFO("test chargingProfileId \n");
  8779. n_chargingProfile = n_chargingProfile + 1;
  8780. //DEBUG_INFO("chargingProfileId Found\n");
  8781. }
  8782. }
  8783. rewind(fptr1);
  8784. //search Charging Profile Element
  8785. //int i= 0;
  8786. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8787. {
  8788. json_object *tmpProfilee;
  8789. tmpProfilee = json_tokener_parse(sLineWord);
  8790. if(!is_error(tmpProfilee))
  8791. {
  8792. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8793. {
  8794. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8795. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8796. }
  8797. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8798. {
  8799. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8800. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8801. }
  8802. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8803. {
  8804. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8805. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8806. }
  8807. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8808. {
  8809. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8810. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8811. }
  8812. }
  8813. json_object_put(tmpProfilee);
  8814. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8815. {
  8816. //------- not write to fptr2-------//
  8817. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8818. //clearflag = TRUE;
  8819. }
  8820. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8821. {
  8822. //------- not write to fptr2-------//
  8823. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8824. }
  8825. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8826. {
  8827. //------- not write to fptr2-------//
  8828. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8829. }
  8830. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8831. {
  8832. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8833. }
  8834. else
  8835. {
  8836. fprintf(fptr2, sLineWord);//writing data into file
  8837. }
  8838. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8839. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8840. if(clearflag == TRUE)
  8841. {
  8842. fclose(fptr1);
  8843. fclose(fptr2);
  8844. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8845. system(str);
  8846. // clear temp file
  8847. sprintf(str,"rm -f %s",temp);
  8848. system(str);
  8849. }
  8850. else
  8851. {
  8852. fclose(fptr1);
  8853. fclose(fptr2);
  8854. memset(str, 0, ARRAY_SIZE(str));
  8855. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8856. system(str);
  8857. resultRename = rename(temp, chargingProfiles[k]);
  8858. if(resultRename == 0)
  8859. {
  8860. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8861. }
  8862. else
  8863. {
  8864. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8865. }
  8866. if(comfirmstr[0]== 0)
  8867. {
  8868. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8869. }
  8870. //Check chargingProfile is empty file
  8871. /*------ Read the file ----------------*/
  8872. fptr1=fopen(chargingProfiles[k],"r");
  8873. ch=fgetc(fptr1);
  8874. rewind(fptr1);
  8875. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8876. if(ch!=EOF)
  8877. {
  8878. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8879. {
  8880. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8881. if(sLineWord[0]=='\0')
  8882. {
  8883. isEmptyFile = TRUE;
  8884. break;
  8885. }
  8886. else
  8887. {
  8888. isEmptyFile = FALSE;
  8889. break;
  8890. }
  8891. }
  8892. }
  8893. else
  8894. isEmptyFile = TRUE;
  8895. fclose(fptr1);
  8896. if(isEmptyFile == TRUE)
  8897. {
  8898. memset(str, 0, ARRAY_SIZE(str));
  8899. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8900. system(str);
  8901. }
  8902. }
  8903. }// End of while(int k=0; k < ChargePointCount; k++)
  8904. }
  8905. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8906. {
  8907. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8908. for(int k=0; k < ChargeProfileCount; k++)
  8909. {
  8910. fptr1 = fopen(chargingProfiles[k], "r");
  8911. fptr2 = fopen(temp, "w+");
  8912. //Check Charging Profile Count
  8913. while(fscanf(fptr1, "%s", word) != EOF)
  8914. {
  8915. //DEBUG_INFO("word=%s\n",word);
  8916. if(strstr(word, "chargingProfileId")!= NULL)
  8917. {
  8918. n_chargingProfile = n_chargingProfile + 1;
  8919. }
  8920. }
  8921. rewind(fptr1);
  8922. //search Charging Profile Element
  8923. //int i= 0;
  8924. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8925. {
  8926. json_object *tmpProfilee;
  8927. tmpProfilee = json_tokener_parse(sLineWord);
  8928. if(!is_error(tmpProfilee))
  8929. {
  8930. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8931. {
  8932. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8933. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8934. }
  8935. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8936. {
  8937. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8938. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8939. }
  8940. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8941. {
  8942. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8943. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8944. }
  8945. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8946. {
  8947. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8948. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8949. }
  8950. }
  8951. json_object_put(tmpProfilee);
  8952. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8953. {
  8954. //------- not write to fptr2-------//
  8955. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8956. //clearflag = TRUE;
  8957. }
  8958. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8959. {
  8960. //------- not write to fptr2-------//
  8961. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8962. }
  8963. else if(stackLevelIsNULL == TRUE)
  8964. {
  8965. //Clear Whole File
  8966. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8967. clearflag = TRUE;
  8968. break;
  8969. }
  8970. else
  8971. {
  8972. fprintf(fptr2, sLineWord);//writing data into file
  8973. }
  8974. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8975. }
  8976. if(clearflag == TRUE)
  8977. {
  8978. fclose(fptr1);
  8979. fclose(fptr2);
  8980. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8981. system(str);
  8982. // clear temp file
  8983. sprintf(str,"rm -f %s",temp);
  8984. system(str);
  8985. }
  8986. else
  8987. {
  8988. fclose(fptr1);
  8989. fclose(fptr2);
  8990. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8991. system(str);
  8992. resultRename = rename(temp, chargingProfiles[k]);
  8993. if(resultRename == 0)
  8994. {
  8995. DEBUG_INFO("File ChargingProfile renamed successfully");
  8996. }
  8997. else
  8998. {
  8999. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9000. }
  9001. if(comfirmstr[0]== 0)
  9002. {
  9003. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9004. }
  9005. //Check chargingProfile is empty file
  9006. /*------ Read the file ----------------*/
  9007. fptr1=fopen(chargingProfiles[k],"r");
  9008. ch=fgetc(fptr1);
  9009. rewind(fptr1);
  9010. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9011. if(ch!=EOF)
  9012. {
  9013. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9014. {
  9015. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9016. if(sLineWord[0]=='\0')
  9017. {
  9018. isEmptyFile = TRUE;
  9019. break;
  9020. }
  9021. else
  9022. {
  9023. isEmptyFile = FALSE;
  9024. break;
  9025. }
  9026. }
  9027. }
  9028. else
  9029. isEmptyFile = TRUE;
  9030. fclose(fptr1);
  9031. if(isEmptyFile == TRUE)
  9032. {
  9033. memset(str, 0, ARRAY_SIZE(str));
  9034. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9035. system(str);
  9036. }
  9037. /*------- End of reading ---------------*/
  9038. }
  9039. } // while(int k=0; k < ChargeProfileCount; k++)
  9040. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9041. end:
  9042. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9043. {
  9044. if(connectorIdInt == 0)
  9045. {
  9046. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9047. {
  9048. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9049. }
  9050. }
  9051. else
  9052. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9053. }
  9054. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9055. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9056. return result;
  9057. }
  9058. void createFirmwareVersionByDataTransfer(void)
  9059. {
  9060. json_object *FirmwareDataTransfer = json_object_new_object();
  9061. // AC & DC model
  9062. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9063. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9064. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9065. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9066. // DC model
  9067. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9068. {
  9069. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9070. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9071. (gunType[3] != GUN_TYPE_UNKNOWN))
  9072. {
  9073. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9074. }
  9075. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9076. {
  9077. // DS DM DW
  9078. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9079. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9080. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9081. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9082. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9083. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9084. }
  9085. else
  9086. {
  9087. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9088. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9089. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9090. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9091. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9092. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9093. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9094. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9095. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9096. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9097. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9098. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9099. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9100. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9101. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9102. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9103. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9104. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9105. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9106. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9107. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9108. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9109. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9110. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9111. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9112. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9113. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9114. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9115. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9116. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9117. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9118. }
  9119. }
  9120. // 4G model
  9121. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9122. {
  9123. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9124. }
  9125. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9126. json_object_put(FirmwareDataTransfer);
  9127. }
  9128. int handleDataTransferRequest(char *uuid, char *payload)
  9129. {
  9130. mtrace();
  9131. json_object *response = json_object_new_object();
  9132. int result = FAIL;
  9133. char tempvendorId[255]={0};
  9134. char tempmessageId[50]={0};
  9135. char tempdata[512]={0};
  9136. char message[2048]={0};
  9137. DEBUG_INFO("handleDataTransferRequest...\n");
  9138. if((uuid != NULL) && (payload != NULL))
  9139. {
  9140. json_object *DataTransfer;
  9141. DataTransfer = json_tokener_parse(payload);
  9142. if(!is_error(DataTransfer))
  9143. {
  9144. // Required data
  9145. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9146. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9147. // Optional data
  9148. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9149. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9150. if(json_object_object_get(DataTransfer, "data") != NULL)
  9151. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9152. result = PASS;
  9153. }
  9154. json_object_put(DataTransfer);
  9155. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9156. {
  9157. // Send all moudle firmware version on EVSE
  9158. createFirmwareVersionByDataTransfer();
  9159. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9160. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9161. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9162. json_object_put(response);
  9163. }
  9164. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9165. {
  9166. system("/usr/bin/run_tmate_restart.sh &");
  9167. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9168. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9169. json_object_put(response);
  9170. }
  9171. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9172. {
  9173. json_object *data;
  9174. data = json_tokener_parse(tempdata);
  9175. if(!is_error(data))
  9176. {
  9177. 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))
  9178. {
  9179. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9180. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9181. if(json_object_object_get(data, "SOC") != NULL)
  9182. {
  9183. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9184. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9185. }
  9186. if(json_object_object_get(data, "Energy") != NULL)
  9187. {
  9188. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9189. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9190. }
  9191. if(json_object_object_get(data, "Duration") != NULL)
  9192. {
  9193. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9194. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9195. }
  9196. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9197. }
  9198. else
  9199. {
  9200. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9201. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9202. }
  9203. }
  9204. else
  9205. {
  9206. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9207. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9208. }
  9209. json_object_put(data);
  9210. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9211. json_object_put(response);
  9212. }
  9213. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9214. {
  9215. json_object *data;
  9216. data = json_tokener_parse(tempdata);
  9217. if(!is_error(data))
  9218. {
  9219. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9220. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9221. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9222. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9223. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9224. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9225. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9226. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9227. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9228. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9229. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9230. }
  9231. else
  9232. {
  9233. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9234. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9235. }
  9236. json_object_put(data);
  9237. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9238. json_object_put(response);
  9239. }
  9240. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9241. {
  9242. json_object *data;
  9243. data = json_tokener_parse(tempdata);
  9244. if(!is_error(data))
  9245. {
  9246. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9247. if(json_object_object_get(data, "idToken") != NULL)
  9248. {
  9249. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9250. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9251. }
  9252. if(json_object_object_get(data, "price") != NULL)
  9253. {
  9254. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9255. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9256. }
  9257. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9258. }
  9259. else
  9260. {
  9261. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9262. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9263. }
  9264. json_object_put(data);
  9265. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9266. json_object_put(response);
  9267. }
  9268. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9269. {
  9270. json_object *data;
  9271. data = json_tokener_parse(tempdata);
  9272. if(!is_error(data))
  9273. {
  9274. if(json_object_object_get(data, "txId") != NULL)
  9275. {
  9276. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9277. for(int idx = 0;idx<gunTotalNumber;idx++)
  9278. {
  9279. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9280. {
  9281. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9282. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9283. if(json_object_object_get(data, "description") != NULL)
  9284. {
  9285. // California pricing V1.0
  9286. DEBUG_INFO("California pricing V1.0\n");
  9287. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9288. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9289. }
  9290. else
  9291. {
  9292. // California pricing V1.1
  9293. DEBUG_INFO("California pricing V1.1\n");
  9294. if(json_object_object_get(data, "timestamp") != NULL)
  9295. {
  9296. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9297. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9298. }
  9299. if(json_object_object_get(data, "meterValue") != NULL)
  9300. {
  9301. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9302. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9303. }
  9304. if(json_object_object_get(data, "cost") != NULL)
  9305. {
  9306. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9307. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9308. }
  9309. if(json_object_object_get(data, "state") != NULL)
  9310. {
  9311. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9312. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9313. }
  9314. if(json_object_object_get(data, "chargingPrice") != NULL)
  9315. {
  9316. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9317. {
  9318. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9319. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9320. }
  9321. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9322. {
  9323. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9324. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9325. }
  9326. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9327. {
  9328. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9329. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9330. }
  9331. }
  9332. if(json_object_object_get(data, "idlePrice") != NULL)
  9333. {
  9334. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9335. {
  9336. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9337. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9338. }
  9339. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9340. {
  9341. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9342. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9343. }
  9344. }
  9345. if(json_object_object_get(data, "nextPeriod") != NULL)
  9346. {
  9347. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9348. {
  9349. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9350. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9351. }
  9352. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9353. {
  9354. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9355. {
  9356. 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")));
  9357. 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"));
  9358. }
  9359. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9360. {
  9361. 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")));
  9362. 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"));
  9363. }
  9364. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9365. {
  9366. 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")));
  9367. 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"));
  9368. }
  9369. }
  9370. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9371. {
  9372. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9373. {
  9374. 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")));
  9375. 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"));
  9376. }
  9377. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9378. {
  9379. 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")));
  9380. 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"));
  9381. }
  9382. }
  9383. }
  9384. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9385. {
  9386. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9387. {
  9388. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9389. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9390. }
  9391. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9392. {
  9393. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9394. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9395. }
  9396. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9397. {
  9398. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9399. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9400. }
  9401. }
  9402. }
  9403. }
  9404. }
  9405. }
  9406. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9407. }
  9408. else
  9409. {
  9410. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9411. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9412. }
  9413. json_object_put(data);
  9414. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9415. json_object_put(response);
  9416. }
  9417. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9418. {
  9419. json_object *data;
  9420. data = json_tokener_parse(tempdata);
  9421. if(!is_error(data))
  9422. {
  9423. if(json_object_object_get(data, "txId") != NULL)
  9424. {
  9425. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9426. for(int idx = 0;idx<gunTotalNumber;idx++)
  9427. {
  9428. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9429. {
  9430. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9431. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9432. if(json_object_object_get(data, "description") != NULL)
  9433. {
  9434. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9435. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9436. }
  9437. }
  9438. }
  9439. }
  9440. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9441. }
  9442. else
  9443. {
  9444. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9445. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9446. }
  9447. json_object_put(data);
  9448. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9449. json_object_put(response);
  9450. }
  9451. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9452. {
  9453. json_object *data;
  9454. data = json_tokener_parse(tempdata);
  9455. if(!is_error(data))
  9456. {
  9457. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9458. if(json_object_object_get(data, "Content_Type") != NULL)
  9459. {
  9460. 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))
  9461. {
  9462. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9463. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9464. {
  9465. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9466. }
  9467. }
  9468. else
  9469. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9470. }
  9471. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9472. }
  9473. else
  9474. {
  9475. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9476. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9477. }
  9478. json_object_put(data);
  9479. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9480. json_object_put(response);
  9481. }
  9482. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9483. {
  9484. json_object *data;
  9485. data = json_tokener_parse(tempdata);
  9486. if(!is_error(data))
  9487. {
  9488. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9489. if(json_object_object_get(data, "ConnectorId") != NULL)
  9490. {
  9491. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9492. }
  9493. if(json_object_object_get(data, "SerialNo") != NULL)
  9494. {
  9495. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9496. }
  9497. if(json_object_object_get(data, "Page_Index") != NULL)
  9498. {
  9499. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9500. }
  9501. if(json_object_object_get(data, "Duration") != NULL)
  9502. {
  9503. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9504. }
  9505. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9506. }
  9507. else
  9508. {
  9509. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9510. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9511. }
  9512. json_object_put(data);
  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 if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9517. {
  9518. json_object *data;
  9519. data = json_tokener_parse(tempdata);
  9520. if(!is_error(data))
  9521. {
  9522. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9523. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9524. {
  9525. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9526. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9527. else
  9528. {
  9529. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9530. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9531. }
  9532. }
  9533. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9534. {
  9535. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9536. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9537. else
  9538. {
  9539. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9540. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9541. }
  9542. }
  9543. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9544. {
  9545. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9546. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9547. else
  9548. {
  9549. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9550. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9551. }
  9552. }
  9553. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9554. {
  9555. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9556. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9557. else
  9558. {
  9559. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9560. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9561. }
  9562. }
  9563. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9564. {
  9565. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9566. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9567. else
  9568. {
  9569. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9570. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9571. }
  9572. }
  9573. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9574. {
  9575. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9576. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9577. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9578. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9579. else
  9580. {
  9581. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9582. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9583. }
  9584. }
  9585. if(json_object_object_get(data, "isAuthentication") != NULL)
  9586. {
  9587. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9588. {
  9589. case 0:
  9590. case 1:
  9591. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9592. break;
  9593. default:
  9594. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9595. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9596. break;
  9597. }
  9598. }
  9599. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9600. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9601. }
  9602. else
  9603. {
  9604. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9605. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9606. }
  9607. json_object_put(data);
  9608. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9609. json_object_put(response);
  9610. }
  9611. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  9612. {
  9613. json_object *data;
  9614. data = json_tokener_parse(tempdata);
  9615. if(!is_error(data))
  9616. {
  9617. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9618. {
  9619. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  9620. {
  9621. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9622. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9623. }
  9624. else
  9625. {
  9626. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9627. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  9628. }
  9629. }
  9630. else
  9631. {
  9632. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9633. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9634. }
  9635. }
  9636. else
  9637. {
  9638. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9639. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9640. }
  9641. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9642. json_object_put(response);
  9643. }
  9644. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9645. {
  9646. json_object *data;
  9647. data = json_tokener_parse(tempdata);
  9648. if(!is_error(data))
  9649. {
  9650. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9651. if(json_object_object_get(data, "stationName") != NULL)
  9652. {
  9653. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9654. }
  9655. else
  9656. {
  9657. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9658. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9659. }
  9660. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9661. {
  9662. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  9663. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9664. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  9665. }
  9666. }
  9667. else
  9668. {
  9669. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9670. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9671. }
  9672. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9673. json_object_put(response);
  9674. }
  9675. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9676. {
  9677. json_object *data;
  9678. data = json_tokener_parse(tempdata);
  9679. if(!is_error(data))
  9680. {
  9681. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9682. if(json_object_object_get(data, "weatherId") != NULL)
  9683. {
  9684. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9685. }
  9686. else
  9687. {
  9688. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9689. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9690. }
  9691. if(json_object_object_get(data, "Temperature") != NULL)
  9692. {
  9693. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9694. }
  9695. else
  9696. {
  9697. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9698. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9699. }
  9700. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9701. {
  9702. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  9703. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9704. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  9705. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  9706. );
  9707. }
  9708. }
  9709. else
  9710. {
  9711. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9712. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9713. }
  9714. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9715. json_object_put(response);
  9716. }
  9717. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9718. {
  9719. json_object *data;
  9720. data = json_tokener_parse(tempdata);
  9721. if(!is_error(data))
  9722. {
  9723. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9724. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9725. {
  9726. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9727. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9728. }
  9729. else
  9730. {
  9731. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9732. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9733. }
  9734. }
  9735. else
  9736. {
  9737. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9738. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9739. }
  9740. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9741. json_object_put(response);
  9742. }
  9743. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  9744. {
  9745. json_object *data;
  9746. data = json_tokener_parse(tempdata);
  9747. if(!is_error(data))
  9748. {
  9749. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9750. {
  9751. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  9752. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9753. if(gun_index < gunTotalNumber)
  9754. {
  9755. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9756. {
  9757. json_object *responsedata = json_object_new_object();
  9758. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  9759. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  9760. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  9761. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  9762. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  9763. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  9764. }
  9765. else
  9766. {
  9767. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9768. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  9769. }
  9770. }
  9771. else
  9772. {
  9773. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9774. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  9775. }
  9776. }
  9777. else
  9778. {
  9779. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9780. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9781. }
  9782. }
  9783. else
  9784. {
  9785. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9786. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9787. }
  9788. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9789. json_object_put(response);
  9790. }
  9791. else
  9792. {
  9793. // Can not find valid message id
  9794. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9795. }
  9796. }
  9797. else
  9798. {
  9799. // Payload is null
  9800. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9801. }
  9802. LWS_Send(message);
  9803. return result;
  9804. }
  9805. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9806. {
  9807. mtrace();
  9808. int result = FAIL;
  9809. int connectorIdInt, durationInt;
  9810. char chargingRateUnitStr[4]={0};
  9811. char comfirmstr[20];
  9812. int confirmPeriods = 0;
  9813. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9814. json_object *GetCompositeSchedule;
  9815. GetCompositeSchedule = json_tokener_parse(payload);
  9816. if(!is_error(GetCompositeSchedule))
  9817. {
  9818. // Required data
  9819. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9820. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9821. else
  9822. connectorIdInt = -1;
  9823. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9824. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9825. else
  9826. durationInt = 86400;
  9827. // Optional data
  9828. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9829. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9830. }
  9831. json_object_put(GetCompositeSchedule);
  9832. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9833. if((connectorIdInt == 0) ||
  9834. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9835. {
  9836. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9837. struct StructChargingProfile tmpProfile[1];
  9838. if(strstr(chargingRateUnitStr, "W") != NULL)
  9839. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9840. else
  9841. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9842. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9843. {
  9844. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9845. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9846. }
  9847. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9848. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9849. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9850. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9851. {
  9852. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9853. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9854. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9855. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9856. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9857. {
  9858. confirmPeriods = idx;
  9859. break;
  9860. }
  9861. }
  9862. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9863. {
  9864. confirmPeriods += 1;
  9865. }
  9866. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9867. }
  9868. else
  9869. {
  9870. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9871. }
  9872. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9873. return result;
  9874. }
  9875. int handleGetConfigurationRequest(char *uuid, char *payload)
  9876. {
  9877. mtrace();
  9878. int result = FAIL;
  9879. int MaxKeySupported = 0;
  9880. int n_keys = 0;
  9881. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9882. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9883. json_object *GetConfiguration;
  9884. GetConfiguration = json_tokener_parse(payload);
  9885. if(!is_error(GetConfiguration))
  9886. {
  9887. // Optional data
  9888. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9889. {
  9890. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9891. {
  9892. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9893. n_keys = idx + 1;
  9894. }
  9895. }
  9896. }
  9897. json_object_put(GetConfiguration);
  9898. UnknownKeynum = 0;
  9899. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9900. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9901. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9902. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9903. if(n_keys != 0)
  9904. {
  9905. for(int i=0;i<n_keys;i++)
  9906. {
  9907. getKeyValue(requestKey[i]);
  9908. }
  9909. }
  9910. else
  9911. {
  9912. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9913. getKeyValue("");
  9914. }
  9915. processUnkownKey();
  9916. sendGetConfigurationConfirmation(uuid);
  9917. return result;
  9918. }
  9919. static char fnamePlusPath[100]={0};
  9920. static char fnamePWithNoPath[60]={0};
  9921. void checkUploadLog(void)
  9922. {
  9923. FILE *fp;
  9924. /* Open the command for reading. */
  9925. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9926. if (fp == NULL) {
  9927. DEBUG_WARN("Failed to run command\n" );
  9928. exit(1);
  9929. }
  9930. int ftppathlen = 0;
  9931. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9932. int i = 0;
  9933. /* Read the output a line at a time - output it. */
  9934. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9935. if(i==0)
  9936. {
  9937. ftppathlen = strlen(fnamePlusPath);
  9938. DEBUG_INFO("%s\n", fnamePlusPath);
  9939. fnamePlusPath[ftppathlen]='\0';
  9940. break;
  9941. }
  9942. i= i+1;
  9943. }
  9944. /* close */
  9945. pclose(fp);
  9946. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9947. {
  9948. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9949. {
  9950. fnamePlusPath[k]='\0';
  9951. }
  9952. }
  9953. i=1;
  9954. //char fname[60]={0};
  9955. while(i < ftppathlen)
  9956. {
  9957. int len=ftppathlen-i;
  9958. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9959. {
  9960. DEBUG_INFO("compare '/' all right\n");
  9961. break;
  9962. }
  9963. i=i+1;
  9964. }
  9965. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9966. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9967. fnamePWithNoPath[i+1] = '\0';
  9968. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9969. {
  9970. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9971. {
  9972. fnamePWithNoPath[j]='\0';
  9973. }
  9974. }
  9975. FILE* fp1 = fopen(fnamePlusPath, "r");
  9976. if (fp1)
  9977. {
  9978. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9979. // file exists
  9980. fclose(fp1);
  9981. }
  9982. else
  9983. {
  9984. // file doesn't exist
  9985. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9986. }
  9987. }
  9988. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9989. {
  9990. mtrace();
  9991. int result = FAIL;
  9992. time_t CurrentTime;
  9993. struct tm *tm;
  9994. pthread_t th_Status;
  9995. CurrentTime = time(NULL);
  9996. tm = localtime(&CurrentTime);
  9997. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  9998. 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);
  9999. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10000. if(!interLock.isGetDiagnosticGoing)
  10001. {
  10002. interLock.isGetDiagnosticGoing = 1;
  10003. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  10004. sleep(1);
  10005. }
  10006. else
  10007. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10008. return result;
  10009. }
  10010. void* GetDiagnosticsProcess(void* data)
  10011. {
  10012. pthread_detach(pthread_self());
  10013. mtrace();
  10014. int retriesInt=0, retryIntervalInt=0;
  10015. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10016. 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};
  10017. int port=0;
  10018. int isSuccess = FALSE;
  10019. char cmdBuf[2048];
  10020. struct tm *tmNow;
  10021. time_t CurrentTime;
  10022. struct tm tmStart;
  10023. struct tm tmStop;
  10024. CurrentTime = time(NULL);
  10025. tmNow=localtime(&CurrentTime);
  10026. uint16_t targetYear, targetMonth;
  10027. json_object *GetDiagnostics;
  10028. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10029. GetDiagnostics = json_tokener_parse(data);
  10030. if(!is_error(GetDiagnostics))
  10031. {
  10032. // Required data
  10033. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10034. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10035. // Optional data
  10036. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10037. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10038. else
  10039. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10040. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10041. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10042. else
  10043. retryIntervalInt = 30;
  10044. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10045. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10046. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10047. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10048. }
  10049. json_object_put(GetDiagnostics);
  10050. // Pack log to compress file
  10051. 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) &&
  10052. (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))
  10053. {
  10054. // Pack system log
  10055. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10056. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10057. targetYear = tmStart.tm_year;
  10058. targetMonth = tmStart.tm_mon;
  10059. do
  10060. {
  10061. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10062. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10063. if(targetMonth+1>=13)
  10064. {
  10065. targetYear += 1;
  10066. targetMonth = 1;
  10067. }
  10068. else
  10069. {
  10070. targetMonth += 1;
  10071. }
  10072. }while((targetYear < (tmNow->tm_year+1900)) ||
  10073. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10074. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10075. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10076. system(cmdBuf);
  10077. // Pack charging & event log
  10078. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10079. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10080. targetYear = tmStart.tm_year;
  10081. targetMonth = tmStart.tm_mon;
  10082. do
  10083. {
  10084. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10085. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10086. if(targetMonth+1>=13)
  10087. {
  10088. targetYear += 1;
  10089. targetMonth = 1;
  10090. }
  10091. else
  10092. {
  10093. targetMonth += 1;
  10094. }
  10095. }while((targetYear < (tmNow->tm_year+1900)) ||
  10096. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10097. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10098. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10099. system(cmdBuf);
  10100. // Combine log file
  10101. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10102. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10103. }
  10104. else
  10105. {
  10106. system("exec /root/logPackTools 'log' 6");
  10107. }
  10108. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10109. system(cmdBuf);
  10110. checkUploadLog();
  10111. //****************location*******************/
  10112. if(strcmp(locationstr,"")==0)
  10113. {
  10114. DEBUG_INFO("location is <Empty>!\n");
  10115. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10116. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10117. goto end;
  10118. }
  10119. memset(protocol, 0, ARRAY_SIZE(protocol));
  10120. memset(user, 0, ARRAY_SIZE(user) );
  10121. memset(password, 0, ARRAY_SIZE(password));
  10122. memset(host, 0, ARRAY_SIZE(host));
  10123. memset(path, 0, ARRAY_SIZE(path));
  10124. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10125. memset(host1, 0, ARRAY_SIZE(host1));
  10126. memset(path1, 0, ARRAY_SIZE(path1));
  10127. /*location: ftp://user:password@host:port/path*/
  10128. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10129. if((access(fnamePlusPath,F_OK))!=-1)
  10130. {
  10131. DEBUG_INFO("fnamePlusPath exist.\n");
  10132. }
  10133. else
  10134. {
  10135. DEBUG_INFO("fnamePlusPath not exist!\n");
  10136. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10137. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10138. goto end;
  10139. }
  10140. if(strchr(locationstr,'@')==NULL)
  10141. {
  10142. sscanf(locationstr,
  10143. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10144. protocol, host, &port, path);
  10145. strcpy(user,"anonymous");
  10146. strcpy(password,"");
  10147. }
  10148. else
  10149. {
  10150. //DEBUG_INFO("pch=%s\n", pch);
  10151. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10152. protocol, user, password, host, &port, path);
  10153. }
  10154. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10155. {
  10156. DEBUG_INFO("protocol is not ftp/http ! \n");
  10157. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10158. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10159. goto end;
  10160. }
  10161. if(strncmp(locationstr,"http", 4) == 0)
  10162. {
  10163. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10164. sprintf(ftppath,"/%s", path);
  10165. do
  10166. {
  10167. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10168. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10169. sleep(3);
  10170. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10171. if(!isSuccess)
  10172. {
  10173. DEBUG_INFO("Diagnostics fail.\n");
  10174. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10175. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10176. sleep(retryIntervalInt);
  10177. }
  10178. else
  10179. {
  10180. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10181. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10182. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10183. }
  10184. retriesInt--;
  10185. }while((isSuccess == 0)&&(retriesInt >= 0));
  10186. }
  10187. else
  10188. {
  10189. sscanf(host,"%[^/]%s",host1, path1);
  10190. if(strlen(path) > 0)
  10191. sprintf(ftppath,"/%s", path);
  10192. else
  10193. sprintf(ftppath,"/%s", path1);
  10194. int ftppathlen=strlen(ftppath);
  10195. int i=1;
  10196. char filenametemp[50];
  10197. while(i < ftppathlen)
  10198. {
  10199. int len=ftppathlen-i;
  10200. if(ftppath[len]== 47) // '/' ascll code: 47
  10201. {
  10202. DEBUG_INFO("find '/' all right\n");
  10203. break;
  10204. }
  10205. i=i+1;
  10206. }
  10207. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10208. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10209. filenametemp[i+1] = 0;
  10210. if(port == 0)
  10211. port = 21;
  10212. do
  10213. {
  10214. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10215. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10216. sleep(3);
  10217. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10218. if(!isSuccess)
  10219. {
  10220. DEBUG_INFO("Diagnostics fail.\n");
  10221. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10222. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10223. sleep(retryIntervalInt);
  10224. }
  10225. else
  10226. {
  10227. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10228. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10229. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10230. }
  10231. retriesInt--;
  10232. }while((!isSuccess)&&(retriesInt >= 0));
  10233. }
  10234. end:
  10235. system("rm -f /mnt/*");
  10236. sleep(5);
  10237. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10238. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10239. interLock.isGetDiagnosticGoing = 0;
  10240. pthread_exit(NULL);
  10241. }
  10242. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10243. {
  10244. mtrace();
  10245. int result = FAIL;
  10246. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10247. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10248. {
  10249. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10250. locallistVersion = -1;
  10251. }
  10252. else
  10253. {
  10254. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10255. OCPP_getListVerion();
  10256. }
  10257. //from db.OCPP_getListVerion
  10258. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10259. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  10260. sendGetLocalListVersionConfirmation(uuid,"");
  10261. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  10262. return result;
  10263. }
  10264. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10265. {
  10266. mtrace();
  10267. int result = FAIL;
  10268. int connectorIdInt=-1;
  10269. int tempIndex = 0;
  10270. int connectorIdIsNULL, chargingProfileIsNULL;
  10271. char comfirmstr[20]={0};
  10272. char cmdBuf[512];
  10273. json_object *RemoteStartTransaction;
  10274. FILE *fp;
  10275. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10276. if(server_pending == TRUE)
  10277. {
  10278. return 0;
  10279. }
  10280. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10281. RemoteStartTransaction = json_tokener_parse(payload);
  10282. if(!is_error(RemoteStartTransaction))
  10283. {
  10284. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10285. {
  10286. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10287. }
  10288. else
  10289. {
  10290. connectorIdIsNULL = TRUE;
  10291. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10292. {
  10293. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10294. {
  10295. connectorIdIsNULL = FALSE;
  10296. connectorIdInt = (gun_index+1);
  10297. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10298. break;
  10299. }
  10300. }
  10301. }
  10302. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10303. {
  10304. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10305. // Required data
  10306. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10307. // Optional data
  10308. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10309. {
  10310. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10311. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10312. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10313. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10314. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10315. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10316. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10317. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10318. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10319. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10320. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10321. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10322. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10323. {
  10324. 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")));
  10325. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10326. 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"));
  10327. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10328. 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"));
  10329. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10330. 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")));
  10331. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10332. {
  10333. 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++)
  10334. {
  10335. 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"));
  10336. 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"));
  10337. 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)
  10338. 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"));
  10339. }
  10340. }
  10341. }
  10342. }
  10343. else
  10344. {
  10345. chargingProfileIsNULL = TRUE;
  10346. }
  10347. }
  10348. }
  10349. else
  10350. {
  10351. connectorIdIsNULL = TRUE;
  10352. }
  10353. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10354. {
  10355. DEBUG_WARN("Connector id is NULL\n.");
  10356. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10357. goto end;
  10358. }
  10359. /*
  10360. enum _SYSTEM_STATUS
  10361. {
  10362. S_BOOTING = 0,
  10363. S_IDLE, = 1
  10364. S_AUTHORIZING, = 2
  10365. S_REASSIGN_CHECK, = 3
  10366. S_REASSIGN, = 4
  10367. S_PRECHARGE, = 5
  10368. S_PREPARING_FOR_EV, = 6
  10369. S_PREPARING_FOR_EVSE, = 7
  10370. S_CHARGING, = 8
  10371. S_TERMINATING, = 9
  10372. S_COMPLETE, = 10
  10373. S_ALARM, = 11
  10374. S_FAULT = 12
  10375. }
  10376. */
  10377. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10378. {
  10379. //check Transaction active
  10380. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10381. {
  10382. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10383. {
  10384. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10385. }
  10386. else
  10387. {
  10388. tempIndex = connectorIdInt -1;
  10389. }
  10390. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10391. {
  10392. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10393. {
  10394. 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))
  10395. {
  10396. //Reserved
  10397. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10398. }
  10399. 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))
  10400. {
  10401. //Reserved
  10402. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10403. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10404. goto end;
  10405. }
  10406. else
  10407. {
  10408. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10409. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10410. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10411. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10412. {
  10413. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10414. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10415. goto end;
  10416. }
  10417. }//END FOR ELSE
  10418. }
  10419. }// END FOR CHAdeMO_QUANTITY
  10420. }
  10421. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10422. {
  10423. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10424. {
  10425. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10426. }
  10427. else
  10428. {
  10429. tempIndex = connectorIdInt -1;
  10430. }
  10431. for (int index = 0; index < CCS_QUANTITY; index++)
  10432. {
  10433. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10434. {
  10435. 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))
  10436. {
  10437. //Reserved
  10438. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10439. }
  10440. 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))
  10441. {
  10442. //Reserved
  10443. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10444. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10445. goto end;
  10446. }
  10447. else
  10448. {
  10449. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10450. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10451. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10452. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10453. {
  10454. DEBUG_WARN("CCS connector not allow start\n.");
  10455. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10456. goto end;
  10457. }
  10458. }// END FOR ELSE
  10459. }
  10460. }// END FOR CCS_QUANTITY
  10461. }
  10462. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10463. {
  10464. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10465. {
  10466. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10467. }
  10468. else
  10469. {
  10470. tempIndex = connectorIdInt -1;
  10471. }
  10472. for (int index = 0; index < GB_QUANTITY; index++)
  10473. {
  10474. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10475. {
  10476. 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))
  10477. {
  10478. //Reserved
  10479. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10480. }
  10481. 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))
  10482. {
  10483. //Reserved
  10484. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10485. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10486. goto end;
  10487. }
  10488. else
  10489. {
  10490. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10491. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10492. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10493. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10494. {
  10495. DEBUG_WARN("GB connector not allow start\n.");
  10496. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10497. goto end;
  10498. }
  10499. }// END FOR ELSE
  10500. }
  10501. } // END FOR GB_QUANTITY
  10502. }
  10503. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10504. {
  10505. tempIndex = connectorIdInt -1;
  10506. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10507. {
  10508. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10509. {
  10510. 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))
  10511. {
  10512. //Reserved
  10513. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10514. }
  10515. 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))
  10516. {
  10517. //Reserved
  10518. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10519. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10520. goto end;
  10521. }
  10522. else
  10523. {
  10524. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10525. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10526. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10527. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10528. {
  10529. DEBUG_WARN("GB connector not allow start\n.");
  10530. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10531. goto end;
  10532. }
  10533. }// END FOR ELSE
  10534. }
  10535. } // END FOR GB_QUANTITY
  10536. }
  10537. else
  10538. {
  10539. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10540. {
  10541. tempIndex = 2;
  10542. }
  10543. else
  10544. {
  10545. tempIndex = connectorIdInt -1;
  10546. }
  10547. for (int index = 0; index < AC_QUANTITY; index++)
  10548. {
  10549. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10550. {
  10551. 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))
  10552. {
  10553. //Reserved
  10554. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10555. }
  10556. 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))
  10557. {
  10558. //Reserved
  10559. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10560. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10561. goto end;
  10562. }
  10563. else
  10564. {
  10565. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10566. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10567. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10568. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10569. {
  10570. DEBUG_WARN("AC connector not allow start\n.");
  10571. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10572. goto end;
  10573. }
  10574. }//END FOR ELSE
  10575. }
  10576. }// END FOR AC_QUANTITY
  10577. }
  10578. if(chargingProfileIsNULL == FALSE)
  10579. {
  10580. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10581. {
  10582. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10583. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10584. //memset idTag
  10585. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10586. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10587. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10588. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10589. // Save profile to file
  10590. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10591. system(cmdBuf);
  10592. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10593. fp = fopen(cmdBuf, "w");
  10594. 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));
  10595. fclose(fp);
  10596. }
  10597. else
  10598. {
  10599. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10600. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10601. }
  10602. }
  10603. else
  10604. {
  10605. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10606. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10607. //memset idTag
  10608. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10609. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10610. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10611. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10612. }
  10613. }
  10614. else
  10615. {
  10616. DEBUG_WARN("Connector id over\n.");
  10617. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10618. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10619. }
  10620. end:
  10621. json_object_put(RemoteStartTransaction);
  10622. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10623. {
  10624. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10625. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10626. }
  10627. //OCPP send RemoteStartConfirmation by first.
  10628. sendRemoteStartConfirmation(uuid, comfirmstr);
  10629. return result;
  10630. }
  10631. int handleRemoteStartRequest(char *uuid, char *payload)
  10632. {
  10633. mtrace();
  10634. int result = PASS;
  10635. int connectorIdInt=-1;
  10636. int tempIndex = 0;
  10637. char comfirmstr[20]={0};
  10638. char cmdBuf[512];
  10639. json_object *RemoteStartTransaction;
  10640. FILE *fp;
  10641. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10642. if(server_pending == TRUE)
  10643. {
  10644. result = FAIL;
  10645. }
  10646. RemoteStartTransaction = json_tokener_parse(payload);
  10647. if(!is_error(RemoteStartTransaction))
  10648. {
  10649. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10650. {
  10651. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10652. }
  10653. else
  10654. {
  10655. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10656. {
  10657. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10658. {
  10659. connectorIdInt = (gun_index+1);
  10660. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10661. break;
  10662. }
  10663. }
  10664. }
  10665. if(connectorIdInt == 0)
  10666. {
  10667. DEBUG_WARN("Connector id shall not equal 0.\n");
  10668. result = FAIL;
  10669. }
  10670. else if(connectorIdInt == -1)
  10671. {
  10672. DEBUG_INFO("Connector id does not specific.\n");
  10673. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10674. {
  10675. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10676. // Required data
  10677. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10678. // Optional data
  10679. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10680. {
  10681. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10682. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10683. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10684. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10685. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10686. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10687. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10688. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10689. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10690. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10691. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10692. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10693. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10694. {
  10695. 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")));
  10696. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10697. 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"));
  10698. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10699. 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"));
  10700. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10701. 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")));
  10702. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10703. {
  10704. 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++)
  10705. {
  10706. 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"));
  10707. 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"));
  10708. 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)
  10709. 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"));
  10710. }
  10711. }
  10712. }
  10713. }
  10714. else
  10715. {
  10716. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10717. }
  10718. }
  10719. }
  10720. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10721. {
  10722. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10723. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10724. // Required data
  10725. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10726. // Optional data
  10727. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10728. {
  10729. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10730. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10731. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10732. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10733. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10734. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10735. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10736. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10737. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10738. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10739. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10740. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10741. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10742. {
  10743. 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")));
  10744. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10745. 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"));
  10746. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10747. 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"));
  10748. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10749. 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")));
  10750. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10751. {
  10752. 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++)
  10753. {
  10754. 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"));
  10755. 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"));
  10756. 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)
  10757. 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"));
  10758. }
  10759. }
  10760. }
  10761. }
  10762. else
  10763. {
  10764. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10765. }
  10766. }
  10767. else
  10768. {
  10769. DEBUG_WARN("Connector id is over maximun value.\n");
  10770. result = FAIL;
  10771. }
  10772. }
  10773. if(result == PASS)
  10774. {
  10775. if(connectorIdInt > 0)
  10776. {
  10777. //check Transaction active
  10778. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10779. {
  10780. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10781. {
  10782. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10783. }
  10784. else
  10785. {
  10786. tempIndex = connectorIdInt -1;
  10787. }
  10788. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10789. {
  10790. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10791. {
  10792. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10793. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10794. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10795. {
  10796. //Reserved
  10797. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10798. }
  10799. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10800. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10801. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10802. {
  10803. //Reserved
  10804. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10805. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10806. goto end;
  10807. }
  10808. else
  10809. {
  10810. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10811. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10812. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10813. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10814. {
  10815. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10816. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10817. goto end;
  10818. }
  10819. }//END FOR ELSE
  10820. }
  10821. }// END FOR CHAdeMO_QUANTITY
  10822. }
  10823. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10824. {
  10825. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10826. {
  10827. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10828. }
  10829. else
  10830. {
  10831. tempIndex = connectorIdInt -1;
  10832. }
  10833. for (int index = 0; index < CCS_QUANTITY; index++)
  10834. {
  10835. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10836. {
  10837. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10838. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10839. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10840. {
  10841. //Reserved
  10842. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10843. }
  10844. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10845. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10846. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10847. {
  10848. //Reserved
  10849. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10850. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10851. goto end;
  10852. }
  10853. else
  10854. {
  10855. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10856. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10857. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10858. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10859. {
  10860. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10861. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10862. goto end;
  10863. }
  10864. }// END FOR ELSE
  10865. }
  10866. }// END FOR CCS_QUANTITY
  10867. }
  10868. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10869. {
  10870. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10871. {
  10872. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10873. }
  10874. else
  10875. {
  10876. tempIndex = connectorIdInt -1;
  10877. }
  10878. for (int index = 0; index < GB_QUANTITY; index++)
  10879. {
  10880. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10881. {
  10882. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10883. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10884. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10885. {
  10886. //Reserved
  10887. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10888. }
  10889. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10890. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10891. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10892. {
  10893. //Reserved
  10894. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10895. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10896. goto end;
  10897. }
  10898. else
  10899. {
  10900. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10901. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10902. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10903. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10904. {
  10905. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10906. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10907. goto end;
  10908. }
  10909. }// END FOR ELSE
  10910. }
  10911. } // END FOR GB_QUANTITY
  10912. }
  10913. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10914. {
  10915. tempIndex = connectorIdInt -1;
  10916. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10917. {
  10918. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10919. {
  10920. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10921. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10922. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10923. {
  10924. //Reserved
  10925. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10926. }
  10927. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10928. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10929. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10930. {
  10931. //Reserved
  10932. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10933. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10934. goto end;
  10935. }
  10936. else
  10937. {
  10938. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10939. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10940. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10941. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10942. {
  10943. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10944. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10945. goto end;
  10946. }
  10947. }// END FOR ELSE
  10948. }
  10949. } // END FOR GB_QUANTITY
  10950. }
  10951. else
  10952. {
  10953. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10954. {
  10955. tempIndex = 2;
  10956. }
  10957. else
  10958. {
  10959. tempIndex = connectorIdInt -1;
  10960. }
  10961. for (int index = 0; index < AC_QUANTITY; index++)
  10962. {
  10963. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10964. {
  10965. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10966. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10967. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10968. {
  10969. //Reserved
  10970. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10971. }
  10972. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10973. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10974. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10975. {
  10976. //Reserved
  10977. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10978. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10979. goto end;
  10980. }
  10981. else
  10982. {
  10983. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10984. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10985. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10986. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10987. {
  10988. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10989. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10990. goto end;
  10991. }
  10992. }//END FOR ELSE
  10993. }
  10994. }// END FOR AC_QUANTITY
  10995. }
  10996. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10997. {
  10998. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10999. {
  11000. // Save profile to file
  11001. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11002. system(cmdBuf);
  11003. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11004. fp = fopen(cmdBuf, "w");
  11005. 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));
  11006. fclose(fp);
  11007. }
  11008. else
  11009. {
  11010. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11011. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11012. goto end;
  11013. }
  11014. }
  11015. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11016. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11017. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11018. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11019. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11020. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11021. }
  11022. else
  11023. {
  11024. uint8_t isHasIdleConnector = FALSE;
  11025. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11026. {
  11027. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11028. {
  11029. isHasIdleConnector = TRUE;
  11030. break;
  11031. }
  11032. }
  11033. if(isHasIdleConnector == TRUE)
  11034. {
  11035. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11036. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11037. {
  11038. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11039. {
  11040. // Save profile to file
  11041. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11042. system(cmdBuf);
  11043. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11044. fp = fopen(cmdBuf, "w");
  11045. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11046. fclose(fp);
  11047. refreshStartTimer(&clientTime.RemoteStartWait);
  11048. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11049. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11050. }
  11051. else
  11052. {
  11053. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11054. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11055. }
  11056. }
  11057. else
  11058. {
  11059. refreshStartTimer(&clientTime.RemoteStartWait);
  11060. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11061. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11062. }
  11063. }
  11064. else
  11065. {
  11066. DEBUG_INFO("There is not any connector is idle.\n");
  11067. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11068. }
  11069. }
  11070. }
  11071. else
  11072. {
  11073. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11074. }
  11075. end:
  11076. json_object_put(RemoteStartTransaction);
  11077. sendRemoteStartConfirmation(uuid, comfirmstr);
  11078. return result;
  11079. }
  11080. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11081. {
  11082. mtrace();
  11083. int result = FAIL;
  11084. int match = FALSE;
  11085. int GunNO = 0;
  11086. int tempIndex = 0;
  11087. int transactionIdInt=0;
  11088. int transactionIdIsNULL= TRUE;
  11089. char comfirmstr[20];
  11090. json_object *RemoteStopTransaction;
  11091. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11092. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11093. if(server_pending == TRUE)
  11094. {
  11095. return 0;
  11096. }
  11097. RemoteStopTransaction = json_tokener_parse(payload);
  11098. if(!is_error(RemoteStopTransaction))
  11099. {
  11100. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11101. {
  11102. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11103. transactionIdIsNULL = FALSE;
  11104. }
  11105. }
  11106. json_object_put(RemoteStopTransaction);
  11107. if(transactionIdIsNULL == FALSE)
  11108. {
  11109. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11110. {
  11111. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11112. {
  11113. //check Transaction active
  11114. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11115. {
  11116. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11117. {
  11118. tempIndex = ((gun_index==2) ? 1: 0);
  11119. }
  11120. else
  11121. {
  11122. tempIndex = gun_index;
  11123. }
  11124. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11125. {
  11126. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11127. {
  11128. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11129. {
  11130. match = TRUE;
  11131. GunNO = gun_index;
  11132. }
  11133. }
  11134. }// END FOR CHAdeMO_QUANTITY
  11135. }
  11136. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11137. {
  11138. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11139. {
  11140. tempIndex = ((gun_index==2) ? 1: 0);
  11141. }
  11142. else
  11143. {
  11144. tempIndex = gun_index;
  11145. }
  11146. for (int index = 0; index < CCS_QUANTITY; index++)
  11147. {
  11148. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11149. {
  11150. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11151. {
  11152. match = TRUE;
  11153. GunNO = gun_index;
  11154. }
  11155. }
  11156. }// END FOR CCS_QUANTITY
  11157. }
  11158. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11159. {
  11160. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11161. {
  11162. tempIndex = ((gun_index==2) ? 1: 0);
  11163. }
  11164. else
  11165. {
  11166. tempIndex = gun_index;
  11167. }
  11168. for (int index = 0; index < GB_QUANTITY; index++)
  11169. {
  11170. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11171. {
  11172. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11173. {
  11174. match = TRUE;
  11175. GunNO = gun_index;
  11176. }
  11177. }
  11178. }// END FOR GB_QUANTITY
  11179. }
  11180. else if(gunType[gun_index] == GUN_TYPE_DO)
  11181. {
  11182. tempIndex = gun_index;
  11183. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11184. {
  11185. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11186. {
  11187. 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
  11188. {
  11189. match = TRUE;
  11190. GunNO = gun_index;
  11191. }
  11192. }
  11193. }// END FOR GB_QUANTITY
  11194. }
  11195. else
  11196. {
  11197. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11198. {
  11199. tempIndex = 2;
  11200. }
  11201. else
  11202. {
  11203. tempIndex = gun_index;
  11204. }
  11205. for (int index = 0; index < AC_QUANTITY; index++)
  11206. {
  11207. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11208. {
  11209. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11210. {
  11211. match = TRUE;
  11212. GunNO = gun_index;
  11213. }
  11214. }
  11215. }// END FOR CHAdeMO_QUANTITY
  11216. } // END FOR AC ELSE
  11217. }// CHECK IF ResponseTransactionId == transactionIdInt
  11218. }//END FOR
  11219. if( match == TRUE)
  11220. {
  11221. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11222. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11223. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11224. }
  11225. else
  11226. {
  11227. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11228. }
  11229. }
  11230. else
  11231. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11232. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11233. return result;
  11234. }
  11235. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11236. {
  11237. mtrace();
  11238. int result = FAIL;
  11239. int connectorIdInt=0, reservationIdInt=0;
  11240. int tempIndex = 0;
  11241. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  11242. char comfirmstr[20]={0};
  11243. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11244. int c = 0;
  11245. char *loc;
  11246. //char *ptr;
  11247. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11248. strcpy(sstrtemp, stringtrimspace(payload));
  11249. //***(1)connectorId ****/
  11250. c=0;
  11251. loc = strstr(sstrtemp, "connectorId");
  11252. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11253. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11254. {
  11255. sstr[c] = loc[strlen("connectorId")+2+c];
  11256. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11257. c++;
  11258. }
  11259. sstr[c] = '\0';
  11260. connectorIdInt = atoi(sstr);
  11261. //***(2)expiryDate ****/
  11262. loc = strstr(sstrtemp, "expiryDate");
  11263. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11264. c = 0;
  11265. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11266. {
  11267. sstr[c] = loc[3+strlen("expiryDate")+c];
  11268. c++;
  11269. }
  11270. sstr[c] = '\0';
  11271. strcpy(expiryDatestr, sstr);
  11272. //***(3)idTag ****/
  11273. loc = strstr(sstrtemp, "idTag");
  11274. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11275. c = 0;
  11276. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11277. {
  11278. sstr[c] = loc[3+strlen("idTag")+c];
  11279. c++;
  11280. }
  11281. sstr[c] = '\0';
  11282. strcpy(idTagstr, sstr);
  11283. //***(4)parentIdTag ****/
  11284. loc = strstr(sstrtemp, "parentIdTag");
  11285. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11286. c = 0;
  11287. if(loc == NULL)
  11288. {
  11289. strcpy(parentIdTagstr, "");
  11290. }
  11291. else
  11292. {
  11293. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11294. {
  11295. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11296. c++;
  11297. }
  11298. sstr[c] = '\0';
  11299. strcpy(parentIdTagstr, sstr);
  11300. }
  11301. //***(5)reservationId ****/
  11302. c=0;
  11303. loc = strstr(sstrtemp, "reservationId");
  11304. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11305. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11306. {
  11307. sstr[c] = loc[strlen("reservationId")+2+c];
  11308. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11309. c++;
  11310. }
  11311. sstr[c] = '\0';
  11312. reservationIdInt = atoi(sstr);
  11313. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11314. /*
  11315. enum SYSTEM_STATUS
  11316. {
  11317. SYS_MODE_BOOTING = 0,
  11318. SYS_MODE_IDLE = 1,
  11319. SYS_MODE_AUTHORIZING = 2,
  11320. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11321. SYS_MODE_REASSIGN = 4,
  11322. SYS_MODE_PREPARING = 5,
  11323. SYS_MODE_PREPARE_FOR_EV = 6,
  11324. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11325. SYS_MODE_CHARGING = 8,
  11326. SYS_MODE_TERMINATING = 9,
  11327. SYS_MODE_COMPLETE = 10,
  11328. SYS_MODE_ALARM = 11,
  11329. SYS_MODE_FAULT = 12,
  11330. SYS_MODE_RESERVATION = 13,
  11331. SYS_MODE_BOOKING = 14,
  11332. SYS_MODE_MAINTAIN = 15,
  11333. SYS_MODE_DEBUG = 16,
  11334. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11335. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11336. SYS_MODE_UPDATE = 19
  11337. };
  11338. */
  11339. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11340. {
  11341. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11342. goto end;
  11343. }
  11344. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11345. {
  11346. //check Transaction active
  11347. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11348. {
  11349. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11350. {
  11351. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11352. }
  11353. else
  11354. {
  11355. tempIndex = connectorIdInt -1;
  11356. }
  11357. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11358. {
  11359. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11360. {
  11361. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11362. {
  11363. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11364. {
  11365. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11366. {
  11367. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11368. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11369. }
  11370. 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'))
  11371. {
  11372. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11373. }
  11374. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11375. {
  11376. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11377. }
  11378. else
  11379. {
  11380. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11381. }
  11382. }
  11383. 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
  11384. {
  11385. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11386. }
  11387. }
  11388. else
  11389. {
  11390. //replace reservation
  11391. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11392. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11393. }
  11394. }
  11395. } // END FOR CHAdeMO_QUANTITY
  11396. }
  11397. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11398. {
  11399. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11400. {
  11401. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11402. }
  11403. else
  11404. {
  11405. tempIndex = connectorIdInt -1;
  11406. }
  11407. for (int index = 0; index < CCS_QUANTITY; index++)
  11408. {
  11409. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11410. {
  11411. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11412. {
  11413. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11414. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11415. {
  11416. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11417. {
  11418. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11419. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11420. }
  11421. 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'))
  11422. {
  11423. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11424. }
  11425. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11426. {
  11427. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11428. }
  11429. else
  11430. {
  11431. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11432. }
  11433. }
  11434. 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
  11435. {
  11436. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11437. }
  11438. }
  11439. else
  11440. {
  11441. //replace reservation
  11442. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11443. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11444. }
  11445. }
  11446. } // END FOR CCS_QUANTITY
  11447. }
  11448. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11449. {
  11450. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11451. {
  11452. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11453. }
  11454. else
  11455. {
  11456. tempIndex = connectorIdInt -1;
  11457. }
  11458. for (int index = 0; index < GB_QUANTITY; index++)
  11459. {
  11460. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11461. {
  11462. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11463. {
  11464. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11465. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11466. {
  11467. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11468. {
  11469. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11470. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11471. }
  11472. 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'))
  11473. {
  11474. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11475. }
  11476. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11477. {
  11478. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11479. }
  11480. else
  11481. {
  11482. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11483. }
  11484. }
  11485. 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
  11486. {
  11487. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11488. }
  11489. }
  11490. else
  11491. {
  11492. //replace reservation
  11493. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11494. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11495. }
  11496. }
  11497. }// END FOR GB_QUANTITY
  11498. }
  11499. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11500. {
  11501. tempIndex = connectorIdInt -1;
  11502. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11503. {
  11504. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11505. {
  11506. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11507. {
  11508. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11509. 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
  11510. {
  11511. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11512. {
  11513. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11514. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11515. }
  11516. 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'))
  11517. {
  11518. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11519. }
  11520. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11521. {
  11522. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11523. }
  11524. else
  11525. {
  11526. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11527. }
  11528. }
  11529. 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
  11530. {
  11531. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11532. }
  11533. }
  11534. else
  11535. {
  11536. //replace reservation
  11537. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11538. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11539. }
  11540. }
  11541. }// END FOR GB_QUANTITY
  11542. }
  11543. else
  11544. {
  11545. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11546. {
  11547. tempIndex = 2;
  11548. }
  11549. else
  11550. {
  11551. tempIndex = (connectorIdInt -1);
  11552. }
  11553. for (int index = 0; index < AC_QUANTITY; index++)
  11554. {
  11555. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11556. {
  11557. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11558. {
  11559. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11560. {
  11561. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11562. {
  11563. 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))
  11564. {
  11565. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11566. }
  11567. else
  11568. {
  11569. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11570. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11571. }
  11572. }
  11573. 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'))
  11574. {
  11575. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11576. }
  11577. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11578. {
  11579. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11580. }
  11581. else
  11582. {
  11583. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11584. }
  11585. }
  11586. 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
  11587. {
  11588. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11589. }
  11590. }
  11591. else
  11592. {
  11593. //replace reservation
  11594. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11595. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11596. }
  11597. }
  11598. } // END FOR AC_QUANTITY
  11599. }
  11600. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11601. }
  11602. else if(connectorIdInt == 0)
  11603. {
  11604. //check Transaction active
  11605. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11606. {
  11607. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11608. {
  11609. 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'))
  11610. {
  11611. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11612. goto end;
  11613. }
  11614. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11615. {
  11616. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11617. goto end;
  11618. }
  11619. 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
  11620. {
  11621. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11622. goto end;
  11623. }
  11624. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11625. {
  11626. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11627. goto end;
  11628. }
  11629. }
  11630. }// END FOR CHAdeMO_QUANTITY
  11631. for (int index = 0; index < CCS_QUANTITY; index++)
  11632. {
  11633. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11634. {
  11635. 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'))
  11636. {
  11637. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11638. goto end;
  11639. }
  11640. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11641. {
  11642. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11643. goto end;
  11644. }
  11645. 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
  11646. {
  11647. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11648. goto end;
  11649. }
  11650. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11651. {
  11652. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11653. goto end;
  11654. }
  11655. }
  11656. } // END FOR CCS_QUANTITY
  11657. for (int index = 0; index < GB_QUANTITY; index++)
  11658. {
  11659. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11660. {
  11661. 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'))
  11662. {
  11663. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11664. goto end;
  11665. }
  11666. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11667. {
  11668. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11669. goto end;
  11670. }
  11671. 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
  11672. {
  11673. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11674. goto end;
  11675. }
  11676. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11677. {
  11678. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11679. goto end;
  11680. }
  11681. }
  11682. } // END FOR GB_QUANTITY
  11683. for (int index = 0; index < AC_QUANTITY; index++)
  11684. {
  11685. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11686. {
  11687. 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'))
  11688. {
  11689. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11690. goto end;
  11691. }
  11692. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11693. {
  11694. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11695. goto end;
  11696. }
  11697. 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
  11698. {
  11699. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11700. goto end;
  11701. }
  11702. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11703. {
  11704. 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))
  11705. {
  11706. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11707. goto end;
  11708. }
  11709. }
  11710. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11711. {
  11712. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11713. goto end;
  11714. }
  11715. }
  11716. }// END FOR AC_QUANTITY
  11717. //The connectorId is 0
  11718. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  11719. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11720. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11721. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  11722. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11723. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  11724. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11725. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  11726. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  11727. result = TRUE;
  11728. return result;
  11729. }
  11730. else
  11731. {
  11732. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11733. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11734. }
  11735. if(strcmp(comfirmstr,"Accepted") == 0)
  11736. {
  11737. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11738. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11739. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11740. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11741. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11742. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  11743. result = TRUE;
  11744. return result;
  11745. }
  11746. end:
  11747. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11748. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11749. return result;
  11750. }
  11751. int handleResetRequest(char *uuid, char *payload)
  11752. {
  11753. mtrace();
  11754. int result = FAIL;
  11755. char sstr[10]={0},sstrtemp[30]={ 0 };
  11756. char typestr[10]={0};
  11757. char comfirmstr[20]={0};
  11758. int c = 0;
  11759. char *loc;
  11760. DEBUG_INFO("handleResetRequest...\n");
  11761. strcpy(sstrtemp, stringtrimspace(payload));
  11762. loc = strstr(sstrtemp, "type");
  11763. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11764. c = 0;
  11765. while (loc[3+strlen("type")+c] != '\"')
  11766. {
  11767. sstr[c] = loc[3+strlen("type")+c];
  11768. c++;
  11769. }
  11770. sstr[c] = '\0';
  11771. strcpy(typestr,sstr);
  11772. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11773. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11774. {
  11775. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11776. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  11777. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11778. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11779. }
  11780. else
  11781. {
  11782. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11783. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11784. result = PASS;
  11785. }
  11786. sendResetConfirmation(uuid, comfirmstr);
  11787. return result;
  11788. }
  11789. int handleSendLocalListRequest(char *uuid, char *payload)
  11790. {
  11791. mtrace();
  11792. int result = FAIL;
  11793. char comfirmstr[20];
  11794. int checkState_Faulted = FALSE;
  11795. json_object *SendLocalList;
  11796. DEBUG_INFO("handleSendLocalListRequest...\n");
  11797. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11798. {
  11799. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11800. goto end;
  11801. }
  11802. //check Charge Point state
  11803. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11804. {
  11805. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11806. {
  11807. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11808. }
  11809. }
  11810. for (int index = 0; index < CCS_QUANTITY; index++)
  11811. {
  11812. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11813. {
  11814. checkState_Faulted = TRUE; //OCPP Status
  11815. }
  11816. }
  11817. for (int index = 0; index < GB_QUANTITY; index++)
  11818. {
  11819. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11820. {
  11821. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11822. }
  11823. }
  11824. //check Charge Point state
  11825. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11826. {
  11827. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11828. {
  11829. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11830. }
  11831. }
  11832. //check Charge Point state
  11833. for (int index = 0; index < AC_QUANTITY; index++)
  11834. {
  11835. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11836. {
  11837. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11838. }
  11839. }
  11840. if(checkState_Faulted == TRUE)
  11841. {
  11842. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11843. goto end;
  11844. }
  11845. // Parsing payload
  11846. SendLocalList = json_tokener_parse(payload);
  11847. if(!is_error(SendLocalList))
  11848. {
  11849. // Required data
  11850. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11851. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11852. // Optional data
  11853. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11854. {
  11855. //Check UpdateType
  11856. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11857. {
  11858. //Local list full update
  11859. DEBUG_INFO("Local list full update.\n");
  11860. OCPP_getListVerion();
  11861. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11862. {
  11863. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11864. goto end;
  11865. }
  11866. OCPP_cleanLocalList();
  11867. }
  11868. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11869. {
  11870. //Local list different update
  11871. DEBUG_INFO("Local list different update.\n");
  11872. OCPP_getListVerion();
  11873. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11874. {
  11875. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11876. goto end;
  11877. }
  11878. }
  11879. else
  11880. {
  11881. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11882. goto end;
  11883. }
  11884. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11885. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11886. {
  11887. 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")));
  11888. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11889. {
  11890. 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")));
  11891. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11892. 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")));
  11893. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11894. 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")));
  11895. }
  11896. // Add to db
  11897. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11898. {
  11899. //Local list full update
  11900. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11901. idx,
  11902. ShmOCPP16Data->SendLocalList.ListVersion,
  11903. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11904. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11905. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11906. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11907. // update list
  11908. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11909. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11910. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11911. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11912. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11913. }
  11914. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11915. {
  11916. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11917. idx,
  11918. ShmOCPP16Data->SendLocalList.ListVersion,
  11919. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11920. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11921. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11922. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11923. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11924. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11925. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11926. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11927. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11928. }
  11929. }
  11930. }
  11931. else
  11932. {
  11933. //Check UpdateType
  11934. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11935. {
  11936. //Local list full update
  11937. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11938. OCPP_cleanLocalList();
  11939. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11940. goto end;
  11941. }
  11942. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11943. {
  11944. //Local list different update
  11945. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11946. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11947. goto end;
  11948. }
  11949. }
  11950. result = PASS;
  11951. }
  11952. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11953. end:
  11954. json_object_put(SendLocalList);
  11955. sendSendLocalListConfirmation(uuid, comfirmstr);
  11956. return result;
  11957. }
  11958. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11959. {
  11960. mtrace();
  11961. int result = FAIL;
  11962. struct StructSetChargingProfile SetProfileReq = {0};
  11963. int tempchargingProfileIdInt;
  11964. int tempstackLevelInt;
  11965. int chargingSchedulePeriodCount = 0;
  11966. char comfirmstr[20]={0};
  11967. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  11968. char rmFileCmd[128]={0};
  11969. int profileQuantity = 0;
  11970. int isReplaceable = FALSE;
  11971. json_object *SetChargingProfile;
  11972. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11973. SetChargingProfile = json_tokener_parse(payload);
  11974. if(!is_error(SetChargingProfile))
  11975. {
  11976. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11977. {
  11978. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11979. }
  11980. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11981. {
  11982. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11983. {
  11984. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11985. }
  11986. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11987. {
  11988. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11989. }
  11990. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11991. {
  11992. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11993. }
  11994. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11995. {
  11996. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11997. }
  11998. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11999. {
  12000. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12001. }
  12002. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12003. {
  12004. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12005. }
  12006. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12007. {
  12008. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12009. }
  12010. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12011. {
  12012. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12013. }
  12014. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12015. {
  12016. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12017. {
  12018. 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")));
  12019. }
  12020. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12021. {
  12022. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12023. }
  12024. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12025. {
  12026. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12027. }
  12028. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12029. {
  12030. 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")));
  12031. }
  12032. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12033. {
  12034. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12035. if(chargingSchedulePeriodCount <= 10)
  12036. {
  12037. 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++)
  12038. {
  12039. 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)
  12040. {
  12041. 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"));
  12042. }
  12043. 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)
  12044. {
  12045. 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"));
  12046. }
  12047. 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)
  12048. {
  12049. 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"));
  12050. }
  12051. }
  12052. }
  12053. }
  12054. }
  12055. }
  12056. }
  12057. // Profile periods quantity check
  12058. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12059. {
  12060. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12061. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12062. goto end;
  12063. }
  12064. // Check invalid limit
  12065. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12066. {
  12067. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12068. {
  12069. 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)))) ||
  12070. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12071. {
  12072. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12073. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12074. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12075. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12076. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12077. goto end;
  12078. }
  12079. }
  12080. }
  12081. else
  12082. {
  12083. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12084. {
  12085. 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))
  12086. {
  12087. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12088. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12089. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12090. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12091. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12092. goto end;
  12093. }
  12094. }
  12095. }
  12096. // Profile purpose info check
  12097. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12098. {
  12099. FILE *fp;
  12100. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12101. if(SetProfileReq.ConnectorId != 0)
  12102. {
  12103. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12104. DEBUG_WARN("Profile connector id is not 0.\n");
  12105. goto end;
  12106. }
  12107. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12108. if (!fp)
  12109. {
  12110. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12111. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12112. }
  12113. else
  12114. {
  12115. char *line = NULL;
  12116. size_t len = 0;
  12117. while(getline(&line, &len, fp) != -1)
  12118. {
  12119. json_object *obj = NULL;
  12120. obj = json_tokener_parse(line);
  12121. if(is_error(obj))
  12122. {
  12123. DEBUG_ERROR("Parse txProfile from file error.\n");
  12124. }
  12125. else
  12126. {
  12127. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12128. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12129. {
  12130. profileQuantity += 1;
  12131. }
  12132. else
  12133. isReplaceable = TRUE;
  12134. }
  12135. }
  12136. }
  12137. fclose(fp);
  12138. }
  12139. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12140. {
  12141. FILE *fp;
  12142. char filename[128]={0};
  12143. int tmpProfileQuantity;
  12144. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12145. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12146. {
  12147. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12148. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12149. goto end;
  12150. }
  12151. if(SetProfileReq.ConnectorId == 0)
  12152. {
  12153. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12154. {
  12155. tmpProfileQuantity = 0;
  12156. memset(filename, 0, ARRAY_SIZE(filename));
  12157. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12158. fp = fopen(filename, "r");
  12159. if (!fp)
  12160. {
  12161. DEBUG_INFO("%s does not create.\n", filename);
  12162. fp = fopen(filename, "w+");
  12163. }
  12164. else
  12165. {
  12166. char *line = NULL;
  12167. size_t len = 0;
  12168. while(getline(&line, &len, fp) != -1)
  12169. {
  12170. json_object *obj = NULL;
  12171. obj = json_tokener_parse(line);
  12172. if(is_error(obj))
  12173. {
  12174. DEBUG_ERROR("Parse txProfile from file error.\n");
  12175. }
  12176. else
  12177. {
  12178. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12179. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12180. {
  12181. tmpProfileQuantity += 1;
  12182. }
  12183. else
  12184. isReplaceable = TRUE;
  12185. }
  12186. }
  12187. }
  12188. fclose(fp);
  12189. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12190. }
  12191. }
  12192. else
  12193. {
  12194. memset(filename, 0, ARRAY_SIZE(filename));
  12195. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12196. fp = fopen(filename, "r");
  12197. if (!fp)
  12198. {
  12199. DEBUG_INFO("%s does not create.\n", filename);
  12200. fp = fopen(filename, "w+");
  12201. }
  12202. else
  12203. {
  12204. char *line = NULL;
  12205. size_t len = 0;
  12206. while(getline(&line, &len, fp) != -1)
  12207. {
  12208. json_object *obj = NULL;
  12209. obj = json_tokener_parse(line);
  12210. if(is_error(obj))
  12211. {
  12212. DEBUG_ERROR("Parse txProfile from file error.\n");
  12213. }
  12214. else
  12215. {
  12216. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12217. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12218. {
  12219. profileQuantity += 1;
  12220. }
  12221. else
  12222. isReplaceable = TRUE;
  12223. }
  12224. }
  12225. }
  12226. fclose(fp);
  12227. }
  12228. }
  12229. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12230. {
  12231. int isMatchTransactiodId= FALSE;
  12232. FILE *fp;
  12233. char filename[128]={0};
  12234. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12235. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12236. if(SetProfileReq.ConnectorId == 0)
  12237. {
  12238. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12239. DEBUG_WARN("Profile connector id is 0.\n");
  12240. goto end;
  12241. }
  12242. int tempIndex = 0;
  12243. //check Transaction active
  12244. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12245. {
  12246. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12247. {
  12248. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12249. }
  12250. else
  12251. {
  12252. tempIndex = SetProfileReq.ConnectorId -1;
  12253. }
  12254. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12255. {
  12256. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12257. {
  12258. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12259. {
  12260. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12261. {
  12262. isMatchTransactiodId = TRUE;
  12263. break;
  12264. }
  12265. }
  12266. }
  12267. }
  12268. }
  12269. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12270. {
  12271. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12272. {
  12273. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12274. }
  12275. else
  12276. {
  12277. tempIndex = SetProfileReq.ConnectorId -1;
  12278. }
  12279. for (int index = 0; index < CCS_QUANTITY; index++)
  12280. {
  12281. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12282. {
  12283. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12284. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12285. {
  12286. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12287. {
  12288. isMatchTransactiodId = TRUE;
  12289. break;
  12290. }
  12291. }
  12292. }
  12293. }
  12294. }
  12295. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12296. {
  12297. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12298. {
  12299. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12300. }
  12301. else
  12302. {
  12303. tempIndex = SetProfileReq.ConnectorId -1;
  12304. }
  12305. for (int index = 0; index < GB_QUANTITY; index++)
  12306. {
  12307. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12308. {
  12309. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12310. {
  12311. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12312. {
  12313. isMatchTransactiodId = TRUE;
  12314. break;
  12315. }
  12316. }
  12317. }
  12318. }
  12319. }
  12320. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12321. {
  12322. tempIndex = SetProfileReq.ConnectorId -1;
  12323. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12324. {
  12325. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12326. {
  12327. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12328. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12329. {
  12330. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12331. {
  12332. isMatchTransactiodId = TRUE;
  12333. break;
  12334. }
  12335. }
  12336. }
  12337. }
  12338. }
  12339. else
  12340. {
  12341. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12342. {
  12343. tempIndex = 2;
  12344. }
  12345. else
  12346. {
  12347. tempIndex = (SetProfileReq.ConnectorId -1);
  12348. }
  12349. for (int index = 0; index < AC_QUANTITY; index++)
  12350. {
  12351. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12352. {
  12353. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12354. {
  12355. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12356. {
  12357. isMatchTransactiodId = TRUE;
  12358. break;
  12359. }
  12360. }
  12361. }
  12362. }
  12363. }
  12364. //check Transaction active
  12365. if(isMatchTransactiodId == FALSE)
  12366. {
  12367. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12368. DEBUG_WARN("Tx profile transaction id is not match.\n");
  12369. goto end;
  12370. }
  12371. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12372. {
  12373. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12374. DEBUG_WARN("Connector id is over max gun number.\n");
  12375. goto end;
  12376. }
  12377. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12378. fp = fopen(filename, "r");
  12379. if (!fp)
  12380. {
  12381. DEBUG_INFO("%s does not create.\n", filename);
  12382. fp = fopen(filename, "w+");
  12383. }
  12384. else
  12385. {
  12386. char *line = NULL;
  12387. size_t len = 0;
  12388. while(getline(&line, &len, fp) != -1)
  12389. {
  12390. json_object *obj = NULL;
  12391. obj = json_tokener_parse(line);
  12392. if(is_error(obj))
  12393. {
  12394. DEBUG_ERROR("Parse txProfile from file error.\n");
  12395. }
  12396. else
  12397. {
  12398. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12399. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12400. {
  12401. profileQuantity += 1;
  12402. }
  12403. else
  12404. isReplaceable = TRUE;
  12405. }
  12406. }
  12407. }
  12408. fclose(fp);
  12409. }
  12410. // Check ChargeProfileMaxStackLevel
  12411. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12412. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12413. {
  12414. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12415. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12416. goto end;
  12417. }
  12418. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12419. {
  12420. FILE *fp;
  12421. char dataLine[4096]={0};
  12422. char fnametemp[128]={0};
  12423. int tmpProfileQuantity;
  12424. //Check ChargePointMaxProfile.json exit
  12425. profileQuantity = 0;
  12426. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12427. {
  12428. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  12429. //Check Charging Profile Count
  12430. tmpProfileQuantity = 0;
  12431. while(fscanf(fp, "%s", dataLine) != EOF)
  12432. {
  12433. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12434. {
  12435. profileQuantity += 1;
  12436. tmpProfileQuantity += 1;
  12437. }
  12438. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12439. }
  12440. fclose(fp);
  12441. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12442. }
  12443. //Check TxDefaultProfile_%d.json
  12444. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12445. {
  12446. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12447. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12448. if((access(fnametemp,F_OK))!=-1)
  12449. {
  12450. fp = fopen(fnametemp, "r");
  12451. //Check Charging Profile Count
  12452. tmpProfileQuantity = 0;
  12453. while(fscanf(fp, "%s", dataLine) != EOF)
  12454. {
  12455. //DEBUG_INFO("word=%s\n",word);
  12456. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12457. {
  12458. profileQuantity += 1;
  12459. tmpProfileQuantity += 1;
  12460. }
  12461. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12462. }
  12463. fclose(fp);
  12464. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12465. }
  12466. }
  12467. //Check TxProfile_%d.json
  12468. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12469. {
  12470. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12471. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  12472. if((access(fnametemp,F_OK))!=-1)
  12473. {
  12474. fp = fopen(fnametemp, "r");
  12475. //Check Charging Profile Count
  12476. tmpProfileQuantity = 0;
  12477. while(fscanf(fp, "%s", dataLine) != EOF)
  12478. {
  12479. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12480. {
  12481. profileQuantity += 1;
  12482. tmpProfileQuantity += 1;
  12483. }
  12484. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12485. }
  12486. fclose(fp);
  12487. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12488. }
  12489. }
  12490. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12491. if((profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData)) && (isReplaceable != TRUE))
  12492. {
  12493. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12494. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12495. goto end;
  12496. }
  12497. }
  12498. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12499. //**********************************Write to File********************************************************/
  12500. {
  12501. FILE *infile;
  12502. FILE *outfile;
  12503. char dataLine[4096]={0};
  12504. char filename[128]={0};
  12505. int chkChar=0;
  12506. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12507. {
  12508. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12509. {
  12510. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12511. }
  12512. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12513. {
  12514. if(SetProfileReq.ConnectorId==0)
  12515. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12516. else
  12517. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12518. }
  12519. else
  12520. {
  12521. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12522. }
  12523. infile = fopen (filename, "r");
  12524. outfile = fopen (tempfile, "w");
  12525. chkChar = fgetc(infile);
  12526. rewind(infile);
  12527. if(chkChar == EOF)
  12528. {
  12529. // Profile is empty
  12530. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12531. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12532. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12533. fclose(infile);
  12534. fclose(outfile);
  12535. sprintf(rmFileCmd,"rm -f %s",filename);
  12536. system(rmFileCmd);
  12537. rename(tempfile, filename);
  12538. }
  12539. else
  12540. {
  12541. // Profile is not empty
  12542. int ChargingProfileAdded = FALSE;
  12543. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12544. {
  12545. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12546. json_object *tmpChargingProfile;
  12547. tmpChargingProfile = json_tokener_parse(dataLine);
  12548. if(!is_error(SetChargingProfile))
  12549. {
  12550. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12551. {
  12552. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12553. {
  12554. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12555. }
  12556. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12557. {
  12558. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12559. }
  12560. }
  12561. }
  12562. json_object_put(tmpChargingProfile);
  12563. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12564. {
  12565. if(ChargingProfileAdded == FALSE)
  12566. {
  12567. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12568. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12569. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12570. ChargingProfileAdded = TRUE;
  12571. }
  12572. }
  12573. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  12574. {
  12575. if(ChargingProfileAdded == FALSE)
  12576. {
  12577. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12578. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12579. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12580. ChargingProfileAdded = TRUE;
  12581. }
  12582. }
  12583. else
  12584. {
  12585. fprintf(outfile,"%s\n",dataLine);
  12586. if(ChargingProfileAdded == FALSE)
  12587. {
  12588. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12589. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12590. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12591. ChargingProfileAdded = TRUE;
  12592. }
  12593. }
  12594. } // end of while loop
  12595. fclose(infile);
  12596. fclose(outfile);
  12597. sprintf(rmFileCmd,"rm -f %s",filename);
  12598. system(rmFileCmd);
  12599. rename(tempfile, filename);
  12600. }
  12601. }
  12602. sleep(1);
  12603. result = TRUE;
  12604. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12605. }
  12606. end:
  12607. json_object_put(SetChargingProfile);
  12608. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12609. {
  12610. if(SetProfileReq.ConnectorId == 0)
  12611. {
  12612. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12613. {
  12614. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  12615. }
  12616. }
  12617. else
  12618. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12619. }
  12620. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12621. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12622. return result;
  12623. }
  12624. int handleTriggerMessageRequest(char *uuid, char *payload)
  12625. {
  12626. mtrace();
  12627. int result = FAIL;
  12628. int connectorIdIsNULL = FALSE;
  12629. int connectorIdInt =0;
  12630. char sstr[40]={0},sstrtemp[100]={ 0 };
  12631. char requestedMessagestr[40]={0};
  12632. char comfirmstr[20]={0};
  12633. int c = 0;
  12634. char *loc;
  12635. DEBUG_INFO("handleTriggerMessageRequest\n");
  12636. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12637. strcpy(sstrtemp, stringtrimspace(payload));
  12638. c = 0;
  12639. loc = strstr(sstrtemp, "requestedMessage");
  12640. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12641. {
  12642. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12643. c++;
  12644. }
  12645. sstr[c] = '\0';
  12646. strcpy(requestedMessagestr, sstr);
  12647. c = 0;
  12648. loc = strstr(sstrtemp, "connectorId");
  12649. if(loc == NULL)
  12650. {
  12651. connectorIdIsNULL = TRUE;
  12652. }
  12653. else
  12654. {
  12655. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12656. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12657. {
  12658. sstr[c] = loc[strlen("connectorId")+2+c];
  12659. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12660. c++;
  12661. }
  12662. sstr[c] = '\0';
  12663. connectorIdInt = atoi(sstr);
  12664. }
  12665. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12666. {
  12667. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12668. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12669. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12670. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12671. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12672. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12673. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12674. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12675. {
  12676. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12677. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12678. return TRUE;
  12679. }
  12680. else
  12681. {
  12682. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12683. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12684. }
  12685. }
  12686. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12687. {
  12688. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12689. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12690. return TRUE;
  12691. }
  12692. //==========================
  12693. // Trigger message
  12694. //==========================
  12695. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12696. {
  12697. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12698. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12699. {
  12700. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12701. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12702. }
  12703. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12704. }
  12705. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12706. {
  12707. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  12708. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12709. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12710. }
  12711. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12712. {
  12713. //sendBootNotificationRequest();
  12714. server_sign = FALSE;
  12715. }
  12716. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12717. {
  12718. refreshStartTimer(&clientTime.Heartbeat);
  12719. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  12720. }
  12721. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12722. {
  12723. if(connectorIdIsNULL == FALSE)
  12724. {
  12725. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12726. {
  12727. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12728. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12729. }
  12730. }
  12731. else
  12732. {
  12733. for(int idx=0;idx< gunTotalNumber;idx++)
  12734. {
  12735. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12736. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12737. }
  12738. }
  12739. }
  12740. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12741. {
  12742. if(connectorIdIsNULL == FALSE)
  12743. {
  12744. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  12745. {
  12746. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12747. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  12748. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12749. }
  12750. }
  12751. else
  12752. {
  12753. for(int idx=0;idx< gunTotalNumber;idx++)
  12754. {
  12755. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  12756. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12757. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12758. }
  12759. }
  12760. }
  12761. return result;
  12762. }
  12763. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12764. {
  12765. mtrace();
  12766. int result = FAIL;
  12767. int connectorIdInt =0;
  12768. char comfirmstr[20]={0};
  12769. int tempIndex = 0;
  12770. json_object *UnlockConnector;
  12771. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12772. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12773. UnlockConnector = json_tokener_parse(payload);
  12774. if(!is_error(UnlockConnector))
  12775. {
  12776. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12777. {
  12778. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12779. }
  12780. }
  12781. json_object_put(UnlockConnector);
  12782. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12783. if(gunTotalNumber == 0)
  12784. {
  12785. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12786. goto end;
  12787. }
  12788. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12789. {
  12790. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12791. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12792. goto end;
  12793. }
  12794. else
  12795. {
  12796. //check Transaction active
  12797. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12798. {
  12799. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12800. {
  12801. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12802. }
  12803. else
  12804. {
  12805. tempIndex = connectorIdInt -1;
  12806. }
  12807. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12808. {
  12809. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12810. {
  12811. //stop Transaction
  12812. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12813. }
  12814. }
  12815. }
  12816. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12817. {
  12818. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12819. {
  12820. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12821. }
  12822. else
  12823. {
  12824. tempIndex = connectorIdInt -1;
  12825. }
  12826. for (int index = 0; index < CCS_QUANTITY; index++)
  12827. {
  12828. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12829. {
  12830. //stop Transaction
  12831. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12832. }
  12833. }
  12834. }
  12835. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12836. {
  12837. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12838. {
  12839. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12840. }
  12841. else
  12842. {
  12843. tempIndex = connectorIdInt -1;
  12844. }
  12845. for (int index = 0; index < GB_QUANTITY; index++)
  12846. {
  12847. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12848. {
  12849. //stop Transaction
  12850. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12851. }
  12852. }
  12853. }
  12854. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12855. {
  12856. tempIndex = connectorIdInt -1;
  12857. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12858. {
  12859. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12860. {
  12861. //stop Transaction
  12862. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12863. }
  12864. }
  12865. }
  12866. else
  12867. {
  12868. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12869. {
  12870. tempIndex = 2;
  12871. }
  12872. else
  12873. {
  12874. tempIndex = connectorIdInt-1;
  12875. }
  12876. for (int index = 0; index < AC_QUANTITY; index++)
  12877. {
  12878. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12879. {
  12880. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12881. }
  12882. }
  12883. }
  12884. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12885. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  12886. result = TRUE;
  12887. return result;
  12888. }
  12889. end:
  12890. //json_object_put(obj); --- remove temporally
  12891. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12892. return result;
  12893. }
  12894. static char UpdateFirmwarepayloadData[300]={0};
  12895. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12896. {
  12897. mtrace();
  12898. int result = FAIL;
  12899. pthread_t t;
  12900. sendUpdateFirmwareConfirmation(uuid);
  12901. memset(UpdateFirmwarepayloadData, 0, 300);
  12902. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12903. if(!interLock.isUpdateFirmwareGoing)
  12904. {
  12905. interLock.isUpdateFirmwareGoing = 1;
  12906. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12907. sleep(1);
  12908. }
  12909. else
  12910. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12911. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  12912. return result;
  12913. }
  12914. void *UpdateFirmwareProcess(void *data)
  12915. {
  12916. pthread_detach(pthread_self());
  12917. mtrace();
  12918. int retriesInt =0, retryIntervalInt=0;
  12919. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  12920. int port=0;
  12921. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  12922. int isSuccess = 0;
  12923. char ftpbuf[1024];
  12924. char temp[1024];
  12925. char * pch;
  12926. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12927. json_object *UpdateFirmware;
  12928. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12929. if(!is_error(UpdateFirmware))
  12930. {
  12931. // Required data
  12932. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12933. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12934. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12935. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12936. // Optional data
  12937. if(json_object_object_get(UpdateFirmware, "retries"))
  12938. {
  12939. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12940. }
  12941. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12942. {
  12943. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12944. }
  12945. }
  12946. json_object_put(UpdateFirmware);
  12947. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12948. memset(path, 0, ARRAY_SIZE(path));
  12949. // Wait retrieveData
  12950. if(strlen(retrieveDatestr) > 10)
  12951. {
  12952. do
  12953. {
  12954. sleep(1);
  12955. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12956. }
  12957. // Ready to download
  12958. system("rm -f /mnt/*");
  12959. if(strncmp(locationstr,"http", 4) == 0)
  12960. {
  12961. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12962. sprintf(ftppath,"/%s", path);
  12963. DEBUG_INFO("locationstr: %s\n", locationstr);
  12964. DEBUG_INFO("protocol: %s\n",protocol);
  12965. DEBUG_INFO("host: %s\n",host);
  12966. DEBUG_INFO("path: %s\n",path);
  12967. DEBUG_INFO("ftppath: %s\n",ftppath);
  12968. int ftppathlen=strlen(ftppath);
  12969. int i=1;
  12970. char filenametemp[50];
  12971. while(i < ftppathlen)
  12972. {
  12973. int len=ftppathlen-i;
  12974. if(ftppath[len]== 47) // '/' ascll code: 47
  12975. {
  12976. DEBUG_INFO("compare '/' all right\n");
  12977. break;
  12978. }
  12979. i=i+1;
  12980. }
  12981. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12982. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12983. filenametemp[i+1] = 0;
  12984. do
  12985. {
  12986. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12987. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12988. sleep(1);
  12989. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12990. if(!isSuccess)
  12991. {
  12992. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12993. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12994. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12995. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12996. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12997. }
  12998. else
  12999. {
  13000. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13001. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13002. }
  13003. retriesInt--;
  13004. }while((isSuccess == 0)&&(retriesInt >= 0));
  13005. }
  13006. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13007. {
  13008. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13009. memset(temp, 0, ARRAY_SIZE(temp));
  13010. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13011. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13012. int ftppathlen=strlen(ftpbuf);
  13013. int i=1;
  13014. char filenametemp[50];
  13015. while(i < ftppathlen)
  13016. {
  13017. int len=ftppathlen-i;
  13018. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13019. {
  13020. DEBUG_INFO(" compare '/' all right\n");
  13021. break;
  13022. }
  13023. i=i+1;
  13024. }
  13025. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13026. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13027. filenametemp[i+1] = 0;
  13028. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13029. pch=strchr(temp,'@');
  13030. if(pch==NULL)
  13031. {
  13032. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13033. protocol, host, &port, path);
  13034. strcpy(user,"anonymous");
  13035. strcpy(password,"");
  13036. }
  13037. else
  13038. {
  13039. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13040. protocol, user, password, host, &port, path);
  13041. }
  13042. sscanf(host,"%[^/]%s",host1, path1);
  13043. sprintf(ftppath,"%s", path1);
  13044. //DEBUG_INFO("protocol =%s\n",protocol);
  13045. //DEBUG_INFO("user =%s\n",user);
  13046. //DEBUG_INFO("password =%s\n",password);
  13047. //DEBUG_INFO("host1 =%s\n",host1);
  13048. //DEBUG_INFO("port =%d\n",port);
  13049. //DEBUG_INFO("path1 =%s\n",path1);
  13050. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13051. //ftpFile(host, user, password, port, ftppath, fname);
  13052. //download firmware pthred
  13053. if(port == 0)
  13054. {
  13055. port = 21;
  13056. }
  13057. do
  13058. {
  13059. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13060. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13061. sleep(1);
  13062. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13063. if(!isSuccess)
  13064. {
  13065. //BulldogUtil.sleepMs(interval*1000);
  13066. DEBUG_INFO("Update firmware request and download file fail.\n");
  13067. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13068. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13069. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13070. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13071. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13072. }
  13073. else
  13074. {
  13075. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13076. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13077. }
  13078. retriesInt--;
  13079. }while((!isSuccess)&&(retriesInt >= 0));
  13080. }
  13081. else
  13082. {
  13083. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13084. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13085. sleep(1);
  13086. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13087. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13088. }
  13089. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13090. interLock.isUpdateFirmwareGoing = 0;
  13091. pthread_exit(NULL);
  13092. }
  13093. int handleCertificateSignedRequest(char *uuid, char *payload)
  13094. {
  13095. mtrace();
  13096. int result = PASS;
  13097. json_object *CertificateSigned;
  13098. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13099. CertificateSigned = json_tokener_parse(payload);
  13100. if(!is_error(CertificateSigned))
  13101. {
  13102. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13103. }
  13104. json_object_put(CertificateSigned);
  13105. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  13106. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13107. fclose(fp);
  13108. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13109. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13110. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13111. sendCertificateSignedConfirmation(uuid);
  13112. return result;
  13113. }
  13114. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13115. {
  13116. mtrace();
  13117. int result = PASS;
  13118. json_object *DeleteCertificate;
  13119. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13120. DeleteCertificate = json_tokener_parse(payload);
  13121. if(!is_error(DeleteCertificate))
  13122. {
  13123. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13124. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13125. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13126. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13127. }
  13128. json_object_put(DeleteCertificate);
  13129. /*
  13130. * TODO: Delete certificateSigned process
  13131. */
  13132. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  13133. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13134. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  13135. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  13136. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  13137. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  13138. sendDeleteCertificateConfirmation(uuid);
  13139. return result;
  13140. }
  13141. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13142. {
  13143. mtrace();
  13144. int result = PASS;
  13145. json_object *ExtendedTriggerMessage;
  13146. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13147. ExtendedTriggerMessage = json_tokener_parse(payload);
  13148. if(!is_error(ExtendedTriggerMessage))
  13149. {
  13150. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13151. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13152. {
  13153. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13154. }
  13155. else
  13156. {
  13157. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  13158. }
  13159. }
  13160. json_object_put(ExtendedTriggerMessage);
  13161. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  13162. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  13163. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13164. {
  13165. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13166. }
  13167. else
  13168. {
  13169. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13170. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13171. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13172. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13173. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13174. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13175. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13176. {
  13177. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13178. }
  13179. else
  13180. {
  13181. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13182. }
  13183. }
  13184. sendExtendedTriggerMessageConfirmation(uuid);
  13185. //==========================
  13186. // Trigger message
  13187. //==========================
  13188. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13189. {
  13190. //sendBootNotificationRequest();
  13191. server_sign = FALSE;
  13192. }
  13193. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13194. {
  13195. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13196. }
  13197. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13198. {
  13199. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13200. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13201. {
  13202. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13203. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13204. }
  13205. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13206. }
  13207. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13208. {
  13209. refreshStartTimer(&clientTime.Heartbeat);
  13210. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13211. }
  13212. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13213. {
  13214. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13215. {
  13216. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13217. }
  13218. else
  13219. {
  13220. for(int idx=0;idx< gunTotalNumber;idx++)
  13221. {
  13222. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13223. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13224. }
  13225. }
  13226. }
  13227. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13228. {
  13229. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  13230. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13231. {
  13232. 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\" &");
  13233. }
  13234. }
  13235. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13236. {
  13237. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13238. {
  13239. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13240. }
  13241. else
  13242. {
  13243. for(int idx=0;idx< gunTotalNumber;idx++)
  13244. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13245. }
  13246. }
  13247. return result;
  13248. }
  13249. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13250. {
  13251. mtrace();
  13252. int result = PASS;
  13253. json_object *GetInstalledCertificateIds;
  13254. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13255. GetInstalledCertificateIds = json_tokener_parse(payload);
  13256. if(!is_error(GetInstalledCertificateIds))
  13257. {
  13258. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13259. }
  13260. json_object_put(GetInstalledCertificateIds);
  13261. /*
  13262. * TODO: Return installed certificate process
  13263. */
  13264. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13265. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  13266. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13267. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13268. sendGetInstalledCertificateIdsConfirmation(uuid);
  13269. return result;
  13270. }
  13271. int handleGetLogRequest(char *uuid, char *payload)
  13272. {
  13273. mtrace();
  13274. int result = PASS;
  13275. json_object *GetLog;
  13276. DEBUG_INFO("handleGetLogRequest...\n");
  13277. GetLog = json_tokener_parse(payload);
  13278. if(!is_error(GetLog))
  13279. {
  13280. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13281. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13282. if(json_object_object_get(GetLog, "retries") != NULL)
  13283. {
  13284. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13285. }
  13286. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13287. {
  13288. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13289. }
  13290. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13291. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13292. {
  13293. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13294. }
  13295. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13296. {
  13297. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13298. }
  13299. }
  13300. json_object_put(GetLog);
  13301. /*
  13302. * TODO: Upload log process
  13303. */
  13304. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  13305. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  13306. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  13307. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  13308. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  13309. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  13310. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  13311. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  13312. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  13313. sendGetLogConfirmation(uuid);
  13314. return result;
  13315. }
  13316. int handleInstallCertificateRequest(char *uuid, char *payload)
  13317. {
  13318. mtrace();
  13319. int result = PASS;
  13320. json_object *InstallCertificate;
  13321. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13322. InstallCertificate = json_tokener_parse(payload);
  13323. if(!is_error(InstallCertificate))
  13324. {
  13325. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13326. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13327. /*
  13328. * TODO: Install certificate process
  13329. */
  13330. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  13331. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  13332. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  13333. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  13334. sendInstallCertificateConfirmation(uuid);
  13335. }
  13336. json_object_put(InstallCertificate);
  13337. return result;
  13338. }
  13339. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13340. {
  13341. mtrace();
  13342. int result = PASS;
  13343. json_object *SignedUpdateFirmware;
  13344. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13345. SignedUpdateFirmware = json_tokener_parse(payload);
  13346. if(!is_error(SignedUpdateFirmware))
  13347. {
  13348. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13349. {
  13350. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13351. }
  13352. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13353. {
  13354. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13355. }
  13356. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13357. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13358. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13359. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13360. {
  13361. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13362. }
  13363. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13364. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13365. }
  13366. json_object_put(SignedUpdateFirmware);
  13367. /*
  13368. * TODO: Upgrade firmware process
  13369. */
  13370. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13371. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  13372. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  13373. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  13374. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  13375. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  13376. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  13377. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  13378. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  13379. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  13380. sendInstallCertificateConfirmation(uuid);
  13381. return result;
  13382. }
  13383. int handleUnknownRequest(char *uuid, char *payload)
  13384. {
  13385. mtrace();
  13386. int result = PASS;
  13387. DEBUG_INFO("handleUnknownRequest...\n");
  13388. sendUnknownConfirmation(uuid);
  13389. result = PASS;
  13390. return result;
  13391. }
  13392. //==========================================
  13393. // Handle server response routine
  13394. //==========================================
  13395. void handleAuthorizeResponse(char *payload, int gun_index)
  13396. {
  13397. mtrace();
  13398. char expiryDatestr[30]={0};
  13399. char parentIdTagstr[20]={0};
  13400. char statusstr[20]={0};
  13401. int expiryDateISNULL=FALSE;
  13402. int parentIdTagISNULL=FALSE;
  13403. DEBUG_INFO("handleAuthorizeResponse...\n");
  13404. json_object *Authorize;
  13405. Authorize = json_tokener_parse(payload);
  13406. if(!is_error(Authorize))
  13407. {
  13408. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13409. {
  13410. // Required data
  13411. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13412. // Optional data
  13413. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13414. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13415. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13416. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13417. }
  13418. }
  13419. json_object_put(Authorize);
  13420. if(expiryDateISNULL == FALSE)
  13421. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13422. if(parentIdTagISNULL == FALSE)
  13423. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13424. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  13425. //Update idTag information to authorization cache if supproted
  13426. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13427. {
  13428. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13429. }
  13430. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  13431. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13432. authorizeRetryTimes = 0;
  13433. }
  13434. void handleBootNotificationResponse(char *payload, int gun_index)
  13435. {
  13436. mtrace();
  13437. char statusStr[12]={0};
  13438. char currentTimeStr[30]={0};
  13439. int intervalInt = 0;
  13440. DEBUG_INFO("handleBootNotificationResponse...\n");
  13441. json_object *BootNotification;
  13442. BootNotification = json_tokener_parse(payload);
  13443. if(!is_error(BootNotification))
  13444. {
  13445. // Required data
  13446. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13447. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13448. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13449. }
  13450. json_object_put(BootNotification);
  13451. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13452. BootNotificationInterval = intervalInt;
  13453. //write back to ShmOCPP16Data->BootNotification
  13454. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  13455. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13456. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  13457. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13458. {
  13459. BootNotificationInterval = 0;
  13460. if((intervalInt == 0) || (intervalInt >= 10))
  13461. {
  13462. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13463. HeartBeatWaitTime = intervalInt;
  13464. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13465. }
  13466. server_sign = TRUE;
  13467. server_pending =FALSE;
  13468. }
  13469. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13470. {
  13471. server_pending = TRUE;
  13472. }
  13473. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  13474. srand(time(NULL));
  13475. refreshStartTimer(&clientTime.Heartbeat);
  13476. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13477. SetOcppConnStatus(TRUE);
  13478. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  13479. }
  13480. void handleDataTransferResponse(char *payload, int gun_index)
  13481. {
  13482. json_object *DataTransfer = json_tokener_parse(payload);
  13483. if(!is_error(DataTransfer))
  13484. {
  13485. // Required data
  13486. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13487. // Optional data
  13488. if(json_object_object_get(DataTransfer, "data") != NULL)
  13489. {
  13490. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13491. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13492. if(!is_error(Data))
  13493. {
  13494. if(json_object_object_get(Data, "msgId") != NULL)
  13495. {
  13496. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13497. {
  13498. OCPP_update_deduct_info(json_object_get_int(json_object_object_get(Data, "txId")), (char*)json_object_get_string(json_object_object_get(Data, "creditNo")));
  13499. }
  13500. }
  13501. }
  13502. json_object_put(Data);
  13503. }
  13504. }
  13505. json_object_put(DataTransfer);
  13506. }
  13507. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13508. {
  13509. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13510. //struct json_object *obj;
  13511. // obj = json_tokener_parse(payload);
  13512. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13513. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13514. //No fields are defined.
  13515. }
  13516. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13517. {
  13518. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13519. //struct json_object *obj;
  13520. // obj = json_tokener_parse(payload);
  13521. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13522. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13523. //No fields are defined.
  13524. }
  13525. void handleHeartbeatResponse(char *payload, int gun_index)
  13526. {
  13527. mtrace();
  13528. DEBUG_INFO("handleHeartbeatResponse...\n");
  13529. json_object *Heartbeat;
  13530. Heartbeat = json_tokener_parse(payload);
  13531. if(!is_error(Heartbeat))
  13532. {
  13533. // Required data
  13534. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13535. }
  13536. json_object_put(Heartbeat);
  13537. if(FirstHeartBeat == 0)
  13538. {
  13539. FirstHeartBeat = 1;
  13540. DEBUG_INFO("FirstHeartBeat \n");
  13541. }
  13542. HeartBeatWithNOResponse = 0;
  13543. refreshStartTimer(&clientTime.Heartbeat);
  13544. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  13545. }
  13546. void handleMeterValuesResponse(char *payload, int gun_index)
  13547. {
  13548. mtrace();
  13549. DEBUG_INFO("handleMeterValuesResponse...\n");
  13550. isQueueSendable = 1;
  13551. }
  13552. void handleStartTransactionResponse(char *payload, int gun_index)
  13553. {
  13554. mtrace();
  13555. //int transactionIdInt = 0;
  13556. FILE *outfile;
  13557. char data[100]={0};
  13558. DEBUG_INFO("handleStartTransactionResponse...\n");
  13559. json_object *StartTransaction;
  13560. StartTransaction = json_tokener_parse(payload);
  13561. if(!is_error(StartTransaction))
  13562. {
  13563. // Required data
  13564. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13565. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13566. // Optional data
  13567. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13568. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13569. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13570. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13571. }
  13572. json_object_put(StartTransaction);
  13573. isQueueSendable = 1;
  13574. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13575. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13576. //-----------Start : write to the Queue TransactionId file -----------------//
  13577. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  13578. {}
  13579. else
  13580. {
  13581. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  13582. if(log == NULL)
  13583. {
  13584. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13585. return ;
  13586. }
  13587. else
  13588. {
  13589. fclose(log);
  13590. }
  13591. }
  13592. // open file for writing
  13593. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13594. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  13595. {
  13596. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  13597. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13598. fputs(data, outfile);
  13599. fclose (outfile);
  13600. }
  13601. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13602. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13603. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13604. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  13605. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13606. }
  13607. void handleStatusNotificationResponse(char *payload, int gun_index)
  13608. {
  13609. mtrace();
  13610. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13611. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13612. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13613. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13614. }
  13615. void handleStopTransactionnResponse(char *payload, int gun_index)
  13616. {
  13617. mtrace();
  13618. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13619. json_object *StopTransaction;
  13620. StopTransaction = json_tokener_parse(payload);
  13621. if(!is_error(StopTransaction))
  13622. {
  13623. // Optional data
  13624. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13625. {
  13626. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13627. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13628. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13629. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13630. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13631. }
  13632. }
  13633. json_object_put(StopTransaction);
  13634. isQueueSendable = 1;
  13635. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13636. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13637. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13638. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13639. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13640. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13641. }
  13642. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13643. {
  13644. mtrace();
  13645. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13646. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  13647. }
  13648. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13649. {
  13650. mtrace();
  13651. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13652. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  13653. }
  13654. void handleSignCertificateResponse(char *payload, int gun_index)
  13655. {
  13656. mtrace();
  13657. DEBUG_INFO("handleSignCertificateResponse...\n");
  13658. json_object *SignCertificate;
  13659. SignCertificate = json_tokener_parse(payload);
  13660. if(!is_error(SignCertificate))
  13661. {
  13662. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13663. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  13664. }
  13665. json_object_put(SignCertificate);
  13666. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  13667. }
  13668. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13669. {
  13670. mtrace();
  13671. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13672. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13673. }
  13674. //==========================================
  13675. // Handle Error routine
  13676. //==========================================
  13677. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13678. {
  13679. mtrace();
  13680. #ifdef SystemLogMessage
  13681. DEBUG_INFO("errorCode: %s\n", errorCode);
  13682. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13683. DEBUG_INFO("errorDetails: %s\n", payload);
  13684. #endif
  13685. }
  13686. //===============================================
  13687. // Common routine
  13688. //===============================================
  13689. int initialConfigurationTable(void)
  13690. {
  13691. //clock_t start_t, end_t, total_t;
  13692. FILE *fp;
  13693. FILE *outfile;
  13694. char str[512]={0};
  13695. char sstr[256]={0};
  13696. int c = 0;
  13697. char *loc;
  13698. int confVersion = 13;
  13699. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13700. //start_t = clock();
  13701. //printf("Starting of the program, start_t = %ld\n", start_t);
  13702. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13703. // Check configuration file size is correct
  13704. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  13705. {
  13706. struct stat st;
  13707. stat("/Storage/OCPP/OCPPConfiguration", &st);
  13708. if(st.st_size < 3100)
  13709. {
  13710. system("rm -f /Storage/OCPP/OCPPConfiguration");
  13711. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13712. }
  13713. }
  13714. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  13715. {
  13716. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13717. if(outfile == NULL)
  13718. {
  13719. DEBUG_INFO("Error opening file\n");
  13720. return FALSE;
  13721. }
  13722. /*Core Profile*/
  13723. //AllowOfflineTxForUnknownId
  13724. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13726. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13727. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13728. //AuthorizationCacheEnabled
  13729. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13732. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13733. //AuthorizeRemoteTxRequests
  13734. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13737. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13738. //BlinkRepeat
  13739. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13742. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13743. //ClockAlignedDataInterval
  13744. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13747. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13748. //ConnectionTimeOut
  13749. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13752. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13753. //GetConfigurationMaxKeys
  13754. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13756. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13757. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13758. // HeartbeatInterval
  13759. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13762. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13763. // LightIntensity
  13764. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13767. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13768. // LocalAuthorizeOffline
  13769. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13772. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13773. // LocalPreAuthorize
  13774. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13776. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13778. // MaxEnergyOnInvalidId
  13779. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13782. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13783. // MeterValuesAlignedData
  13784. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13786. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13787. 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" );
  13788. else
  13789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13790. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13791. // MeterValuesAlignedDataMaxLength
  13792. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13794. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13796. else
  13797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13799. // MeterValuesSampledData
  13800. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13802. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13803. 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" );
  13804. else
  13805. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13806. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13807. // MeterValuesSampledDataMaxLength
  13808. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13810. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13812. else
  13813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13814. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13815. // MeterValueSampleInterval
  13816. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13820. // MinimumStatusDuration
  13821. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13824. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13826. // NumberOfConnectors
  13827. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13829. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13830. {
  13831. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13832. }
  13833. else
  13834. {
  13835. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13836. }
  13837. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13838. // ResetRetries
  13839. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13840. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13842. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13843. // ConnectorPhaseRotation
  13844. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13847. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13848. // ConnectorPhaseRotationMaxLength
  13849. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13852. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13853. // StopTransactionOnEVSideDisconnect
  13854. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13857. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13858. // StopTransactionOnInvalidId
  13859. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13863. // StopTxnAlignedData
  13864. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13867. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13868. // StopTxnAlignedDataMaxLength
  13869. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13872. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13873. // StopTxnSampledData
  13874. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13875. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13876. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13878. else
  13879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13880. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13881. // StopTxnSampledDataMaxLength
  13882. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13884. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13885. {
  13886. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13887. }
  13888. else
  13889. {
  13890. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13891. }
  13892. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13893. // SupportedFeatureProfiles
  13894. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13896. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13897. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13898. // SupportedFeatureProfilesMaxLength
  13899. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13902. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13903. // TransactionMessageAttempts
  13904. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13905. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13907. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13908. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13909. // TransactionMessageRetryInterval
  13910. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13912. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13913. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13914. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13915. // UnlockConnectorOnEVSideDisconnect
  13916. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13918. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13919. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13920. // WebSocketPingInterval
  13921. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13924. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13925. // QueueOffLineMeterValues
  13926. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13928. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13929. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13930. // AuthorizationKey
  13931. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13932. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13933. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  13934. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13935. // SecurityProfile
  13936. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13938. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  13939. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13940. // DefaultPrice
  13941. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13944. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13945. // CustomDisplayCostAndPrice
  13946. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13947. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13948. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13949. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13950. // CustomIdleFeeAfterStop
  13951. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13952. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13953. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13954. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13955. // TimeOffset
  13956. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  13959. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13960. // NextTimeOffsetTransitionDateTime
  13961. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  13964. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13965. // TimeOffsetNextTransition
  13966. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13967. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13968. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  13969. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13970. // SystemUptimeSec
  13971. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13974. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13975. // FreeVend
  13976. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13979. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13980. // FreeVendIdtag
  13981. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  13982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  13983. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  13984. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  13985. // OcppServer
  13986. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13987. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13988. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13989. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13990. // MaintainServer
  13991. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13993. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13994. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13995. // StatusNotificationPeriodically
  13996. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13997. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13999. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14000. // StatusNotificationInterval
  14001. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14002. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14003. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14004. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14005. // Configuration Version
  14006. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  14007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14008. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  14009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14010. //* Local Auth List Management Profile*/
  14011. #if 0
  14012. //For OCTT Test Case
  14013. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  14015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14016. #endif
  14017. #if 1
  14018. //LocalAuthListEnabled
  14019. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14022. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14023. #endif
  14024. //LocalAuthListMaxLength
  14025. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  14028. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14029. //SendLocalListMaxLength
  14030. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14031. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14032. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14033. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14034. //ReserveConnectorZeroSupported
  14035. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14037. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14038. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14039. //* Smart Charging Profile */
  14040. //ChargeProfileMaxStackLevel
  14041. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14044. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14045. // ChargingScheduleAllowedChargingRateUnit
  14046. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  14049. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14050. // ChargingScheduleMaxPeriods
  14051. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14054. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14055. // ConnectorSwitch3to1PhaseSupported
  14056. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14059. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14060. // MaxChargingProfilesInstalled
  14061. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14065. fclose(outfile);
  14066. }
  14067. else
  14068. {
  14069. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  14070. char keystr[60]={0};
  14071. char readonlystr[10]={0};
  14072. char valuestr[256]={0};
  14073. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  14074. if(fp == NULL) {
  14075. DEBUG_INFO("Error opening file");
  14076. return FALSE;
  14077. }
  14078. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14079. {
  14080. //DEBUG_INFO("Get Configuration \n");
  14081. if(strlen(str) > 0)
  14082. {
  14083. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14084. //*************************key*********************************/
  14085. if(strstr(str, "key") != NULL)
  14086. {
  14087. loc = strstr(str, "key");
  14088. c = 0;
  14089. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14090. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14091. {
  14092. sstr[c] = loc[strlen("key")+3+c];
  14093. c++;
  14094. }
  14095. sstr[c] = '\0';
  14096. strcpy(keystr,sstr);
  14097. }
  14098. //*************************readonly*********************************/
  14099. if(strstr(str, "readonly") != NULL)
  14100. {
  14101. loc = strstr(str, "readonly");
  14102. c = 0;
  14103. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14104. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14105. {
  14106. sstr[c] = loc[strlen("readonly")+2+c];
  14107. c++;
  14108. }
  14109. sstr[c] = '\0';
  14110. strcpy(readonlystr,sstr);
  14111. }
  14112. //*************************value*********************************/
  14113. if(strstr(str, "value") != NULL)
  14114. {
  14115. loc = strstr(str, "value");
  14116. c = 0;
  14117. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14118. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14119. {
  14120. sstr[c] = loc[strlen("value")+3+c];
  14121. c++;
  14122. }
  14123. sstr[c] = '\0';
  14124. strcpy(valuestr,sstr);
  14125. }
  14126. // DEBUG_INFO("keystr=%s\n",keystr);
  14127. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14128. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14129. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14130. {
  14131. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14132. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14133. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14134. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14135. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14136. }
  14137. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14138. {
  14139. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14140. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14141. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14142. }
  14143. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14144. {
  14145. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14146. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14147. }
  14148. if(strcmp(keystr, "BlinkRepeat") == 0)
  14149. {
  14150. //Charger.BlinkRepeat = Integer.parseInt(value);
  14151. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14152. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14153. }
  14154. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14155. {
  14156. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14157. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14158. }
  14159. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14160. {
  14161. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14162. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14163. }
  14164. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14165. {
  14166. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14167. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14168. }
  14169. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14170. {
  14171. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14172. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14173. HeartBeatWaitTime = atoi(valuestr);
  14174. }
  14175. if(strcmp(keystr, "LightIntensity") == 0)
  14176. {
  14177. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14178. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14179. }
  14180. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14181. {
  14182. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14183. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14184. }
  14185. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14186. {
  14187. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14188. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14189. }
  14190. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14191. {
  14192. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14193. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14194. }
  14195. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14196. {
  14197. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14199. }
  14200. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14201. {
  14202. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14204. }
  14205. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14206. {
  14207. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14208. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14209. }
  14210. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14211. {
  14212. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14213. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14214. }
  14215. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14216. {
  14217. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14218. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14219. }
  14220. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14221. {
  14222. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14223. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14224. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14225. }
  14226. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14227. {
  14228. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14229. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14230. }
  14231. if(strcmp(keystr, "ResetRetries") == 0)
  14232. {
  14233. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14234. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14235. }
  14236. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14237. {
  14238. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14239. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14240. }
  14241. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14242. {
  14243. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14244. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14245. }
  14246. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14247. {
  14248. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14249. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14250. }
  14251. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14252. {
  14253. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14254. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14255. }
  14256. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14257. {
  14258. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14259. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14260. }
  14261. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14262. {
  14263. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14264. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14265. }
  14266. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14267. {
  14268. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14269. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14270. }
  14271. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14272. {
  14273. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14274. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14275. }
  14276. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14277. {
  14278. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14279. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14280. }
  14281. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14282. {
  14283. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14284. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14285. }
  14286. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14287. {
  14288. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14289. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14290. TransactionMessageAttemptsValue = atoi(valuestr);
  14291. }
  14292. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14293. {
  14294. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14295. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14296. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14297. }
  14298. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14299. {
  14300. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14301. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14302. }
  14303. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14304. {
  14305. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14306. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14307. }
  14308. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14309. {
  14310. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14311. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14312. }
  14313. if(strcmp(keystr, "AuthorizationKey") == 0)
  14314. {
  14315. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14316. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14317. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14318. }
  14319. if(strcmp(keystr, "SecurityProfile") == 0)
  14320. {
  14321. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14322. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14323. }
  14324. if(strcmp(keystr, "DefaultPrice") == 0)
  14325. {
  14326. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14327. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14328. }
  14329. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14330. {
  14331. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14332. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14333. }
  14334. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14335. {
  14336. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14337. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14338. }
  14339. if(strcmp(keystr, "TimeOffset") == 0)
  14340. {
  14341. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14342. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  14343. }
  14344. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  14345. {
  14346. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14347. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  14348. }
  14349. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  14350. {
  14351. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14352. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  14353. }
  14354. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14355. {
  14356. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14357. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  14358. }
  14359. if(strcmp(keystr, "FreeVend") == 0)
  14360. {
  14361. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14362. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14363. }
  14364. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14365. {
  14366. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14367. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14368. }
  14369. if(strcmp(keystr, "OcppServer") == 0)
  14370. {
  14371. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14372. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14373. }
  14374. if(strcmp(keystr, "MaintainServer") == 0)
  14375. {
  14376. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14377. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14378. }
  14379. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14380. {
  14381. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14382. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14383. }
  14384. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14385. {
  14386. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14387. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14388. }
  14389. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14390. {
  14391. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14392. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14393. }
  14394. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14395. {
  14396. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14397. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14398. }
  14399. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14400. {
  14401. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14402. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14403. }
  14404. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14405. {
  14406. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14407. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14408. }
  14409. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14410. {
  14411. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14412. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14413. }
  14414. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14415. {
  14416. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14417. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14418. }
  14419. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14420. {
  14421. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14422. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14423. }
  14424. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14425. {
  14426. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14427. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14428. }
  14429. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14430. {
  14431. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14432. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14433. }
  14434. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14435. {
  14436. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14437. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14438. }
  14439. }
  14440. }
  14441. fclose(fp);
  14442. }
  14443. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14444. {
  14445. return PASS;
  14446. }
  14447. else
  14448. {
  14449. return FAIL;
  14450. }
  14451. }
  14452. void StoreConfigurationTable(void)
  14453. {
  14454. FILE *outfile;
  14455. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14456. if(outfile == NULL)
  14457. {
  14458. DEBUG_INFO("Error opening file");
  14459. return ;
  14460. }
  14461. /*Core Profile*/
  14462. //AllowOfflineTxForUnknownId
  14463. /*
  14464. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14465. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14466. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14467. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14468. */
  14469. //DEBUG_INFO("data=%s\n",data);
  14470. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14471. //AuthorizationCacheEnabled
  14472. /*
  14473. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14474. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14475. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14476. */
  14477. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14478. //AuthorizeRemoteTxRequests
  14479. /*
  14480. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14481. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14483. */
  14484. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14485. //BlinkRepeat
  14486. /*
  14487. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14488. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14489. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14490. */
  14491. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14492. //ClockAlignedDataInterval
  14493. /*
  14494. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14495. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14497. */
  14498. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14499. //ConnectionTimeOut
  14500. /*
  14501. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14504. */
  14505. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14506. //GetConfigurationMaxKeys
  14507. /*
  14508. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14511. */
  14512. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14513. // HeartbeatInterval
  14514. /*
  14515. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14516. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14518. */
  14519. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14520. // LightIntensity
  14521. /*
  14522. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14523. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14524. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14525. */
  14526. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14527. // LocalAuthorizeOffline
  14528. /*
  14529. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14530. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14532. */
  14533. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14534. // LocalPreAuthorize
  14535. /*
  14536. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14537. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14538. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14539. */
  14540. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14541. // MaxEnergyOnInvalidId
  14542. /*
  14543. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14544. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14545. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14546. */
  14547. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14548. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14549. // MeterValuesAlignedData
  14550. /*
  14551. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14554. */
  14555. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14556. // MeterValuesAlignedDataMaxLength
  14557. /*
  14558. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14561. */
  14562. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14563. // MeterValuesSampledData
  14564. /*
  14565. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14568. */
  14569. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14570. // MeterValuesSampledDataMaxLength
  14571. /*
  14572. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14575. */
  14576. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14577. // MeterValueSampleInterval
  14578. /*
  14579. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14580. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14582. */
  14583. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14584. // MinimumStatusDuration
  14585. /*
  14586. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14589. */
  14590. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14591. // NumberOfConnectors
  14592. /*
  14593. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14595. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14596. {
  14597. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14598. }
  14599. else
  14600. {
  14601. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14602. }
  14603. */
  14604. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14605. // ResetRetries
  14606. /*
  14607. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14608. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14610. */
  14611. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14612. // ConnectorPhaseRotation
  14613. /*
  14614. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14617. */
  14618. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14619. // ConnectorPhaseRotationMaxLength
  14620. /*
  14621. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14624. */
  14625. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14626. // StopTransactionOnEVSideDisconnect
  14627. /*
  14628. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14629. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14631. */
  14632. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14633. // StopTransactionOnInvalidId
  14634. /*
  14635. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14638. */
  14639. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14640. // StopTxnAlignedData
  14641. /*
  14642. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14645. */
  14646. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14647. // StopTxnAlignedDataMaxLength
  14648. /*
  14649. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14652. */
  14653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14654. // StopTxnSampledData
  14655. /*
  14656. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14659. */
  14660. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14661. // StopTxnSampledDataMaxLength
  14662. /*
  14663. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14664. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14666. */
  14667. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14668. // SupportedFeatureProfiles
  14669. /*
  14670. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14673. */
  14674. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14675. // SupportedFeatureProfilesMaxLength
  14676. /*
  14677. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14680. */
  14681. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14682. // TransactionMessageAttempts
  14683. /*
  14684. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14687. */
  14688. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14689. // TransactionMessageRetryInterval
  14690. /*
  14691. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14693. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14694. */
  14695. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14696. // UnlockConnectorOnEVSideDisconnect
  14697. /*
  14698. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14699. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14701. */
  14702. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14703. // WebSocketPingInterval
  14704. /*
  14705. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14708. */
  14709. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14710. // QueueOffLineMeterValues
  14711. /*
  14712. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14715. */
  14716. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14717. // AuthorizationKey
  14718. /*
  14719. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14720. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14721. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14722. */
  14723. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14724. // SecurityProfile
  14725. /*
  14726. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14727. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14728. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14729. */
  14730. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14731. // DefaultPrice
  14732. /*
  14733. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14736. */
  14737. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14738. // CustomDisplayCostAndPrice
  14739. /*
  14740. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14742. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14743. */
  14744. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14745. // CustomIdleFeeAfterStop
  14746. /*
  14747. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14750. */
  14751. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14752. // TimeOffset
  14753. /*
  14754. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  14757. */
  14758. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14759. // NextTimeOffsetTransitionDateTime
  14760. /*
  14761. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14762. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  14764. */
  14765. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14766. // TimeOffsetNextTransition
  14767. /*
  14768. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  14771. */
  14772. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14773. // SystemUptimeSec
  14774. /*
  14775. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14776. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14778. */
  14779. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14780. // FreeVend
  14781. /*
  14782. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14785. */
  14786. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14787. // FreeVendIdtag
  14788. /*
  14789. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14791. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14792. */
  14793. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14794. // OcppServer
  14795. /*
  14796. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14799. */
  14800. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14801. // MaintainServer
  14802. /*
  14803. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14805. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14806. */
  14807. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14808. // StatusNotificationPeriodically
  14809. /*
  14810. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14813. */
  14814. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14815. // StatusNotificationInterval
  14816. /*
  14817. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14820. */
  14821. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14822. // ConfigurationVersion
  14823. /*
  14824. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14826. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14827. */
  14828. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14829. //* Local Auth List Management Profile*/
  14830. //LocalAuthListEnabled
  14831. /*
  14832. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14835. */
  14836. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14837. //LocalAuthListMaxLength
  14838. /*
  14839. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14840. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14842. */
  14843. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14844. //SendLocalListMaxLength
  14845. /*
  14846. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14847. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14849. */
  14850. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14851. //ReserveConnectorZeroSupported
  14852. /*
  14853. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14856. */
  14857. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14858. //* Smart Charging Profile */
  14859. //ChargeProfileMaxStackLevel
  14860. /*
  14861. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14864. */
  14865. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14866. // ChargingScheduleAllowedChargingRateUnit
  14867. /*
  14868. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14871. */
  14872. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14873. // ChargingScheduleMaxPeriods
  14874. /*
  14875. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14878. */
  14879. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14880. // ConnectorSwitch3to1PhaseSupported
  14881. /*
  14882. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14884. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14885. */
  14886. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14887. // MaxChargingProfilesInstalled
  14888. /*
  14889. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14890. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14892. */
  14893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14894. fclose(outfile);
  14895. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14896. }
  14897. void getKeyValue(char *keyReq)
  14898. {
  14899. int isEmpty = FALSE;
  14900. int isKnowKey = FALSE;
  14901. DEBUG_INFO("keyReq = %s\n", keyReq);
  14902. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14903. isEmpty = TRUE;
  14904. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14905. {
  14906. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14907. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14908. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14909. {
  14910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14911. }
  14912. else
  14913. {
  14914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14915. }
  14916. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14917. isKnowKey = TRUE;
  14918. }
  14919. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14920. {
  14921. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14922. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14923. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14924. {
  14925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14926. }
  14927. else
  14928. {
  14929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14930. }
  14931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14932. isKnowKey = TRUE;
  14933. }
  14934. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14935. {
  14936. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14937. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14938. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14939. {
  14940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14941. }
  14942. else
  14943. {
  14944. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14945. }
  14946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14947. isKnowKey = TRUE;
  14948. }
  14949. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14950. {
  14951. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14952. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14953. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14954. {
  14955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14956. }
  14957. else
  14958. {
  14959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14960. }
  14961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14962. isKnowKey = TRUE;
  14963. }
  14964. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14965. {
  14966. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14967. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14968. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14969. {
  14970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14971. }
  14972. else
  14973. {
  14974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14975. }
  14976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14977. isKnowKey = TRUE;
  14978. }
  14979. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14980. {
  14981. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14982. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14983. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14984. {
  14985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14986. }
  14987. else
  14988. {
  14989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14990. }
  14991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14992. isKnowKey = TRUE;
  14993. }
  14994. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14995. {
  14996. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14998. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14999. {
  15000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  15001. }
  15002. else
  15003. {
  15004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  15005. }
  15006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  15007. isKnowKey = TRUE;
  15008. }
  15009. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  15010. {
  15011. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  15012. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  15013. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15014. {
  15015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  15016. }
  15017. else
  15018. {
  15019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15020. }
  15021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15022. isKnowKey = TRUE;
  15023. }
  15024. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15025. {
  15026. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15028. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15029. {
  15030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15031. }
  15032. else
  15033. {
  15034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15035. }
  15036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15037. isKnowKey = TRUE;
  15038. }
  15039. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15040. {
  15041. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15043. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15044. {
  15045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15046. }
  15047. else
  15048. {
  15049. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15050. }
  15051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15052. isKnowKey = TRUE;
  15053. }
  15054. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15055. {
  15056. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15058. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15059. {
  15060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15061. }
  15062. else
  15063. {
  15064. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15065. }
  15066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15067. isKnowKey = TRUE;
  15068. }
  15069. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15070. {
  15071. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15073. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15074. {
  15075. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15076. }
  15077. else
  15078. {
  15079. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15080. }
  15081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15082. isKnowKey = TRUE;
  15083. }
  15084. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15085. {
  15086. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15088. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15089. {
  15090. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15091. }
  15092. else
  15093. {
  15094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15095. }
  15096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15097. isKnowKey = TRUE;
  15098. }
  15099. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15100. {
  15101. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15103. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15104. {
  15105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15106. }
  15107. else
  15108. {
  15109. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15110. }
  15111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15112. isKnowKey = TRUE;
  15113. }
  15114. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15115. {
  15116. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15118. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15119. {
  15120. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15121. }
  15122. else
  15123. {
  15124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15125. }
  15126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15127. isKnowKey = TRUE;
  15128. }
  15129. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15130. {
  15131. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15133. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15134. {
  15135. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15136. }
  15137. else
  15138. {
  15139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15140. }
  15141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15142. isKnowKey = TRUE;
  15143. }
  15144. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15145. {
  15146. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15148. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15149. {
  15150. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15151. }
  15152. else
  15153. {
  15154. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15155. }
  15156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15157. isKnowKey = TRUE;
  15158. }
  15159. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15160. {
  15161. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15163. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15164. {
  15165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15166. }
  15167. else
  15168. {
  15169. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15170. }
  15171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  15172. isKnowKey = TRUE;
  15173. }
  15174. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15175. {
  15176. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15178. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15179. {
  15180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15181. }
  15182. else
  15183. {
  15184. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15185. }
  15186. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15188. isKnowKey = TRUE;
  15189. }
  15190. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15191. {
  15192. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15193. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15194. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15195. {
  15196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15197. }
  15198. else
  15199. {
  15200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15201. }
  15202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15203. isKnowKey = TRUE;
  15204. }
  15205. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15206. {
  15207. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15209. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15210. {
  15211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15212. }
  15213. else
  15214. {
  15215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15216. }
  15217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15218. isKnowKey = TRUE;
  15219. }
  15220. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15221. {
  15222. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15224. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15225. {
  15226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15227. }
  15228. else
  15229. {
  15230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15231. }
  15232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15233. isKnowKey = TRUE;
  15234. }
  15235. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15236. {
  15237. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15239. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15240. {
  15241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15242. }
  15243. else
  15244. {
  15245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15246. }
  15247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15248. isKnowKey = TRUE;
  15249. }
  15250. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15251. {
  15252. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15254. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15255. {
  15256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15257. }
  15258. else
  15259. {
  15260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15261. }
  15262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15263. isKnowKey = TRUE;
  15264. }
  15265. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15266. {
  15267. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15269. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15270. {
  15271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15272. }
  15273. else
  15274. {
  15275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15276. }
  15277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15278. isKnowKey = TRUE;
  15279. }
  15280. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15281. {
  15282. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15284. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15285. {
  15286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15287. }
  15288. else
  15289. {
  15290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15291. }
  15292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15293. isKnowKey = TRUE;
  15294. }
  15295. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15296. {
  15297. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15299. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15300. {
  15301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15302. }
  15303. else
  15304. {
  15305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15306. }
  15307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15308. isKnowKey = TRUE;
  15309. }
  15310. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15311. {
  15312. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15314. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15315. {
  15316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15317. }
  15318. else
  15319. {
  15320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15321. }
  15322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15323. isKnowKey = TRUE;
  15324. }
  15325. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15326. {
  15327. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15329. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15330. {
  15331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15332. }
  15333. else
  15334. {
  15335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15336. }
  15337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15338. isKnowKey = TRUE;
  15339. }
  15340. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15341. {
  15342. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15344. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15345. {
  15346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15347. }
  15348. else
  15349. {
  15350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15351. }
  15352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15353. isKnowKey = TRUE;
  15354. }
  15355. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15356. {
  15357. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15359. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15360. {
  15361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15362. }
  15363. else
  15364. {
  15365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15366. }
  15367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15368. isKnowKey = TRUE;
  15369. }
  15370. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15371. {
  15372. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15374. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15375. {
  15376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15377. }
  15378. else
  15379. {
  15380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15381. }
  15382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15383. isKnowKey = TRUE;
  15384. }
  15385. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15386. {
  15387. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15389. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15390. {
  15391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15392. }
  15393. else
  15394. {
  15395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15396. }
  15397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15398. isKnowKey = TRUE;
  15399. }
  15400. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15401. {
  15402. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15404. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15405. {
  15406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15407. }
  15408. else
  15409. {
  15410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15411. }
  15412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15413. isKnowKey = TRUE;
  15414. }
  15415. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15416. {
  15417. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15419. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15420. {
  15421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15422. }
  15423. else
  15424. {
  15425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15426. }
  15427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15428. isKnowKey = TRUE;
  15429. }
  15430. /*
  15431. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15432. {
  15433. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15435. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15436. {
  15437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15438. }
  15439. else
  15440. {
  15441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15442. }
  15443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15444. isKnowKey = TRUE;
  15445. }*/
  15446. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15447. {
  15448. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15450. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15451. {
  15452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15453. }
  15454. else
  15455. {
  15456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15457. }
  15458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15459. isKnowKey = TRUE;
  15460. }
  15461. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15462. {
  15463. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15465. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15466. {
  15467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15468. }
  15469. else
  15470. {
  15471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15472. }
  15473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15474. isKnowKey = TRUE;
  15475. }
  15476. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15477. {
  15478. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15480. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15481. {
  15482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15483. }
  15484. else
  15485. {
  15486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15487. }
  15488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15489. isKnowKey = TRUE;
  15490. }
  15491. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15492. {
  15493. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15495. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15496. {
  15497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15498. }
  15499. else
  15500. {
  15501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15502. }
  15503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15504. isKnowKey = TRUE;
  15505. }
  15506. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  15507. {
  15508. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  15509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  15510. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15511. {
  15512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  15513. }
  15514. else
  15515. {
  15516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  15517. }
  15518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  15519. isKnowKey = TRUE;
  15520. }
  15521. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  15522. {
  15523. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  15524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  15525. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15526. {
  15527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  15528. }
  15529. else
  15530. {
  15531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  15532. }
  15533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  15534. isKnowKey = TRUE;
  15535. }
  15536. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  15537. {
  15538. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  15539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  15540. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15541. {
  15542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  15543. }
  15544. else
  15545. {
  15546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  15547. }
  15548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  15549. isKnowKey = TRUE;
  15550. }
  15551. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15552. {
  15553. struct sysinfo s_info;
  15554. int error = sysinfo(&s_info);
  15555. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15557. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15558. {
  15559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15560. }
  15561. else
  15562. {
  15563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15564. }
  15565. if(error != 0)
  15566. {
  15567. DEBUG_WARN("System uptime get error: %d\n", error);
  15568. }
  15569. else
  15570. {
  15571. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15572. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15573. }
  15574. isKnowKey = TRUE;
  15575. }
  15576. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15577. {
  15578. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15580. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15581. {
  15582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15583. }
  15584. else
  15585. {
  15586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15587. }
  15588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  15589. isKnowKey = TRUE;
  15590. }
  15591. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15592. {
  15593. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15595. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15596. {
  15597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15598. }
  15599. else
  15600. {
  15601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15602. }
  15603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15604. isKnowKey = TRUE;
  15605. }
  15606. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15607. {
  15608. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15610. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15611. {
  15612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15613. }
  15614. else
  15615. {
  15616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15617. }
  15618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15619. isKnowKey = TRUE;
  15620. }
  15621. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15622. {
  15623. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15625. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15626. {
  15627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15628. }
  15629. else
  15630. {
  15631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15632. }
  15633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15634. isKnowKey = TRUE;
  15635. }
  15636. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15637. {
  15638. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15640. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15641. {
  15642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15643. }
  15644. else
  15645. {
  15646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15647. }
  15648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15649. isKnowKey = TRUE;
  15650. }
  15651. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15652. {
  15653. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15655. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15656. {
  15657. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15658. }
  15659. else
  15660. {
  15661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15662. }
  15663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15664. isKnowKey = TRUE;
  15665. }
  15666. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15667. {
  15668. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15670. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15671. {
  15672. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15673. }
  15674. else
  15675. {
  15676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15677. }
  15678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15679. isKnowKey = TRUE;
  15680. }
  15681. #if 1
  15682. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15683. {
  15684. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15686. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15687. {
  15688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15689. }
  15690. else
  15691. {
  15692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15693. }
  15694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15695. isKnowKey = TRUE;
  15696. }
  15697. #endif
  15698. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15699. {
  15700. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15702. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15703. {
  15704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15705. }
  15706. else
  15707. {
  15708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15709. }
  15710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15711. isKnowKey = TRUE;
  15712. }
  15713. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15714. {
  15715. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15717. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15718. {
  15719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15720. }
  15721. else
  15722. {
  15723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15724. }
  15725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15726. isKnowKey = TRUE;
  15727. }
  15728. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15729. {
  15730. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15732. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15733. {
  15734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15735. }
  15736. else
  15737. {
  15738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15739. }
  15740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15741. isKnowKey = TRUE;
  15742. }
  15743. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15744. {
  15745. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15747. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15748. {
  15749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15750. }
  15751. else
  15752. {
  15753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15754. }
  15755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15756. isKnowKey = TRUE;
  15757. }
  15758. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15759. {
  15760. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15762. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15763. {
  15764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15765. }
  15766. else
  15767. {
  15768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15769. }
  15770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15771. isKnowKey = TRUE;
  15772. }
  15773. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15774. {
  15775. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15776. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15777. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15778. {
  15779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15780. }
  15781. else
  15782. {
  15783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15784. }
  15785. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15786. isKnowKey = TRUE;
  15787. }
  15788. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15789. {
  15790. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15791. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15792. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15793. {
  15794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15795. }
  15796. else
  15797. {
  15798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15799. }
  15800. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15801. isKnowKey = TRUE;
  15802. }
  15803. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15804. {
  15805. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15807. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15808. {
  15809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15810. }
  15811. else
  15812. {
  15813. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15814. }
  15815. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15816. isKnowKey = TRUE;
  15817. }
  15818. //=========================================================
  15819. if(!isEmpty && !isKnowKey)
  15820. {
  15821. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15822. strcpy(unknownkey[UnknownKeynum], keyReq);
  15823. UnknownKeynum = UnknownKeynum + 1;
  15824. }
  15825. }
  15826. void processUnkownKey(void)
  15827. {
  15828. DEBUG_INFO("processUnkownKey...\n");
  15829. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15830. for(int index=0; index < UnknownKeynum; index++)
  15831. {
  15832. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15833. {
  15834. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15835. }
  15836. }
  15837. }
  15838. int setKeyValue(char *key, char *value)
  15839. {
  15840. int isSuccess = NotSupported;
  15841. int check_ascii=0;
  15842. char str[501]={0};
  15843. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15844. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15845. {
  15846. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15847. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15848. {
  15849. strcpy(str, (const char*)value);
  15850. for(int i = 0; str[i]; i++){
  15851. str[i] = tolower(str[i]);
  15852. }
  15853. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15854. isSuccess = ConfigurationStatus_Accepted;
  15855. }
  15856. else
  15857. {
  15858. isSuccess = ConfigurationStatus_Rejected;
  15859. }
  15860. }
  15861. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15862. {
  15863. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15864. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15865. {
  15866. strcpy(str, (const char*)value);
  15867. for(int i = 0; str[i]; i++){
  15868. str[i] = tolower(str[i]);
  15869. }
  15870. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15871. isSuccess = ConfigurationStatus_Accepted;
  15872. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  15873. }
  15874. else
  15875. {
  15876. isSuccess = ConfigurationStatus_Rejected;
  15877. }
  15878. }
  15879. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15880. {
  15881. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15882. {
  15883. strcpy(str, (const char*)value);
  15884. for(int i = 0; str[i]; i++)
  15885. {
  15886. str[i] = tolower(str[i]);
  15887. }
  15888. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15889. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15890. isSuccess = ConfigurationStatus_Accepted;
  15891. }
  15892. else
  15893. {
  15894. isSuccess = ConfigurationStatus_Rejected;
  15895. }
  15896. }
  15897. if(strcmp(key, "BlinkRepeat") == 0)
  15898. {
  15899. //Charger.BlinkRepeat = Integer.parseInt(value);
  15900. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15901. {
  15902. check_ascii = value[0];
  15903. if( (check_ascii < 48) || (check_ascii > 57) )
  15904. {
  15905. isSuccess = ConfigurationStatus_Rejected;
  15906. }
  15907. else
  15908. {
  15909. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15910. isSuccess = ConfigurationStatus_Accepted;
  15911. }
  15912. }
  15913. else
  15914. {
  15915. isSuccess = ConfigurationStatus_Rejected;
  15916. }
  15917. }
  15918. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15919. {
  15920. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15921. {
  15922. check_ascii = value[0];
  15923. if( (check_ascii < 48) || (check_ascii > 57) )
  15924. {
  15925. isSuccess = ConfigurationStatus_Rejected;
  15926. }
  15927. else
  15928. {
  15929. if((atoi(value) == 0) || (atoi(value) >= 5))
  15930. {
  15931. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15932. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15933. isSuccess = ConfigurationStatus_Accepted;
  15934. }
  15935. else
  15936. isSuccess = ConfigurationStatus_Rejected;
  15937. }
  15938. }
  15939. else
  15940. {
  15941. isSuccess = ConfigurationStatus_Rejected;
  15942. }
  15943. }
  15944. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15945. {
  15946. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15947. {
  15948. check_ascii = value[0];
  15949. if( (check_ascii < 48) || (check_ascii > 57) )
  15950. {
  15951. isSuccess = ConfigurationStatus_Rejected;
  15952. }
  15953. else
  15954. {
  15955. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15956. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15957. isSuccess = ConfigurationStatus_Accepted;
  15958. }
  15959. }
  15960. else
  15961. {
  15962. isSuccess = ConfigurationStatus_Rejected;
  15963. }
  15964. }
  15965. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15966. {
  15967. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15968. {
  15969. check_ascii = value[0];
  15970. if( (check_ascii < 48) || (check_ascii > 57) )
  15971. {
  15972. isSuccess = ConfigurationStatus_Rejected;
  15973. }
  15974. else
  15975. {
  15976. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15977. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15978. isSuccess = ConfigurationStatus_Accepted;
  15979. }
  15980. }
  15981. else
  15982. {
  15983. isSuccess = ConfigurationStatus_Rejected;
  15984. }
  15985. }
  15986. if(strcmp(key, "HeartbeatInterval") == 0)
  15987. {
  15988. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15989. {
  15990. check_ascii = value[0];
  15991. if( (check_ascii < 48) || (check_ascii > 57) )
  15992. {
  15993. isSuccess = ConfigurationStatus_Rejected;
  15994. }
  15995. else
  15996. {
  15997. if((atoi(value) == 0) || (atoi(value) >= 10))
  15998. {
  15999. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16000. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  16001. HeartBeatWaitTime = atoi(value);
  16002. isSuccess = ConfigurationStatus_Accepted;
  16003. }
  16004. else
  16005. {
  16006. isSuccess = ConfigurationStatus_Rejected;
  16007. }
  16008. }
  16009. }
  16010. else
  16011. {
  16012. isSuccess = ConfigurationStatus_Rejected;
  16013. }
  16014. }
  16015. if(strcmp(key, "LightIntensity") == 0)
  16016. {
  16017. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16018. {
  16019. check_ascii = value[0];
  16020. if( (check_ascii < 48) || (check_ascii > 57) )
  16021. {
  16022. isSuccess = ConfigurationStatus_Rejected;
  16023. }
  16024. else
  16025. {
  16026. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  16027. isSuccess = ConfigurationStatus_Accepted;
  16028. }
  16029. }
  16030. else
  16031. {
  16032. isSuccess = ConfigurationStatus_Rejected;
  16033. }
  16034. }
  16035. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  16036. {
  16037. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16038. {
  16039. strcpy(str, (const char*)value);
  16040. for(int i = 0; str[i]; i++)
  16041. {
  16042. str[i] = tolower(str[i]);
  16043. }
  16044. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16045. isSuccess = ConfigurationStatus_Accepted;
  16046. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16047. }
  16048. else
  16049. {
  16050. isSuccess = ConfigurationStatus_Rejected;
  16051. }
  16052. }
  16053. if(strcmp(key, "LocalPreAuthorize") == 0)
  16054. {
  16055. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16056. {
  16057. strcpy(str, (const char*)value);
  16058. for(int i = 0; str[i]; i++)
  16059. {
  16060. str[i] = tolower(str[i]);
  16061. }
  16062. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16063. isSuccess = ConfigurationStatus_Accepted;
  16064. }
  16065. else
  16066. {
  16067. isSuccess = ConfigurationStatus_Rejected;
  16068. }
  16069. }
  16070. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  16071. {
  16072. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16073. {
  16074. check_ascii = value[0];
  16075. if( (check_ascii < 48) || (check_ascii > 57) )
  16076. {
  16077. isSuccess = ConfigurationStatus_Rejected;
  16078. }
  16079. else
  16080. {
  16081. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  16082. isSuccess = ConfigurationStatus_Accepted;
  16083. }
  16084. }
  16085. else
  16086. {
  16087. isSuccess = ConfigurationStatus_Rejected;
  16088. }
  16089. }
  16090. if(strcmp(key, "MeterValuesAlignedData") == 0)
  16091. {
  16092. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16093. {
  16094. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  16095. isSuccess = ConfigurationStatus_Accepted;
  16096. }
  16097. else
  16098. {
  16099. isSuccess = ConfigurationStatus_Rejected;
  16100. }
  16101. }
  16102. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  16103. {
  16104. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16105. {
  16106. check_ascii = value[0];
  16107. if( (check_ascii < 48) || (check_ascii > 57) )
  16108. {
  16109. isSuccess = ConfigurationStatus_Rejected;
  16110. }
  16111. else
  16112. {
  16113. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16114. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  16115. isSuccess = ConfigurationStatus_Accepted;
  16116. }
  16117. }
  16118. else
  16119. {
  16120. isSuccess = ConfigurationStatus_Rejected;
  16121. }
  16122. }
  16123. if(strcmp(key, "MeterValuesSampledData") == 0 )
  16124. {
  16125. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16126. {
  16127. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  16128. isSuccess = ConfigurationStatus_Accepted;
  16129. }
  16130. else
  16131. {
  16132. isSuccess = ConfigurationStatus_Rejected;
  16133. }
  16134. }
  16135. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16136. {
  16137. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16138. {
  16139. check_ascii = value[0];
  16140. if( (check_ascii < 48) || (check_ascii > 57) )
  16141. {
  16142. isSuccess = ConfigurationStatus_Rejected;
  16143. }
  16144. else
  16145. {
  16146. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16147. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16148. isSuccess = ConfigurationStatus_Accepted;
  16149. }
  16150. }
  16151. else
  16152. {
  16153. isSuccess = ConfigurationStatus_Rejected;
  16154. }
  16155. }
  16156. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16157. {
  16158. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16159. {
  16160. check_ascii = value[0];
  16161. if( (check_ascii < 48) || (check_ascii > 57) )
  16162. {
  16163. isSuccess = ConfigurationStatus_Rejected;
  16164. }
  16165. else
  16166. {
  16167. if((atoi(value) == 0) || (atoi(value) >= 3))
  16168. {
  16169. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16170. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16171. isSuccess = ConfigurationStatus_Accepted;
  16172. }
  16173. else
  16174. {
  16175. isSuccess = ConfigurationStatus_Rejected;
  16176. }
  16177. }
  16178. }
  16179. else
  16180. {
  16181. isSuccess = ConfigurationStatus_Rejected;
  16182. }
  16183. }
  16184. if(strcmp(key, "MinimumStatusDuration") == 0)
  16185. {
  16186. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16187. {
  16188. check_ascii = value[0];
  16189. if( (check_ascii < 48) || (check_ascii > 57) )
  16190. {
  16191. isSuccess = ConfigurationStatus_Rejected;
  16192. }
  16193. else
  16194. {
  16195. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16196. {
  16197. isSuccess = ConfigurationStatus_Rejected;
  16198. }
  16199. else
  16200. {
  16201. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16202. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16203. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16204. isSuccess = ConfigurationStatus_Accepted;
  16205. }
  16206. }
  16207. }
  16208. else
  16209. {
  16210. isSuccess = ConfigurationStatus_Rejected;
  16211. }
  16212. }
  16213. if(strcmp(key, "NumberOfConnectors") == 0)
  16214. {
  16215. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16216. {
  16217. check_ascii = value[0];
  16218. if( (check_ascii < 48) || (check_ascii > 57) )
  16219. {
  16220. isSuccess = ConfigurationStatus_Rejected;
  16221. }
  16222. else
  16223. {
  16224. //Charger.ResetRetries = Integer.parseInt(value);
  16225. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16226. isSuccess = ConfigurationStatus_Accepted;
  16227. }
  16228. }
  16229. else
  16230. {
  16231. isSuccess = ConfigurationStatus_Rejected;
  16232. }
  16233. }
  16234. if(strcmp(key, "ResetRetries") == 0)
  16235. {
  16236. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16237. {
  16238. check_ascii = value[0];
  16239. if( (check_ascii < 48) || (check_ascii > 57) )
  16240. {
  16241. isSuccess = ConfigurationStatus_Rejected;
  16242. }
  16243. else
  16244. {
  16245. //Charger.ResetRetries = Integer.parseInt(value);
  16246. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16247. isSuccess = ConfigurationStatus_Accepted;
  16248. }
  16249. }
  16250. else
  16251. {
  16252. isSuccess = ConfigurationStatus_Rejected;
  16253. }
  16254. }
  16255. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16256. {
  16257. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16258. {
  16259. strcpy(str, (const char*)value);
  16260. for(int i = 0; str[i]; i++)
  16261. {
  16262. str[i] = tolower(str[i]);
  16263. }
  16264. if(strcmp(str, "notapplicable")== 0)
  16265. {
  16266. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16267. isSuccess = ConfigurationStatus_Accepted;
  16268. }
  16269. else if(strcmp(str, "unknown")== 0)
  16270. {
  16271. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16272. isSuccess = ConfigurationStatus_Accepted;
  16273. }
  16274. else if(strcmp(str, "rst")== 0)
  16275. {
  16276. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16277. isSuccess = ConfigurationStatus_Accepted;
  16278. }
  16279. else if(strcmp(str, "rts")== 0)
  16280. {
  16281. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16282. isSuccess = ConfigurationStatus_Accepted;
  16283. }
  16284. else if(strcmp(str, "srt")== 0)
  16285. {
  16286. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16287. isSuccess = ConfigurationStatus_Accepted;
  16288. }
  16289. else if(strcmp(str, "str")== 0)
  16290. {
  16291. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16292. isSuccess = ConfigurationStatus_Accepted;
  16293. }
  16294. else if(strcmp(str, "trs")== 0)
  16295. {
  16296. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16297. isSuccess = ConfigurationStatus_Accepted;
  16298. }
  16299. else if(strcmp(str, "tsr")== 0)
  16300. {
  16301. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16302. isSuccess = ConfigurationStatus_Accepted;
  16303. }
  16304. else
  16305. {
  16306. isSuccess = ConfigurationStatus_Rejected;
  16307. }
  16308. }
  16309. else
  16310. {
  16311. isSuccess = ConfigurationStatus_Rejected;
  16312. }
  16313. }
  16314. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16315. {
  16316. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16317. {
  16318. check_ascii = value[0];
  16319. if( (check_ascii < 48) || (check_ascii > 57) )
  16320. {
  16321. isSuccess = ConfigurationStatus_Rejected;
  16322. }
  16323. else
  16324. {
  16325. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16326. isSuccess = ConfigurationStatus_Accepted;
  16327. }
  16328. }
  16329. else
  16330. {
  16331. isSuccess = ConfigurationStatus_Rejected;
  16332. }
  16333. }
  16334. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16335. {
  16336. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16337. {
  16338. strcpy(str, (const char*)value);
  16339. for(int i = 0; str[i]; i++)
  16340. {
  16341. str[i] = tolower(str[i]);
  16342. }
  16343. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16344. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16345. isSuccess = ConfigurationStatus_Accepted;
  16346. }
  16347. else
  16348. {
  16349. isSuccess = ConfigurationStatus_Rejected;
  16350. }
  16351. }
  16352. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16353. {
  16354. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16355. {
  16356. strcpy(str, (const char*)value);
  16357. for(int i = 0; str[i]; i++)
  16358. {
  16359. str[i] = tolower(str[i]);
  16360. }
  16361. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16362. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16363. isSuccess = ConfigurationStatus_Accepted;
  16364. }
  16365. else
  16366. {
  16367. isSuccess = ConfigurationStatus_Rejected;
  16368. }
  16369. }
  16370. if(strcmp(key, "StopTxnAlignedData") == 0)
  16371. {
  16372. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16373. {
  16374. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16375. isSuccess = ConfigurationStatus_Accepted;
  16376. }
  16377. else
  16378. {
  16379. isSuccess = ConfigurationStatus_Rejected;
  16380. }
  16381. }
  16382. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16383. {
  16384. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16385. {
  16386. check_ascii = value[0];
  16387. if( (check_ascii < 48) || (check_ascii > 57) )
  16388. {
  16389. isSuccess = ConfigurationStatus_Rejected;
  16390. }
  16391. else
  16392. {
  16393. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16394. isSuccess = ConfigurationStatus_Accepted;
  16395. }
  16396. }
  16397. else
  16398. {
  16399. isSuccess = ConfigurationStatus_Rejected;
  16400. }
  16401. }
  16402. if(strcmp(key, "StopTxnSampledData") == 0)
  16403. {
  16404. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16405. {
  16406. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16407. isSuccess = ConfigurationStatus_Accepted;
  16408. }
  16409. else
  16410. {
  16411. isSuccess = ConfigurationStatus_Rejected;
  16412. }
  16413. }
  16414. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16415. {
  16416. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16417. {
  16418. check_ascii = value[0];
  16419. if( (check_ascii < 48) || (check_ascii > 57) )
  16420. {
  16421. isSuccess = ConfigurationStatus_Rejected;
  16422. }
  16423. else
  16424. {
  16425. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16426. isSuccess = ConfigurationStatus_Accepted;
  16427. }
  16428. }
  16429. else
  16430. {
  16431. isSuccess = ConfigurationStatus_Rejected;
  16432. }
  16433. }
  16434. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16435. {
  16436. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16437. {
  16438. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16439. isSuccess = ConfigurationStatus_Accepted;
  16440. }
  16441. else
  16442. {
  16443. isSuccess = ConfigurationStatus_Rejected;
  16444. }
  16445. }
  16446. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16447. {
  16448. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16449. {
  16450. check_ascii = value[0];
  16451. if( (check_ascii < 48) || (check_ascii > 57) )
  16452. {
  16453. isSuccess = ConfigurationStatus_Rejected;
  16454. }
  16455. else
  16456. {
  16457. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16458. isSuccess = ConfigurationStatus_Accepted;
  16459. }
  16460. }
  16461. else
  16462. {
  16463. isSuccess = ConfigurationStatus_Rejected;
  16464. }
  16465. }
  16466. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16467. {
  16468. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16469. {
  16470. check_ascii = value[0];
  16471. if( (check_ascii < 48) || (check_ascii > 57) )
  16472. {
  16473. isSuccess = ConfigurationStatus_Rejected;
  16474. }
  16475. else
  16476. {
  16477. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16478. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16479. TransactionMessageAttemptsValue = atoi(value);
  16480. isSuccess = ConfigurationStatus_Accepted;
  16481. }
  16482. }
  16483. else
  16484. {
  16485. isSuccess = ConfigurationStatus_Rejected;
  16486. }
  16487. }
  16488. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16489. {
  16490. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16491. {
  16492. check_ascii = value[0];
  16493. if( (check_ascii < 48) || (check_ascii > 57) )
  16494. {
  16495. isSuccess = ConfigurationStatus_Rejected;
  16496. }
  16497. else
  16498. {
  16499. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16500. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16501. TransactionMessageRetryIntervalValue = atoi(value);
  16502. isSuccess = ConfigurationStatus_Accepted;
  16503. }
  16504. }
  16505. else
  16506. {
  16507. isSuccess = ConfigurationStatus_Rejected;
  16508. }
  16509. }
  16510. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16511. {
  16512. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16513. {
  16514. strcpy(str, (const char*)value);
  16515. for(int i = 0; str[i]; i++)
  16516. {
  16517. str[i] = tolower(str[i]);
  16518. }
  16519. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16520. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16521. isSuccess = ConfigurationStatus_Accepted;
  16522. }
  16523. else
  16524. {
  16525. isSuccess = ConfigurationStatus_Rejected;
  16526. }
  16527. }
  16528. if(strcmp(key, "WebSocketPingInterval") == 0)
  16529. {
  16530. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16531. {
  16532. check_ascii = value[0];
  16533. if( (check_ascii < 48) || (check_ascii > 57) )
  16534. {
  16535. isSuccess = ConfigurationStatus_Rejected;
  16536. }
  16537. else
  16538. {
  16539. if((atoi(value) == 0) || (atoi(value) >= 10))
  16540. {
  16541. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16542. isSuccess = ConfigurationStatus_Accepted;
  16543. }
  16544. else
  16545. isSuccess = ConfigurationStatus_Rejected;
  16546. }
  16547. }
  16548. else
  16549. {
  16550. isSuccess = ConfigurationStatus_Rejected;
  16551. }
  16552. }
  16553. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16554. {
  16555. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16556. {
  16557. strcpy(str, (const char*)value);
  16558. for(int i = 0; str[i]; i++)
  16559. {
  16560. str[i] = tolower(str[i]);
  16561. }
  16562. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16563. isSuccess = ConfigurationStatus_Accepted;
  16564. }
  16565. else
  16566. {
  16567. isSuccess = ConfigurationStatus_Rejected;
  16568. }
  16569. }
  16570. if(strcmp(key, "AuthorizationKey") == 0)
  16571. {
  16572. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16573. {
  16574. strcpy(str, (const char*)value);
  16575. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16576. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16577. isSuccess = ConfigurationStatus_Accepted;
  16578. }
  16579. else
  16580. {
  16581. isSuccess = ConfigurationStatus_Rejected;
  16582. }
  16583. }
  16584. if(strcmp(key, "SecurityProfile") == 0)
  16585. {
  16586. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16587. {
  16588. check_ascii = value[0];
  16589. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16590. {
  16591. isSuccess = ConfigurationStatus_Rejected;
  16592. }
  16593. else if(check_ascii == 0x33)
  16594. {
  16595. isSuccess = NotSupported;
  16596. }
  16597. else
  16598. {
  16599. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16600. {
  16601. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16602. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  16603. isSuccess = ConfigurationStatus_Accepted;
  16604. }
  16605. else
  16606. isSuccess = ConfigurationStatus_Rejected;
  16607. }
  16608. }
  16609. else
  16610. {
  16611. isSuccess = ConfigurationStatus_Rejected;
  16612. }
  16613. }
  16614. if(strcmp(key, "DefaultPrice") == 0)
  16615. {
  16616. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16617. {
  16618. strcpy(str, (const char*)value);
  16619. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16620. isSuccess = ConfigurationStatus_Accepted;
  16621. }
  16622. else
  16623. {
  16624. isSuccess = ConfigurationStatus_Rejected;
  16625. }
  16626. }
  16627. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16628. {
  16629. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16630. {
  16631. strcpy(str, (const char*)value);
  16632. for(int i = 0; str[i]; i++)
  16633. {
  16634. str[i] = tolower(str[i]);
  16635. }
  16636. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16637. isSuccess = ConfigurationStatus_Accepted;
  16638. }
  16639. else
  16640. {
  16641. isSuccess = ConfigurationStatus_Rejected;
  16642. }
  16643. }
  16644. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16645. {
  16646. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16647. {
  16648. strcpy(str, (const char*)value);
  16649. for(int i = 0; str[i]; i++)
  16650. {
  16651. str[i] = tolower(str[i]);
  16652. }
  16653. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16654. isSuccess = ConfigurationStatus_Accepted;
  16655. }
  16656. else
  16657. {
  16658. isSuccess = ConfigurationStatus_Rejected;
  16659. }
  16660. }
  16661. if(strcmp(key, "TimeOffset") == 0)
  16662. {
  16663. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16664. {
  16665. strcpy(str, (const char*)value);
  16666. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  16667. isSuccess = ConfigurationStatus_Accepted;
  16668. }
  16669. else
  16670. {
  16671. isSuccess = ConfigurationStatus_Rejected;
  16672. }
  16673. }
  16674. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  16675. {
  16676. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  16677. {
  16678. strcpy(str, (const char*)value);
  16679. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  16680. isSuccess = ConfigurationStatus_Accepted;
  16681. }
  16682. else
  16683. {
  16684. isSuccess = ConfigurationStatus_Rejected;
  16685. }
  16686. }
  16687. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  16688. {
  16689. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  16690. {
  16691. strcpy(str, (const char*)value);
  16692. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  16693. isSuccess = ConfigurationStatus_Accepted;
  16694. }
  16695. else
  16696. {
  16697. isSuccess = ConfigurationStatus_Rejected;
  16698. }
  16699. }
  16700. if(strcmp(key, "SystemUptimeSec") == 0)
  16701. {
  16702. isSuccess = NotSupported;
  16703. }
  16704. if(strcmp(key, "FreeVend") == 0)
  16705. {
  16706. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16707. {
  16708. strcpy(str, (const char*)value);
  16709. for(int i = 0; str[i]; i++)
  16710. {
  16711. str[i] = tolower(str[i]);
  16712. }
  16713. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16714. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16715. isSuccess = ConfigurationStatus_Accepted;
  16716. }
  16717. else
  16718. {
  16719. isSuccess = ConfigurationStatus_Rejected;
  16720. }
  16721. }
  16722. if(strcmp(key, "FreeVendIdtag") == 0)
  16723. {
  16724. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16725. {
  16726. strcpy(str, (const char*)value);
  16727. if(strlen(str) <= 20)
  16728. {
  16729. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  16730. isSuccess = ConfigurationStatus_Accepted;
  16731. }
  16732. else
  16733. {
  16734. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  16735. isSuccess = ConfigurationStatus_Rejected;
  16736. }
  16737. }
  16738. else
  16739. {
  16740. isSuccess = ConfigurationStatus_Rejected;
  16741. }
  16742. }
  16743. if(strcmp(key, "OcppServer") == 0)
  16744. {
  16745. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16746. {
  16747. strcpy(str, (const char*)value);
  16748. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16749. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16750. isSuccess = ConfigurationStatus_Accepted;
  16751. }
  16752. else
  16753. {
  16754. isSuccess = ConfigurationStatus_Rejected;
  16755. }
  16756. }
  16757. if(strcmp(key, "MaintainServer") == 0)
  16758. {
  16759. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16760. {
  16761. strcpy(str, (const char*)value);
  16762. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16763. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16764. isSuccess = ConfigurationStatus_Accepted;
  16765. }
  16766. else
  16767. {
  16768. isSuccess = ConfigurationStatus_Rejected;
  16769. }
  16770. }
  16771. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16772. {
  16773. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16774. {
  16775. strcpy(str, (const char*)value);
  16776. for(int i = 0; str[i]; i++)
  16777. {
  16778. str[i] = tolower(str[i]);
  16779. }
  16780. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16781. isSuccess = ConfigurationStatus_Accepted;
  16782. }
  16783. else
  16784. {
  16785. isSuccess = ConfigurationStatus_Rejected;
  16786. }
  16787. }
  16788. if(strcmp(key, "StatusNotificationInterval") == 0)
  16789. {
  16790. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16791. {
  16792. check_ascii = value[0];
  16793. if( (check_ascii < 48) || (check_ascii > 57) )
  16794. {
  16795. isSuccess = ConfigurationStatus_Rejected;
  16796. }
  16797. else
  16798. {
  16799. if((atoi(value) == 0) || (atoi(value) >= 10))
  16800. {
  16801. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16802. isSuccess = ConfigurationStatus_Accepted;
  16803. }
  16804. else
  16805. isSuccess = ConfigurationStatus_Rejected;
  16806. }
  16807. }
  16808. else
  16809. {
  16810. isSuccess = ConfigurationStatus_Rejected;
  16811. }
  16812. }
  16813. #if 0
  16814. //For OCPP Test Case
  16815. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16816. {
  16817. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16818. {
  16819. strcpy(str, (const char*)value);
  16820. for(int i = 0; str[i]; i++)
  16821. {
  16822. str[i] = tolower(str[i]);
  16823. }
  16824. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16825. isSuccess = ConfigurationStatus_Accepted;
  16826. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16827. }
  16828. else
  16829. {
  16830. isSuccess = ConfigurationStatus_Rejected;
  16831. }
  16832. }
  16833. #endif
  16834. #if 1
  16835. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16836. {
  16837. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16838. {
  16839. strcpy(str, (const char*)value);
  16840. for(int i = 0; str[i]; i++)
  16841. {
  16842. str[i] = tolower(str[i]);
  16843. }
  16844. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16845. isSuccess = ConfigurationStatus_Accepted;
  16846. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16847. }
  16848. else
  16849. {
  16850. isSuccess = ConfigurationStatus_Rejected;
  16851. }
  16852. }
  16853. #endif
  16854. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16855. {
  16856. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16857. {
  16858. check_ascii = value[0];
  16859. if( (check_ascii < 48) || (check_ascii > 57) )
  16860. {
  16861. isSuccess = ConfigurationStatus_Rejected;
  16862. }
  16863. else
  16864. {
  16865. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16866. isSuccess = ConfigurationStatus_Accepted;
  16867. }
  16868. }
  16869. else
  16870. {
  16871. isSuccess = ConfigurationStatus_Rejected;
  16872. }
  16873. }
  16874. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16875. {
  16876. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16877. {
  16878. check_ascii = value[0];
  16879. if( (check_ascii < 48) || (check_ascii > 57) )
  16880. {
  16881. isSuccess = ConfigurationStatus_Rejected;
  16882. }
  16883. else
  16884. {
  16885. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16886. isSuccess = ConfigurationStatus_Accepted;
  16887. }
  16888. }
  16889. else
  16890. {
  16891. isSuccess = ConfigurationStatus_Rejected;
  16892. }
  16893. }
  16894. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16895. {
  16896. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16897. {
  16898. strcpy(str, (const char*)value);
  16899. for(int i = 0; str[i]; i++)
  16900. {
  16901. str[i] = tolower(str[i]);
  16902. }
  16903. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16904. isSuccess = ConfigurationStatus_Accepted;
  16905. }
  16906. else
  16907. {
  16908. isSuccess = ConfigurationStatus_Rejected;
  16909. }
  16910. }
  16911. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16912. {
  16913. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16914. {
  16915. check_ascii = value[0];
  16916. if( (check_ascii < 48) || (check_ascii > 57) )
  16917. {
  16918. isSuccess = ConfigurationStatus_Rejected;
  16919. }
  16920. else
  16921. {
  16922. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16923. isSuccess = ConfigurationStatus_Accepted;
  16924. }
  16925. }
  16926. else
  16927. {
  16928. isSuccess = ConfigurationStatus_Rejected;
  16929. }
  16930. }
  16931. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16932. {
  16933. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16934. {
  16935. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16936. isSuccess = ConfigurationStatus_Accepted;
  16937. }
  16938. else
  16939. {
  16940. isSuccess = ConfigurationStatus_Rejected;
  16941. }
  16942. }
  16943. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16944. {
  16945. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16946. {
  16947. check_ascii = value[0];
  16948. if( (check_ascii < 48) || (check_ascii > 57) )
  16949. {
  16950. isSuccess = ConfigurationStatus_Rejected;
  16951. }
  16952. else
  16953. {
  16954. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16955. isSuccess = ConfigurationStatus_Accepted;
  16956. }
  16957. }
  16958. else
  16959. {
  16960. isSuccess = ConfigurationStatus_Rejected;
  16961. }
  16962. }
  16963. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16964. {
  16965. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16966. {
  16967. strcpy(str, (const char*)value);
  16968. for(int i = 0; str[i]; i++)
  16969. {
  16970. str[i] = tolower(str[i]);
  16971. }
  16972. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16973. isSuccess = ConfigurationStatus_Accepted;
  16974. }
  16975. else
  16976. {
  16977. isSuccess = ConfigurationStatus_Rejected;
  16978. }
  16979. }
  16980. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16981. {
  16982. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16983. {
  16984. check_ascii = value[0];
  16985. if( (check_ascii < 48) || (check_ascii > 57) )
  16986. {
  16987. isSuccess = ConfigurationStatus_Rejected;
  16988. }
  16989. else
  16990. {
  16991. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16992. isSuccess = ConfigurationStatus_Accepted;
  16993. }
  16994. }
  16995. else
  16996. {
  16997. isSuccess = ConfigurationStatus_Rejected;
  16998. }
  16999. }
  17000. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17001. return isSuccess;
  17002. }
  17003. int TransactionMessageAttemptsGet(void)
  17004. {
  17005. return TransactionMessageAttemptsValue;
  17006. }
  17007. int FirstHeartBeatResponse(void)
  17008. {
  17009. return FirstHeartBeat;
  17010. }
  17011. int TransactionMessageRetryIntervalGet(void)
  17012. {
  17013. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17014. }
  17015. int ReadHttpStatus(int sock)
  17016. {
  17017. //char c;
  17018. char buff[1024]="",*ptr=buff+1;
  17019. int bytes_received, status;
  17020. DEBUG_INFO("Begin Response ..\n");
  17021. while((bytes_received = recv(sock, ptr, 1, 0))){
  17022. if(bytes_received==-1){
  17023. perror("ReadHttpStatus");
  17024. exit(1);
  17025. }
  17026. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  17027. ptr++;
  17028. }
  17029. *ptr=0;
  17030. ptr=buff+1;
  17031. sscanf(ptr,"%*s %d ", &status);
  17032. DEBUG_INFO("%s\n",ptr);
  17033. DEBUG_INFO("status=%d\n",status);
  17034. DEBUG_INFO("End Response ..\n");
  17035. return (bytes_received>0)?status:0;
  17036. }
  17037. //the only filed that it parsed is 'Content-Length'
  17038. int ParseHeader(int sock)
  17039. {
  17040. //char c;
  17041. char buff[1024]="",*ptr=buff+4;
  17042. int bytes_received;
  17043. DEBUG_INFO("Begin HEADER ..\n");
  17044. while((bytes_received = recv(sock, ptr, 1, 0))){
  17045. if(bytes_received==-1){
  17046. perror("Parse Header");
  17047. exit(1);
  17048. }
  17049. if(
  17050. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  17051. (ptr[-1]=='\r') && (*ptr=='\n' )
  17052. ) break;
  17053. ptr++;
  17054. }
  17055. *ptr=0;
  17056. ptr=buff+4;
  17057. //printf("%s",ptr);
  17058. if(bytes_received){
  17059. ptr=strstr(ptr,"Content-Length:");
  17060. if(ptr){
  17061. sscanf(ptr,"%*s %d",&bytes_received);
  17062. }else
  17063. bytes_received=-1; //unknown size
  17064. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  17065. }
  17066. DEBUG_INFO("End HEADER ..\n");
  17067. return bytes_received ;
  17068. }
  17069. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  17070. {
  17071. int result = TRUE;
  17072. char rmFileCmd[100]={0};
  17073. char FilePath[100]={0};
  17074. char ftpbuf[200];
  17075. int systemresult;
  17076. sprintf(FilePath,"/mnt/%s",filename);
  17077. system("ping 8.8.8.8 &");
  17078. if((access(FilePath,F_OK))!=-1)
  17079. {
  17080. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17081. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17082. system(rmFileCmd);
  17083. }
  17084. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17085. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17086. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17087. systemresult = system(ftpbuf);
  17088. if(systemresult != 0)
  17089. {
  17090. DEBUG_INFO("http DownLoad error!\n");
  17091. result = FALSE;
  17092. }
  17093. system("pkill ping");
  17094. return result;
  17095. }
  17096. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  17097. {
  17098. int result = TRUE;
  17099. char rmFileCmd[100]={0};
  17100. char FilePath[100]={0};
  17101. char ftpbuf[200];
  17102. int systemresult;
  17103. sprintf(FilePath,"/mnt/%s",filename);
  17104. system("ping 8.8.8.8 &");
  17105. if((access(FilePath,F_OK))!=-1)
  17106. {
  17107. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17108. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17109. system(rmFileCmd);
  17110. }
  17111. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17112. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  17113. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17114. systemresult = system(ftpbuf);
  17115. if(systemresult != 0)
  17116. {
  17117. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17118. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17119. systemresult = system(ftpbuf);
  17120. if(systemresult != 0)
  17121. {
  17122. DEBUG_WARN("wget error!\n");
  17123. result = FALSE;
  17124. }
  17125. }
  17126. system("pkill ping");
  17127. return result;
  17128. }
  17129. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17130. {
  17131. char rmFileCmd[100]={0};
  17132. char FilePath[100]={0};
  17133. char buf[512];
  17134. int systemresult = 0;
  17135. //DEBUG_INFO("filename=%s\n",filename);
  17136. //DEBUG_INFO("url=%s\n",url);
  17137. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17138. if((access(FilePath,F_OK))!=-1)
  17139. {
  17140. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17141. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17142. system(rmFileCmd);
  17143. }
  17144. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17145. if(fp == NULL)
  17146. {
  17147. DEBUG_INFO("log is NULL\n");
  17148. return FALSE;
  17149. }
  17150. else
  17151. {
  17152. fprintf(fp, "%s\n", url);
  17153. fprintf(fp, "%s\n", filename);
  17154. fclose(fp);
  17155. }
  17156. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17157. if(phpFP == NULL)
  17158. {
  17159. DEBUG_INFO("PHP upload fail.\n");
  17160. return FALSE;
  17161. }
  17162. else
  17163. {
  17164. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17165. {
  17166. if(strstr(buf, "result") != NULL)
  17167. {
  17168. sscanf(buf, "result: %d", &systemresult);
  17169. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17170. }
  17171. }
  17172. pclose(phpFP);
  17173. }
  17174. if(systemresult != 1)
  17175. {
  17176. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  17177. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  17178. if(phpFP == NULL)
  17179. {
  17180. DEBUG_WARN("PHP PUT upload fail.\n");
  17181. return FALSE;
  17182. }
  17183. else
  17184. {
  17185. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17186. {
  17187. if(strstr(buf, "result") != NULL)
  17188. {
  17189. sscanf(buf, "result: %d", &systemresult);
  17190. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  17191. }
  17192. }
  17193. pclose(phpFP);
  17194. }
  17195. }
  17196. return TRUE;
  17197. }
  17198. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17199. {
  17200. int result = FALSE;
  17201. char ftpbuf[200];
  17202. int systemresult;
  17203. /*
  17204. // Domaind name transfer to IP address
  17205. struct hostent* server;
  17206. char *IPbuffer;
  17207. server = gethostbyname(location);
  17208. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17209. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17210. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17211. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17212. systemresult = system(ftpbuf);
  17213. if(systemresult != 0)
  17214. {
  17215. DEBUG_INFO("ftpput error!\n");
  17216. }
  17217. else
  17218. {
  17219. result = TRUE;
  17220. DEBUG_INFO("ftpput OK!\n");
  17221. }
  17222. return result;
  17223. }
  17224. int GetOcppServerURL()
  17225. {
  17226. int result = FALSE;
  17227. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17228. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17229. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17230. struct yuarel url;
  17231. char urlStr[512];
  17232. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  17233. {
  17234. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  17235. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17236. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17237. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  17238. if(yuarel_parse(&url, urlStr) != -1)
  17239. {
  17240. sprintf(OcppProtocol, "%s", url.scheme);
  17241. sprintf(OcppHost, "%s", url.host);
  17242. if(url.path == NULL)
  17243. OcppTempPath[0] = '\0';
  17244. else
  17245. {
  17246. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  17247. {
  17248. sprintf(OcppTempPath, "%s/", url.path);
  17249. }
  17250. else
  17251. {
  17252. sprintf(OcppTempPath, "%s", url.path);
  17253. }
  17254. }
  17255. if(url.port == 0)
  17256. {
  17257. if(strcmp(OcppProtocol, "wss") == 0)
  17258. OcppPort = 443;
  17259. else
  17260. OcppPort = 80;
  17261. }
  17262. else
  17263. OcppPort = url.port;
  17264. result = TRUE;
  17265. }
  17266. }
  17267. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  17268. {
  17269. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  17270. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17271. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17272. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  17273. if(yuarel_parse(&url, urlStr) != -1)
  17274. {
  17275. sprintf(OcppProtocol, "%s", url.scheme);
  17276. sprintf(OcppHost, "%s", url.host);
  17277. if(url.path == NULL)
  17278. OcppTempPath[0] = '\0';
  17279. else
  17280. sprintf(OcppTempPath, "%s", url.path);
  17281. if(url.port == 0)
  17282. {
  17283. if(strcmp(OcppProtocol, "wss") == 0)
  17284. OcppPort = 443;
  17285. else
  17286. OcppPort = 80;
  17287. }
  17288. else
  17289. OcppPort = url.port;
  17290. result = TRUE;
  17291. }
  17292. }
  17293. else
  17294. {
  17295. strcpy(OcppHost,"");
  17296. }
  17297. return result;
  17298. }
  17299. int GetOcppPath()
  17300. {
  17301. int result = FALSE;
  17302. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  17303. {
  17304. if(OcppTempPath == NULL)
  17305. {
  17306. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17307. }
  17308. else
  17309. {
  17310. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17311. }
  17312. result = TRUE;
  17313. goto End;
  17314. }
  17315. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  17316. {
  17317. if(OcppTempPath == NULL)
  17318. {
  17319. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  17320. }
  17321. else
  17322. {
  17323. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  17324. }
  17325. result = TRUE;
  17326. goto End;
  17327. }
  17328. else
  17329. {
  17330. strcpy(OcppPath,"");
  17331. }
  17332. End:
  17333. return result;
  17334. }
  17335. int GetOcppPort()
  17336. {
  17337. return OcppPort;
  17338. }
  17339. int GetOcppConnStatus(void)
  17340. {
  17341. return ShmOCPP16Data->OcppConnStatus;
  17342. }
  17343. void SetOcppConnStatus(uint8_t status)
  17344. {
  17345. ShmOCPP16Data->OcppConnStatus = status;
  17346. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  17347. }
  17348. int GetHeartBeatWithNOResponse(void)
  17349. {
  17350. return HeartBeatWithNOResponse;
  17351. }
  17352. void SetHeartBeatWithNOResponse(void)
  17353. {
  17354. HeartBeatWithNOResponse = 0;
  17355. }
  17356. void GetStartTransactionIdTag(int gun_index)
  17357. {
  17358. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17359. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17360. }
  17361. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17362. {
  17363. char ch;
  17364. FILE *fptr1;
  17365. int temptransactionId;
  17366. char str[100]={0};
  17367. temptransactionId = 0;
  17368. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17369. {
  17370. DEBUG_INFO("IdTag is empty.\n");
  17371. return temptransactionId;
  17372. }
  17373. /*------ Read the file ----------------*/
  17374. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  17375. if (!fptr1)
  17376. {
  17377. DEBUG_INFO("QueueTransactionId file open error.\n");
  17378. //printf(" File not found or unable to open the input file!!\n");
  17379. return temptransactionId;
  17380. }
  17381. ch=fgetc(fptr1);
  17382. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  17383. rewind(fptr1);
  17384. if(ch!=EOF)
  17385. {
  17386. // printf("%c",ch);
  17387. while (fgets(str, 100, fptr1) != NULL)
  17388. {
  17389. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17390. if(str[0]=='\0')
  17391. {
  17392. break;
  17393. }
  17394. char *revbuf[8] = {0}; // Variable store string split
  17395. int num = 0;// Quantity after string split
  17396. DEBUG_INFO("Transaction queue data= %s\n", str);
  17397. splitstring(str,",",revbuf,&num); // String split
  17398. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17399. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17400. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17401. DEBUG_INFO("------------------------------\n");
  17402. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17403. {
  17404. if(isStopTransaction)
  17405. {
  17406. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17407. {
  17408. temptransactionId = atoi(revbuf[2]);
  17409. //break;
  17410. }
  17411. }
  17412. else
  17413. {
  17414. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17415. {
  17416. temptransactionId = atoi(revbuf[2]);
  17417. //break;
  17418. }
  17419. }
  17420. }
  17421. }
  17422. }
  17423. else
  17424. DEBUG_INFO("EOF\n");
  17425. fclose(fptr1);
  17426. /*------- End of reading ---------------*/
  17427. return temptransactionId;
  17428. }
  17429. void SetTransactionIdZero(int transactionId)
  17430. {
  17431. char ch;
  17432. FILE *fptr1, *fptr2;
  17433. int temptransactionId = 0;
  17434. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  17435. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  17436. if (!fptr1)
  17437. {
  17438. //printf(" File not found or unable to open the input file!!\n");
  17439. return ;
  17440. }
  17441. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17442. if (!fptr2)
  17443. {
  17444. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17445. fclose(fptr1);
  17446. return ;
  17447. }
  17448. ch=fgetc(fptr1);
  17449. rewind(fptr1);
  17450. if(ch!=EOF)
  17451. {
  17452. // copy all contents to the temporary file except the specific line
  17453. while (fgets(str, 100, fptr1) != NULL)
  17454. {
  17455. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17456. if(str[0]=='\0')
  17457. {
  17458. break;
  17459. }
  17460. char *revbuf[8] = {0};
  17461. int num = 0;
  17462. strcpy(strtemp, str);
  17463. splitstring(str,",",revbuf,&num);
  17464. if(revbuf[2][0] != '\0')
  17465. {
  17466. temptransactionId = atoi(revbuf[2]);
  17467. if(transactionId != temptransactionId)
  17468. {
  17469. fprintf(fptr2, "%s\n", strtemp);
  17470. }
  17471. }
  17472. }
  17473. }
  17474. fclose(fptr1);
  17475. fclose(fptr2);
  17476. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  17477. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  17478. /*------ Read the file ----------------*/
  17479. }
  17480. int InternetDisconnect(void)
  17481. {
  17482. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17483. }
  17484. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17485. void storeTempStopTransaction(int gun_index)
  17486. {
  17487. char guid[37]={0};
  17488. int tempIndex = 0;
  17489. char TempStopTransaction[256];
  17490. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  17491. DEBUG_INFO("storeTempStopTransaction...\n");
  17492. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17493. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  17494. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17495. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17496. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17497. {
  17498. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17499. {
  17500. tempIndex = ((gun_index==2) ? 1: 0);
  17501. }
  17502. else
  17503. {
  17504. tempIndex = gun_index;
  17505. }
  17506. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17507. {
  17508. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17509. {
  17510. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17511. }
  17512. }// END OF CHAdeMO_QUANTITY
  17513. }
  17514. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17515. {
  17516. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17517. {
  17518. tempIndex = ((gun_index==2) ? 1: 0);
  17519. }
  17520. else
  17521. {
  17522. tempIndex = gun_index;
  17523. }
  17524. for (int index = 0; index < CCS_QUANTITY; index++)
  17525. {
  17526. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17527. {
  17528. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17529. }
  17530. }// END OF CCS_QUANTITY
  17531. }
  17532. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17533. {
  17534. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17535. {
  17536. tempIndex = ((gun_index==2) ? 1: 0);
  17537. }
  17538. else
  17539. {
  17540. tempIndex = gun_index;
  17541. }
  17542. for (int index = 0; index < GB_QUANTITY; index++)
  17543. {
  17544. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17545. {
  17546. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17547. }
  17548. }// END OF GB_QUANTITY
  17549. }
  17550. else if(gunType[gun_index] == GUN_TYPE_DO)
  17551. {
  17552. tempIndex = gun_index;
  17553. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17554. {
  17555. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17556. {
  17557. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17558. }
  17559. }
  17560. }
  17561. else
  17562. {
  17563. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17564. {
  17565. tempIndex = 2;
  17566. }
  17567. else
  17568. {
  17569. tempIndex = gun_index;
  17570. }
  17571. for (int index = 0; index < AC_QUANTITY; index++)
  17572. {
  17573. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17574. {
  17575. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17576. }
  17577. }// END OF AC_QUANTITY
  17578. }
  17579. //Stop Transaction Time
  17580. struct timeval tmnow;
  17581. struct tm *tm;
  17582. char buf[28];//, usec_buf[6];
  17583. gettimeofday(&tmnow, NULL);
  17584. time_t t;
  17585. t = time(NULL);
  17586. /*UTC time and date*/
  17587. tm = gmtime(&t);
  17588. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17589. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  17590. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  17591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17592. random_uuid(guid);
  17593. /***********************************transactionData******************************************************/
  17594. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17596. //=================================
  17597. //1. Transaction_Begin
  17598. //=================================
  17599. //============================== Energy.Active.Import.Interval ===========================================
  17600. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17601. {
  17602. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  17603. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17604. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  17605. 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*/]);
  17606. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17607. 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))
  17608. {
  17609. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  17610. }
  17611. else
  17612. {
  17613. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  17614. }
  17615. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  17616. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17617. }
  17618. //=================================
  17619. //2. Transaction_End
  17620. //=================================
  17621. //2.1====================================== Current.Import L1 ==============================================
  17622. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17623. {
  17624. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17625. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17626. {
  17627. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17628. {
  17629. tempIndex = ((gun_index==2) ? 1: 0);
  17630. }
  17631. else
  17632. {
  17633. tempIndex = gun_index;
  17634. }
  17635. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17636. {
  17637. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17638. {
  17639. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17640. }
  17641. }// End of for CHAdeMO_QUANTITY
  17642. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17643. }
  17644. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17645. {
  17646. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17647. {
  17648. tempIndex = ((gun_index==2) ? 1: 0);
  17649. }
  17650. else
  17651. {
  17652. tempIndex = gun_index;
  17653. }
  17654. for (int index = 0; index < CCS_QUANTITY; index++)
  17655. {
  17656. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17657. {
  17658. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17659. }
  17660. }// End of for CCS_QUANTITY
  17661. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17662. }
  17663. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17664. {
  17665. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17666. {
  17667. tempIndex = ((gun_index==2) ? 1: 0);
  17668. }
  17669. else
  17670. {
  17671. tempIndex = gun_index;
  17672. }
  17673. for (int index = 0; index < GB_QUANTITY; index++)
  17674. {
  17675. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17676. {
  17677. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17678. }
  17679. }// End of for GB_QUANTITY
  17680. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17681. }
  17682. else if(gunType[gun_index] == GUN_TYPE_DO)
  17683. {
  17684. tempIndex = gun_index;
  17685. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17686. {
  17687. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17688. {
  17689. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17690. }
  17691. }
  17692. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17693. }
  17694. else
  17695. {
  17696. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17697. {
  17698. tempIndex = 2;
  17699. }
  17700. else
  17701. {
  17702. tempIndex = gun_index;
  17703. }
  17704. for (int index = 0; index < AC_QUANTITY; index++)
  17705. {
  17706. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17707. {
  17708. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17709. }
  17710. }// End of for AC_QUANTITY
  17711. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17712. }
  17713. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17714. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17715. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17716. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17717. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17718. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17719. }
  17720. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17721. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17722. {
  17723. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17724. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17725. {
  17726. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17727. {
  17728. tempIndex = ((gun_index==2) ? 1: 0);
  17729. }
  17730. else
  17731. {
  17732. tempIndex = gun_index;
  17733. }
  17734. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17735. {
  17736. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17737. {
  17738. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17739. }
  17740. }// END OF CHAdeMO_QUANTITY
  17741. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17742. }
  17743. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17744. {
  17745. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17746. {
  17747. tempIndex = ((gun_index==2) ? 1: 0);
  17748. }
  17749. else
  17750. {
  17751. tempIndex = gun_index;
  17752. }
  17753. for (int index = 0; index < CCS_QUANTITY; index++)
  17754. {
  17755. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17756. {
  17757. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17758. }
  17759. }// END OF CCS_QUANTITY
  17760. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17761. }
  17762. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17763. {
  17764. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17765. {
  17766. tempIndex = ((gun_index==2) ? 1: 0);
  17767. }
  17768. else
  17769. {
  17770. tempIndex = gun_index;
  17771. }
  17772. for (int index = 0; index < GB_QUANTITY; index++)
  17773. {
  17774. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17775. {
  17776. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17777. }
  17778. }// END OF GB_QUANTITY
  17779. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17780. }
  17781. else if(gunType[gun_index] == GUN_TYPE_DO)
  17782. {
  17783. tempIndex = gun_index;
  17784. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17785. {
  17786. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17787. {
  17788. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17789. }
  17790. }
  17791. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17792. }
  17793. else
  17794. {
  17795. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17796. {
  17797. tempIndex = 2;
  17798. }
  17799. else
  17800. {
  17801. tempIndex = gun_index;
  17802. }
  17803. for (int index = 0; index < AC_QUANTITY; index++)
  17804. {
  17805. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17806. {
  17807. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17808. }
  17809. }// END OF AC_QUANTITY
  17810. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17811. }
  17812. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17813. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17814. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17815. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17816. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17817. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17818. }
  17819. //2.3====================================== Power.Active.Import =========================================
  17820. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17821. {
  17822. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17823. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17824. {
  17825. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17826. {
  17827. tempIndex = ((gun_index==2) ? 1: 0);
  17828. }
  17829. else
  17830. {
  17831. tempIndex = gun_index;
  17832. }
  17833. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17834. {
  17835. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17836. {
  17837. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17838. }
  17839. } // End for CHAdeMO_QUANTITY
  17840. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17841. }
  17842. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17843. {
  17844. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17845. {
  17846. tempIndex = ((gun_index==2) ? 1: 0);
  17847. }
  17848. else
  17849. {
  17850. tempIndex = gun_index;
  17851. }
  17852. for (int index = 0; index < CCS_QUANTITY; index++)
  17853. {
  17854. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17855. {
  17856. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17857. }
  17858. } // END for CCS_QUANTITY
  17859. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17860. }
  17861. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17862. {
  17863. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17864. {
  17865. tempIndex = ((gun_index==2) ? 1: 0);
  17866. }
  17867. else
  17868. {
  17869. tempIndex = gun_index;
  17870. }
  17871. for (int index = 0; index < GB_QUANTITY; index++)
  17872. {
  17873. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17874. {
  17875. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17876. }
  17877. }// END for GB_QUANTITY
  17878. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17879. }
  17880. else if(gunType[gun_index] == GUN_TYPE_DO)
  17881. {
  17882. tempIndex = gun_index;
  17883. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17884. {
  17885. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17886. {
  17887. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17888. }
  17889. }
  17890. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17891. }
  17892. else
  17893. {
  17894. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17895. {
  17896. tempIndex = 2;
  17897. }
  17898. else
  17899. {
  17900. tempIndex = gun_index;
  17901. }
  17902. for (int index = 0; index < AC_QUANTITY; index++)
  17903. {
  17904. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17905. {
  17906. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17907. }
  17908. } // END for AC_QUANTITY
  17909. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17910. }
  17911. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17912. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17913. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17914. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17915. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17916. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17917. }
  17918. //2.4====================================== Voltage L1 ====================================================
  17919. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17920. {
  17921. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17922. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17923. {
  17924. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17925. {
  17926. tempIndex = ((gun_index==2) ? 1: 0);
  17927. }
  17928. else
  17929. {
  17930. tempIndex = gun_index;
  17931. }
  17932. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17933. {
  17934. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17935. {
  17936. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17937. }
  17938. } // END OF FOR CHAdeMO_QUANTITY
  17939. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17940. }
  17941. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17942. {
  17943. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17944. {
  17945. tempIndex = ((gun_index==2) ? 1: 0);
  17946. }
  17947. else
  17948. {
  17949. tempIndex = gun_index;
  17950. }
  17951. for (int index = 0; index < CCS_QUANTITY; index++)
  17952. {
  17953. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17954. {
  17955. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17956. }
  17957. } // END OF FOR CCS_QUANTITY
  17958. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17959. }
  17960. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17961. {
  17962. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17963. {
  17964. tempIndex = ((gun_index==2) ? 1: 0);
  17965. }
  17966. else
  17967. {
  17968. tempIndex = gun_index;
  17969. }
  17970. for (int index = 0; index < GB_QUANTITY; index++)
  17971. {
  17972. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17973. {
  17974. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17975. }
  17976. } // END OF FOR GB_QUANTITY
  17977. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17978. }
  17979. else if(gunType[gun_index] == GUN_TYPE_DO)
  17980. {
  17981. tempIndex = gun_index;
  17982. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17983. {
  17984. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17985. {
  17986. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17987. }
  17988. }
  17989. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17990. }
  17991. else
  17992. {
  17993. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17994. {
  17995. tempIndex = 2;
  17996. }
  17997. else
  17998. {
  17999. tempIndex = gun_index;
  18000. }
  18001. for (int index = 0; index < AC_QUANTITY; index++)
  18002. {
  18003. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18004. {
  18005. 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
  18006. }
  18007. } // END OF FOR AC_QUANTITY
  18008. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18009. }
  18010. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18011. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  18012. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  18013. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18014. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  18015. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18016. }
  18017. //2.5============================================== End SoC =========================================================
  18018. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18019. {
  18020. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18021. 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))
  18022. {
  18023. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18024. {
  18025. tempIndex = ((gun_index==2) ? 1: 0);
  18026. }
  18027. else
  18028. {
  18029. tempIndex = gun_index;
  18030. }
  18031. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18032. {
  18033. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18034. {
  18035. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18036. {
  18037. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  18038. }
  18039. }
  18040. }
  18041. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18042. {
  18043. for (int index = 0; index < CCS_QUANTITY; index++)
  18044. {
  18045. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18046. {
  18047. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  18048. }
  18049. }
  18050. }
  18051. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18052. {
  18053. for (int index = 0; index < GB_QUANTITY; index++)
  18054. {
  18055. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18056. {
  18057. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  18058. }
  18059. }
  18060. }
  18061. else if(gunType[gun_index] == GUN_TYPE_DO)
  18062. {
  18063. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18064. {
  18065. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18066. {
  18067. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  18068. }
  18069. }
  18070. }
  18071. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18072. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  18073. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18074. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  18075. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  18076. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18077. } // END FOR DC CASE
  18078. }
  18079. //2.6====================================== Current.Import L2 ==============================================
  18080. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18081. {
  18082. // AC 3 phase L2 current
  18083. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18084. {
  18085. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18086. {
  18087. tempIndex = 2;
  18088. }
  18089. else
  18090. {
  18091. tempIndex = gun_index;
  18092. }
  18093. for (int index = 0; index < AC_QUANTITY; index++)
  18094. {
  18095. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18096. {
  18097. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  18098. }
  18099. }// End of for AC_QUANTITY
  18100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  18101. }
  18102. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18103. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  18104. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  18105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  18106. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18107. }
  18108. //2.7====================================== Current.Import L3 ==============================================
  18109. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18110. {
  18111. // AC 3 phase L3 current
  18112. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18113. {
  18114. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18115. {
  18116. tempIndex = 2;
  18117. }
  18118. else
  18119. {
  18120. tempIndex = gun_index;
  18121. }
  18122. for (int index = 0; index < AC_QUANTITY; index++)
  18123. {
  18124. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18125. {
  18126. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  18127. }
  18128. }// End of for AC_QUANTITY
  18129. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  18130. }
  18131. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18132. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  18133. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  18134. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  18135. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18136. }
  18137. //2.9====================================== Voltage L2 ====================================================
  18138. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18139. {
  18140. // AC 3 phase L2 volatge
  18141. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18142. {
  18143. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18144. {
  18145. tempIndex = 2;
  18146. }
  18147. else
  18148. {
  18149. tempIndex = gun_index;
  18150. }
  18151. for (int index = 0; index < AC_QUANTITY; index++)
  18152. {
  18153. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18154. {
  18155. 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
  18156. }
  18157. } // END OF FOR AC_QUANTITY
  18158. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  18159. }
  18160. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18161. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18162. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18163. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18164. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18165. }
  18166. //2.10====================================== Voltage L3 ====================================================
  18167. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18168. {
  18169. // AC 3 phase L3 volatge
  18170. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18171. {
  18172. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18173. {
  18174. tempIndex = 2;
  18175. }
  18176. else
  18177. {
  18178. tempIndex = gun_index;
  18179. }
  18180. for (int index = 0; index < AC_QUANTITY; index++)
  18181. {
  18182. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18183. {
  18184. 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
  18185. }
  18186. } // END OF FOR AC_QUANTITY
  18187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18188. }
  18189. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18191. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18192. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18193. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18194. }
  18195. //====================== Start SoC ================================
  18196. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18197. {
  18198. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18199. 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))
  18200. {
  18201. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18202. {
  18203. tempIndex = ((gun_index==2) ? 1: 0);
  18204. }
  18205. else
  18206. {
  18207. tempIndex = gun_index;
  18208. }
  18209. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18210. {
  18211. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18212. {
  18213. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18214. {
  18215. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18216. }
  18217. }
  18218. }
  18219. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18220. {
  18221. for (int index = 0; index < CCS_QUANTITY; index++)
  18222. {
  18223. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18224. {
  18225. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18226. }
  18227. }
  18228. }
  18229. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18230. {
  18231. for (int index = 0; index < GB_QUANTITY; index++)
  18232. {
  18233. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18234. {
  18235. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18236. }
  18237. }
  18238. }
  18239. else if(gunType[gun_index] == GUN_TYPE_DO)
  18240. {
  18241. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18242. {
  18243. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18244. {
  18245. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18246. }
  18247. }
  18248. }
  18249. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18250. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18251. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18252. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18253. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18254. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18255. } // END FOR DC CASE
  18256. }
  18257. //======================================== Message create ==============================================
  18258. json_object *StopTransaction = json_object_new_object();
  18259. json_object *transactionDatas = json_object_new_array();
  18260. json_object *sampledValues = json_object_new_array();
  18261. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  18262. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  18263. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  18264. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  18265. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  18266. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18267. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  18268. {
  18269. json_object *transactionData = json_object_new_object();
  18270. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18271. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18272. {
  18273. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18274. {
  18275. json_object *sampledValue = json_object_new_object();
  18276. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18277. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18278. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18279. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18280. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18281. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18282. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18283. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18284. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18285. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18286. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18287. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18288. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18289. json_object_array_add(sampledValues, sampledValue);
  18290. }
  18291. }
  18292. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18293. json_object_array_add(transactionDatas, transactionData);
  18294. }
  18295. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18296. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18297. ,MESSAGE_TYPE_CALL
  18298. ,guid
  18299. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18300. json_object_put(StopTransaction);
  18301. // Check File "TempStopTransaction" Exist
  18302. if((access(TempStopTransaction,F_OK))!=-1)
  18303. {
  18304. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18305. fclose(fopen(TempStopTransaction, "w"));
  18306. }
  18307. else
  18308. {
  18309. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18310. FILE *log = fopen(TempStopTransaction, "w+");
  18311. if(log == NULL)
  18312. {
  18313. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18314. return ;
  18315. }
  18316. else
  18317. {
  18318. fclose(log);
  18319. }
  18320. }
  18321. //Add TempStopTransaction | Update TempStopTransaction
  18322. // open file for writing
  18323. FILE *outfile;
  18324. outfile = fopen (TempStopTransaction, "a");
  18325. //DEBUG_INFO("data = %s\n", queuedata);
  18326. fputs(queuedata, outfile);
  18327. fputs("\n", outfile);
  18328. fclose (outfile);
  18329. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18330. OCPP_updatePeriodEnergy(gun_index);
  18331. }
  18332. void checkTempStopTransaction(int gun_index)
  18333. {
  18334. FILE *fptr1;
  18335. char ch;
  18336. char str[QUEUE_MESSAGE_LENGTH]={0};
  18337. char guid[37]={0};
  18338. char tempdata[65]={0};
  18339. char connectorStr[2]={0};
  18340. char TempStopTransaction[256];
  18341. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18342. fptr1 = fopen(TempStopTransaction, "r");
  18343. //TempStopTransaction格式: 槍號,StopTransaction封包
  18344. if (!fptr1)
  18345. {
  18346. //printf(" File not found or unable to open the input file!!\n");
  18347. return ;
  18348. }
  18349. ch=fgetc(fptr1);
  18350. //printf(" Now the content of the file %s is : \n",fname);
  18351. rewind(fptr1);
  18352. if(ch!=EOF)
  18353. {
  18354. // copy all contents to the temporary file except the specific line
  18355. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18356. {
  18357. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18358. if(str[0]=='\0')
  18359. {
  18360. break;
  18361. }
  18362. //TempStopTransaction格式: 槍號,StopTransaction封包
  18363. strncpy(connectorStr, str, 1);
  18364. if(atoi(connectorStr) != (gun_index+1))
  18365. {
  18366. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18367. fclose(fptr1);
  18368. return ;
  18369. }
  18370. //random_uuid(guid);
  18371. strncpy(guid, str+6, 36); //copy guid
  18372. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18373. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18374. {
  18375. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18376. }
  18377. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18378. OCPP_insert_transaction_msg(NO, str);
  18379. memset(str,0,ARRAY_SIZE(str));
  18380. }
  18381. }
  18382. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18383. fclose(fptr1);
  18384. remove(TempStopTransaction); // remove the original file
  18385. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18386. }
  18387. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18388. {
  18389. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18390. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18391. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18392. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18393. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18394. }
  18395. int GetWebSocketPingInterval(void)
  18396. {
  18397. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18398. }
  18399. int GetServerSign(void)
  18400. {
  18401. return server_sign;
  18402. }
  18403. uint8_t GetOcppSecurityProfile()
  18404. {
  18405. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18406. }
  18407. void GetOcppChargerBoxId(uint8_t *data)
  18408. {
  18409. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18410. }
  18411. void GetOcppSecurityPassword(uint8_t *data)
  18412. {
  18413. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18414. }
  18415. void SetOcppVersion(uint8_t *version)
  18416. {
  18417. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18418. DEBUG_INFO("ocpp version: %s\n", version);
  18419. if(strstr((char*)version, "ocpp1.6") != NULL)
  18420. {
  18421. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18422. }
  18423. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18424. {
  18425. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18426. system("pkill OcppBackend");
  18427. }
  18428. }
  18429. void SetServerSign(int value)
  18430. {
  18431. server_sign = value;
  18432. }
  18433. int GetBootNotificationInterval(void)
  18434. {
  18435. return BootNotificationInterval;
  18436. }
  18437. int GetInternetConn(void)
  18438. {
  18439. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18440. }
  18441. int GetBackendConnectionTimeout(void)
  18442. {
  18443. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18444. }
  18445. int isConnectorInitMode(int gun_index)
  18446. {
  18447. int tempIndex = 0;
  18448. int result = TRUE;
  18449. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18450. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18451. {
  18452. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18453. {
  18454. tempIndex = ((gun_index==2) ? 1: 0);
  18455. }
  18456. else
  18457. {
  18458. tempIndex = gun_index;
  18459. }
  18460. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18461. {
  18462. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18463. {
  18464. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18465. } //end of the same index
  18466. }//end of for CHAdeMO_QUANTITY
  18467. }
  18468. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18469. {
  18470. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18471. {
  18472. tempIndex = ((gun_index==2) ? 1: 0);
  18473. }
  18474. else
  18475. {
  18476. tempIndex = gun_index;
  18477. }
  18478. for (int index = 0; index < CCS_QUANTITY; index++)
  18479. {
  18480. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18481. {
  18482. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18483. } //end of the same index
  18484. } // end of for CCS_QUANTITY
  18485. }
  18486. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18487. {
  18488. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18489. {
  18490. tempIndex = ((gun_index==2) ? 1: 0);
  18491. }
  18492. else
  18493. {
  18494. tempIndex = gun_index;
  18495. }
  18496. for (int index = 0; index < GB_QUANTITY; index++)
  18497. {
  18498. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18499. {
  18500. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18501. } //end of the same index
  18502. } // end of for GB_QUANTITY
  18503. }
  18504. else if(gunType[gun_index] == GUN_TYPE_DO)
  18505. {
  18506. tempIndex = gun_index;
  18507. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18508. {
  18509. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18510. {
  18511. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18512. } //end of the same index
  18513. }
  18514. }
  18515. else
  18516. {
  18517. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18518. {
  18519. tempIndex = 2;
  18520. }
  18521. else
  18522. {
  18523. tempIndex = gun_index;
  18524. }
  18525. for (int index = 0; index < AC_QUANTITY; index++)
  18526. {
  18527. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18528. {
  18529. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18530. }//end of the same index
  18531. }//end of for AC_QUANTITY
  18532. }
  18533. return result;
  18534. }
  18535. void refreshProcDogTimer()
  18536. {
  18537. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  18538. }
  18539. void InitialSystemValue(void)
  18540. {
  18541. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18542. locallistVersion=0;
  18543. BootNotificationInterval = 0;
  18544. authorizeRetryTimes = 0;
  18545. GunStatusInterval = 10;
  18546. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18547. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18548. //Hear Beat
  18549. HeartBeatWithNOResponse = 0;
  18550. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18551. FirstHeartBeat = 0;
  18552. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18553. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18554. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18555. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18556. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18557. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18558. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18559. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18560. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18561. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18562. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18563. //Status && ConnectorPlugIn Setting
  18564. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18565. {
  18566. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18567. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18568. }
  18569. for (int index = 0; index < CCS_QUANTITY; index++)
  18570. {
  18571. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18572. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18573. }
  18574. for (int index = 0; index < GB_QUANTITY; index++)
  18575. {
  18576. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18577. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18578. }
  18579. for (int index = 0; index < AC_QUANTITY; index++)
  18580. {
  18581. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18582. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18583. }
  18584. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18585. {
  18586. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18587. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18588. }
  18589. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18590. {
  18591. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18592. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18593. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18594. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18595. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18596. }
  18597. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18598. refreshStartTimer(&clientTime.Heartbeat);
  18599. sleep(1);
  18600. }
  18601. void LWS_Send(char *str)
  18602. {
  18603. //=====================================================
  18604. // Check InternetConn 0: disconnected, 1: connected
  18605. //====================================================
  18606. if(GetOcppConnStatus() == 0)
  18607. {
  18608. DEBUG_INFO("offline now !!!\n");
  18609. return;
  18610. }
  18611. // Only disable isWebsocketSendable operation initiated by charger
  18612. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18613. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18614. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18615. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18616. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18617. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18618. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18619. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18620. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18621. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18622. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18623. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18624. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18625. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18626. {
  18627. isWebsocketSendable = 0;
  18628. }
  18629. pthread_mutex_lock(&lock_send);
  18630. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18631. sprintf((char *)SendBuffer, "%s", str);
  18632. SendBufLen = strlen(str);
  18633. pthread_mutex_unlock(&lock_send);
  18634. lws_callback_on_writable(wsi_client);
  18635. //lws_service(context, 0);
  18636. //sleep(1);
  18637. }
  18638. void LWS_SendNow(char *str)
  18639. {
  18640. //=====================================================
  18641. // Check InternetConn 0: disconnected, 1: connected
  18642. //====================================================
  18643. if(GetOcppConnStatus() == 0)
  18644. {
  18645. DEBUG_INFO("offline now !!!\n");
  18646. return;
  18647. }
  18648. // Only disable isWebsocketSendable operation initiated by charger
  18649. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18650. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18651. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18652. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18653. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18654. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18655. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18656. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18657. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18658. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18659. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18660. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18661. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18662. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18663. {
  18664. isWebsocketSendable = 0;
  18665. }
  18666. pthread_mutex_lock(&lock_send);
  18667. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18668. sprintf((char *)SendBuffer, "%s", str);
  18669. SendBufLen = strlen(str);
  18670. pthread_mutex_unlock(&lock_send);
  18671. lws_callback_on_writable(wsi_client);
  18672. lws_service(context, 0);
  18673. //sleep(1);
  18674. }