MessageHandler.c 928 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198
  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)
  1102. {
  1103. int result = PASS;
  1104. char* errMsg = NULL;
  1105. char sqlStr[8192];
  1106. sprintf(sqlStr, "insert into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '0');", txId, creditNo, deductResult, isDonateInvoice, amount, vemData);
  1107. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1108. {
  1109. result = FAIL;
  1110. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  1111. }
  1112. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  1113. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1114. {
  1115. result = FAIL;
  1116. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  1117. }
  1118. return result;
  1119. }
  1120. int OCPP_update_deduct_info(int txId, char *creditNo)
  1121. {
  1122. int result = PASS;
  1123. char* errMsg = NULL;
  1124. char sqlStr[8192];
  1125. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  1126. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1127. {
  1128. result = FAIL;
  1129. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  1130. }
  1131. return result;
  1132. }
  1133. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1134. {
  1135. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1136. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  1137. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s}",
  1138. atoi(columnValue[1]),
  1139. columnValue[2],
  1140. atoi(columnValue[3])==1?"true":"false",
  1141. atoi(columnValue[4])==1?"true":"false",
  1142. columnValue[5]);
  1143. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1144. return 0;
  1145. }
  1146. void OCPP_query_deduct_info()
  1147. {
  1148. int rc = 0;
  1149. char sql[100];
  1150. char zErrMsg[100];
  1151. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1152. /* Execute SQL statement */
  1153. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1154. if( rc != SQLITE_OK )
  1155. {
  1156. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1157. }
  1158. }
  1159. //==========================================
  1160. // Check time passed since today
  1161. //==========================================
  1162. long long DiffTimebWithNow(struct timeb ST)
  1163. {
  1164. //return milli-second
  1165. struct timeb ET;
  1166. long long StartTime,StopTime;
  1167. ftime(&ET);
  1168. StartTime=(long long)ST.time;
  1169. StopTime=(long long)ET.time;
  1170. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1171. }
  1172. int getTimePassSinceToday(uint8_t gun_index)
  1173. {
  1174. int result = -1;
  1175. static time_t lastTime[4];
  1176. time_t t;
  1177. struct tm *tmStartToday;
  1178. struct timeb tbStartToday;
  1179. t=time(NULL);
  1180. if(difftime(t, lastTime[gun_index])>0)
  1181. {
  1182. tmStartToday=localtime(&t);
  1183. tmStartToday->tm_hour = 0;
  1184. tmStartToday->tm_min = 0;
  1185. tmStartToday->tm_sec = 0;
  1186. tbStartToday.time = mktime(tmStartToday);
  1187. tbStartToday.millitm = 0;
  1188. result = DiffTimebWithNow(tbStartToday)/1000;
  1189. lastTime[gun_index] = t;
  1190. }
  1191. return result;
  1192. }
  1193. void getNowDatetime(uint8_t *data)
  1194. {
  1195. time_t t = time(NULL);
  1196. struct tm tm = *localtime(&t);
  1197. 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);
  1198. }
  1199. int syncDateTimeRTC(uint8_t *data)
  1200. {
  1201. struct ParsingResult
  1202. {
  1203. int result;
  1204. int scanedElement;
  1205. int year;
  1206. int month;
  1207. int mday;
  1208. int hour;
  1209. int min;
  1210. int sec;
  1211. int tz_hour;
  1212. int tz_min;
  1213. float minSec;
  1214. }result;
  1215. struct tm tmOrg;
  1216. struct tm *tmTarget;
  1217. struct timeb tbTarget;
  1218. char buf[128];
  1219. memset(&result, 0x00, sizeof(struct ParsingResult));
  1220. result.result = PASS;
  1221. if(strstr((char*)data, ".") != NULL)
  1222. {
  1223. // Original data with mini second
  1224. if(strstr((char*)data, "Z") != NULL)
  1225. {
  1226. // Original data with Z
  1227. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1228. &result.year,
  1229. &result.month,
  1230. &result.mday,
  1231. &result.hour,
  1232. &result.min,
  1233. &result.sec,
  1234. &result.minSec);
  1235. }
  1236. else
  1237. {
  1238. // Original data without Z
  1239. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1240. &result.year,
  1241. &result.month,
  1242. &result.mday,
  1243. &result.hour,
  1244. &result.min,
  1245. &result.sec,
  1246. &result.minSec,
  1247. &result.tz_hour,
  1248. &result.tz_min);
  1249. }
  1250. }
  1251. else
  1252. {
  1253. // Original data without 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:%dZ",
  1258. &result.year,
  1259. &result.month,
  1260. &result.mday,
  1261. &result.hour,
  1262. &result.min,
  1263. &result.sec);
  1264. }
  1265. else
  1266. {
  1267. // Original data without Z
  1268. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1269. &result.year,
  1270. &result.month,
  1271. &result.mday,
  1272. &result.hour,
  1273. &result.min,
  1274. &result.sec,
  1275. &result.tz_hour,
  1276. &result.tz_min);
  1277. }
  1278. }
  1279. tmOrg.tm_year = result.year - 1900;
  1280. tmOrg.tm_mon = result.month - 1;
  1281. tmOrg.tm_mday = result.mday;
  1282. tmOrg.tm_hour = result.hour;
  1283. tmOrg.tm_min = result.min;
  1284. tmOrg.tm_sec = result.sec;
  1285. tmOrg.tm_gmtoff = 0;
  1286. tbTarget.time = mktime(&tmOrg);
  1287. tbTarget.timezone = 0;
  1288. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1289. tmTarget = gmtime(&tbTarget.time);
  1290. 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);
  1291. //DEBUG_INFO(" org date time: %s\n", data);
  1292. //DEBUG_INFO("parse date time: %s\n", buf);
  1293. system(buf);
  1294. system("/sbin/hwclock -w --systohc");
  1295. if(result.scanedElement < 6)
  1296. result.result = FAIL;
  1297. return result.result;
  1298. }
  1299. //==========================================
  1300. // GetCompositeSchedule logic related function
  1301. //==========================================
  1302. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1303. {
  1304. //return milli-second
  1305. unsigned int StartTime,StopTime;
  1306. StartTime=(unsigned int)ST.time;
  1307. StopTime=(unsigned int)ET.time;
  1308. return (StopTime-StartTime);
  1309. }
  1310. int DiffTimebWithNowSec(struct timeb ST)
  1311. {
  1312. //return milli-second
  1313. struct timeb ET;
  1314. unsigned int StartTime,StopTime;
  1315. ftime(&ET);
  1316. StartTime=(unsigned int)ST.time;
  1317. StopTime=(unsigned int)ET.time;
  1318. return (StopTime-StartTime);
  1319. }
  1320. int getStartStop(uint8_t *start, uint8_t *stop)
  1321. {
  1322. int result = -1;
  1323. struct tm tmStart;
  1324. struct timeb tbStart;
  1325. struct tm tmStop;
  1326. struct timeb tbStop;
  1327. 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) &&
  1328. (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))
  1329. {
  1330. //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);
  1331. //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);
  1332. tmStart.tm_year -= 1900;
  1333. tmStart.tm_mon -= 1;
  1334. tbStart.time = mktime(&tmStart);
  1335. tbStart.millitm = 0;
  1336. tmStop.tm_year -= 1900;
  1337. tmStop.tm_mon -= 1;
  1338. tbStop.time = mktime(&tmStop);
  1339. tbStop.millitm = 0;
  1340. result = DiffTimebSec(tbStart, tbStop);
  1341. //DEBUG_INFO("getStartStop(): %d\n", result);
  1342. }
  1343. else
  1344. {
  1345. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1346. }
  1347. return result;
  1348. }
  1349. int isOvertNow(uint8_t *start)
  1350. {
  1351. int result = NO;
  1352. struct ParsingResult
  1353. {
  1354. int result;
  1355. int scanedElement;
  1356. int year;
  1357. int month;
  1358. int mday;
  1359. int hour;
  1360. int min;
  1361. int sec;
  1362. int tz_hour;
  1363. int tz_min;
  1364. float minSec;
  1365. }parsingResult;
  1366. struct tm tmStart;
  1367. struct timeb tbStart;
  1368. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1369. if(strstr((char*)start, ".") != NULL)
  1370. {
  1371. // Original data with mini second
  1372. if(strstr((char*)start, "Z") != NULL)
  1373. {
  1374. // Original data with Z
  1375. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1376. &parsingResult.year,
  1377. &parsingResult.month,
  1378. &parsingResult.mday,
  1379. &parsingResult.hour,
  1380. &parsingResult.min,
  1381. &parsingResult.sec,
  1382. &parsingResult.minSec);
  1383. }
  1384. else
  1385. {
  1386. // Original data without Z
  1387. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1388. &parsingResult.year,
  1389. &parsingResult.month,
  1390. &parsingResult.mday,
  1391. &parsingResult.hour,
  1392. &parsingResult.min,
  1393. &parsingResult.sec,
  1394. &parsingResult.minSec,
  1395. &parsingResult.tz_hour,
  1396. &parsingResult.tz_min);
  1397. }
  1398. }
  1399. else
  1400. {
  1401. // Original data without 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:%dZ",
  1406. &parsingResult.year,
  1407. &parsingResult.month,
  1408. &parsingResult.mday,
  1409. &parsingResult.hour,
  1410. &parsingResult.min,
  1411. &parsingResult.sec);
  1412. }
  1413. else
  1414. {
  1415. // Original data without Z
  1416. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1417. &parsingResult.year,
  1418. &parsingResult.month,
  1419. &parsingResult.mday,
  1420. &parsingResult.hour,
  1421. &parsingResult.min,
  1422. &parsingResult.sec,
  1423. &parsingResult.tz_hour,
  1424. &parsingResult.tz_min);
  1425. }
  1426. }
  1427. if(parsingResult.scanedElement >= 6)
  1428. {
  1429. tmStart.tm_year = parsingResult.year - 1900;
  1430. tmStart.tm_mon = parsingResult.month - 1;
  1431. tmStart.tm_mday = parsingResult.mday;
  1432. tmStart.tm_hour = parsingResult.hour;
  1433. tmStart.tm_min = parsingResult.min;
  1434. tmStart.tm_sec = parsingResult.sec;
  1435. tmStart.tm_gmtoff = 0;
  1436. tbStart.time = mktime(&tmStart);
  1437. tbStart.timezone = 0;
  1438. tbStart.millitm = 0;
  1439. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1440. if(DiffTimebWithNowSec(tbStart) <= 0)
  1441. result = NO;
  1442. else
  1443. result = YES;
  1444. }
  1445. else
  1446. {
  1447. DEBUG_WARN("Start date parsing error.\n");
  1448. }
  1449. return result;
  1450. }
  1451. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1452. {
  1453. int result = -1;
  1454. struct tm tmStart;
  1455. struct timeb tbStart;
  1456. struct tm tmStop;
  1457. struct timeb tbStop;
  1458. 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) &&
  1459. (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))
  1460. {
  1461. tmStart.tm_year -= 1900;
  1462. tmStart.tm_mon -= 1;
  1463. tbStart.time = mktime(&tmStart);
  1464. tbStart.millitm = 0;
  1465. tmStop.tm_year -= 1900;
  1466. tmStop.tm_mon -= 1;
  1467. tbStop.time = mktime(&tmStop);
  1468. tbStop.millitm = 0;
  1469. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1470. }
  1471. return result;
  1472. }
  1473. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1474. {
  1475. FILE *fp;
  1476. char profileFileName[128];
  1477. char *line = NULL;
  1478. size_t len = 0;
  1479. time_t CurrentTime;
  1480. struct tm *tmComposite;
  1481. struct StructChargingProfile maxProfile;
  1482. uint8_t limitMax=0;
  1483. int compositePeriodIdx = 0;
  1484. CurrentTime = time(NULL);
  1485. tmComposite=localtime(&CurrentTime);
  1486. 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);
  1487. if(isUnitA)
  1488. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1489. else
  1490. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1491. compositeProfile->ChargingSchedule.Duration = durationReq;
  1492. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1493. {
  1494. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1495. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1496. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1497. }
  1498. compositeProfile->ChargingProfileId = 0;
  1499. compositeProfile->StackLevel = 99 ;
  1500. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1501. maxProfile.ChargingProfileId = -1;
  1502. maxProfile.ChargingSchedule.Duration = -1;
  1503. system("rm -f /tmp/*.json");
  1504. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1505. // Search max profile
  1506. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1507. if((access(profileFileName, F_OK))!=-1)
  1508. {
  1509. fp = fopen(profileFileName, "r");
  1510. while(getline(&line, &len, fp) != -1)
  1511. {
  1512. json_object *obj = NULL;
  1513. obj = json_tokener_parse(line);
  1514. if(is_error(obj))
  1515. {
  1516. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1517. }
  1518. else
  1519. {
  1520. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1521. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1522. )
  1523. {
  1524. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1525. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1526. )
  1527. {
  1528. struct tm tmFrom, tmTo;
  1529. struct timeb tbFrom, tbTo;
  1530. 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) &&
  1531. (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))
  1532. {
  1533. tmFrom.tm_year -= 1900;
  1534. tmFrom.tm_mon -= 1;
  1535. tbFrom.time = mktime(&tmFrom);
  1536. tmTo.tm_year -= 1900;
  1537. tmTo.tm_mon -= 1;
  1538. tbTo.time = mktime(&tmTo);
  1539. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1540. {
  1541. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1542. {
  1543. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1544. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1545. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1546. }
  1547. maxProfile.ChargingProfileId = -1;
  1548. maxProfile.StackLevel = -1;
  1549. if(maxProfile.ChargingProfileId == -1)
  1550. DEBUG_INFO("MaxProfile found.\n");
  1551. else
  1552. DEBUG_INFO("MaxProfile updated.\n");
  1553. // Required item
  1554. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1555. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1556. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1557. if(isUnitA)
  1558. {
  1559. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1560. 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++)
  1561. {
  1562. 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"));
  1563. 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?
  1564. 3:
  1565. 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")));
  1566. 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")));
  1567. }
  1568. }
  1569. else
  1570. {
  1571. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1572. 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++)
  1573. {
  1574. 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"));
  1575. 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?
  1576. 3:
  1577. 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")));
  1578. 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));
  1579. }
  1580. }
  1581. // Optional item
  1582. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1583. {
  1584. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1585. }
  1586. else
  1587. {
  1588. sprintf((char*)maxProfile.ValidFrom, " ");
  1589. }
  1590. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1591. {
  1592. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1593. }
  1594. else
  1595. {
  1596. sprintf((char*)maxProfile.ValidTo, " ");
  1597. }
  1598. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1599. {
  1600. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1601. }
  1602. else
  1603. {
  1604. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1605. }
  1606. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1607. {
  1608. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1609. }
  1610. else
  1611. {
  1612. maxProfile.TransactionId = -1;
  1613. }
  1614. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1615. {
  1616. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1617. }
  1618. else
  1619. {
  1620. maxProfile.ChargingSchedule.Duration = 86400;
  1621. }
  1622. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1623. {
  1624. 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")));
  1625. }
  1626. else
  1627. {
  1628. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1629. }
  1630. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1631. {
  1632. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1633. }
  1634. else
  1635. {
  1636. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1637. }
  1638. }
  1639. }
  1640. }
  1641. else
  1642. {
  1643. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1644. {
  1645. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1646. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1647. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1648. }
  1649. maxProfile.ChargingProfileId = -1;
  1650. maxProfile.StackLevel = -1;
  1651. if(maxProfile.ChargingProfileId == -1)
  1652. DEBUG_INFO("MaxProfile found.\n");
  1653. else
  1654. DEBUG_INFO("MaxProfile updated.\n");
  1655. // Required item
  1656. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1657. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1658. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1659. if(isUnitA)
  1660. {
  1661. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1662. 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++)
  1663. {
  1664. 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"));
  1665. 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?
  1666. 3:
  1667. 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")));
  1668. 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")));
  1669. }
  1670. }
  1671. else
  1672. {
  1673. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1674. 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++)
  1675. {
  1676. 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"));
  1677. 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?
  1678. 3:
  1679. 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")));
  1680. 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));
  1681. }
  1682. }
  1683. // Optional item
  1684. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1685. {
  1686. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1687. }
  1688. else
  1689. {
  1690. sprintf((char*)maxProfile.ValidFrom, " ");
  1691. }
  1692. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1693. {
  1694. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1695. }
  1696. else
  1697. {
  1698. sprintf((char*)maxProfile.ValidTo, " ");
  1699. }
  1700. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1701. {
  1702. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1703. }
  1704. else
  1705. {
  1706. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1707. }
  1708. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1709. {
  1710. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1711. }
  1712. else
  1713. {
  1714. maxProfile.TransactionId = -1;
  1715. }
  1716. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1717. {
  1718. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1719. }
  1720. else
  1721. {
  1722. maxProfile.ChargingSchedule.Duration = 86400;
  1723. }
  1724. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1725. {
  1726. 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")));
  1727. }
  1728. else
  1729. {
  1730. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1731. }
  1732. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1733. {
  1734. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1735. }
  1736. else
  1737. {
  1738. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1739. }
  1740. }
  1741. }
  1742. }
  1743. json_object_put(obj);
  1744. }
  1745. fclose(fp);
  1746. /*
  1747. if(maxProfile.ChargingProfileId !=-1)
  1748. {
  1749. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1750. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1751. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1752. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1753. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1754. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1755. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1756. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1757. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1758. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1759. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1760. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1761. {
  1762. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1763. {
  1764. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1765. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1766. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1767. }
  1768. }
  1769. }
  1770. else
  1771. DEBUG_INFO("MaxProfile not found.\n");
  1772. DEBUG_INFO("------------------------------------\n");*/
  1773. }
  1774. if(maxProfile.ChargingProfileId != -1)
  1775. {
  1776. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1777. {
  1778. if(maxProfile.ChargingSchedule.Duration != -1)
  1779. {
  1780. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1781. 0:
  1782. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1783. }
  1784. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1785. {
  1786. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1787. {
  1788. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1789. 0:
  1790. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1791. if(idxPeriod > 0)
  1792. {
  1793. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1794. {
  1795. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1796. }
  1797. }
  1798. }
  1799. }
  1800. }
  1801. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1802. {
  1803. if(maxProfile.ChargingSchedule.Duration != -1)
  1804. {
  1805. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1806. }
  1807. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1808. {
  1809. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1810. {
  1811. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1812. if(idxPeriod > 0)
  1813. {
  1814. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1815. {
  1816. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1817. }
  1818. }
  1819. }
  1820. }
  1821. }
  1822. else
  1823. {
  1824. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1825. {
  1826. if(maxProfile.ChargingSchedule.Duration != -1)
  1827. {
  1828. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1829. 0:
  1830. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1831. }
  1832. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1833. {
  1834. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1835. {
  1836. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1837. 0:
  1838. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1839. if(idxPeriod > 0)
  1840. {
  1841. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1842. {
  1843. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1844. }
  1845. }
  1846. }
  1847. }
  1848. }
  1849. else
  1850. {
  1851. if(maxProfile.ChargingSchedule.Duration != -1)
  1852. {
  1853. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1854. 0:
  1855. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1856. }
  1857. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1858. {
  1859. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1860. {
  1861. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1862. 0:
  1863. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1864. if(idxPeriod > 0)
  1865. {
  1866. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1867. {
  1868. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1869. }
  1870. }
  1871. }
  1872. }
  1873. }
  1874. }
  1875. /*
  1876. DEBUG_INFO("MaxProfile after align.\n");
  1877. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1878. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1879. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1880. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1881. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1882. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1883. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1884. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1885. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1886. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1887. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1888. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1889. {
  1890. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1891. {
  1892. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1893. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1894. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1895. }
  1896. }
  1897. DEBUG_INFO("------------------------------------\n");*/
  1898. }
  1899. // Find each profile period quantity
  1900. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1901. {
  1902. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1903. limitMax = idx+1;
  1904. }
  1905. if(maxProfile.ChargingProfileId != -1)
  1906. {
  1907. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1908. {
  1909. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1910. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1911. (maxProfile.ChargingSchedule.Duration > 0))
  1912. {
  1913. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1914. {
  1915. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1916. compositePeriodIdx++;
  1917. }
  1918. else
  1919. {
  1920. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1921. }
  1922. }
  1923. }
  1924. }
  1925. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1926. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1927. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1928. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1929. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1930. {
  1931. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1932. {
  1933. compositeProfile->ChargingProfileId = 1;
  1934. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1935. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1936. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1937. }
  1938. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1939. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1940. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1941. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1942. }
  1943. if(line)
  1944. free(line);
  1945. }
  1946. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1947. {
  1948. FILE *fp;
  1949. char profileFileName[128];
  1950. char *line = NULL;
  1951. size_t len = 0;
  1952. time_t CurrentTime;
  1953. struct tm *tmComposite;
  1954. struct StructChargingProfile maxProfile;
  1955. struct StructChargingProfile defaultTxProfile;
  1956. struct StructChargingProfile txProfile;
  1957. struct StructChargingSchedulePeriod tmpPeriod;
  1958. uint8_t limitMax=0;
  1959. uint8_t limitDef=0;
  1960. uint8_t limitTx=0;
  1961. int compositePeriodIdx = 0;
  1962. CurrentTime = time(NULL);
  1963. tmComposite=localtime(&CurrentTime);
  1964. 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);
  1965. if(isUnitA)
  1966. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1967. else
  1968. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1969. compositeProfile->ChargingSchedule.Duration = durationReq;
  1970. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1971. {
  1972. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1973. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1974. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1975. }
  1976. compositeProfile->ChargingProfileId = 0;
  1977. compositeProfile->StackLevel = 99 ;
  1978. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1979. maxProfile.ChargingProfileId = -1;
  1980. defaultTxProfile.ChargingProfileId = -1;
  1981. txProfile.ChargingProfileId = -1;
  1982. maxProfile.ChargingSchedule.Duration = -1;
  1983. defaultTxProfile.ChargingSchedule.Duration = -1;
  1984. txProfile.ChargingSchedule.Duration = -1;
  1985. system("rm -f /tmp/*.json");
  1986. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1987. /*
  1988. * Search valid charging profile
  1989. */
  1990. //DEBUG_INFO("====================================\n");
  1991. // Search tx profile
  1992. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1993. if((access(profileFileName, F_OK))!=-1)
  1994. {
  1995. fp = fopen(profileFileName, "r");
  1996. while(getline(&line, &len, fp) != -1)
  1997. {
  1998. json_object *obj = NULL;
  1999. obj = json_tokener_parse(line);
  2000. if(is_error(obj))
  2001. {
  2002. DEBUG_ERROR("Parse txProfile from file error.\n");
  2003. }
  2004. else
  2005. {
  2006. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2007. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2008. )
  2009. {
  2010. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2011. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2012. )
  2013. {
  2014. struct tm tmFrom, tmTo;
  2015. struct timeb tbFrom, tbTo;
  2016. 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) &&
  2017. (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))
  2018. {
  2019. tmFrom.tm_year -= 1900;
  2020. tmFrom.tm_mon -= 1;
  2021. tbFrom.time = mktime(&tmFrom);
  2022. tmTo.tm_year -= 1900;
  2023. tmTo.tm_mon -= 1;
  2024. tbTo.time = mktime(&tmTo);
  2025. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2026. {
  2027. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2028. {
  2029. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2030. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2031. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2032. }
  2033. txProfile.ChargingProfileId = -1;
  2034. txProfile.StackLevel = -1;
  2035. if(txProfile.ChargingProfileId == -1)
  2036. DEBUG_INFO("TxProfile found.\n");
  2037. else
  2038. DEBUG_INFO("TxProfile updated.\n");
  2039. // Required item
  2040. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2041. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2042. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2043. if(isUnitA)
  2044. {
  2045. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2046. 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++)
  2047. {
  2048. 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"));
  2049. 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?
  2050. 3:
  2051. 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")));
  2052. 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")));
  2053. }
  2054. }
  2055. else
  2056. {
  2057. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2058. 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++)
  2059. {
  2060. 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"));
  2061. 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?
  2062. 3:
  2063. 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")));
  2064. 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));
  2065. }
  2066. }
  2067. // Optional item
  2068. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2069. {
  2070. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2071. }
  2072. else
  2073. {
  2074. sprintf((char*)txProfile.ValidFrom, " ");
  2075. }
  2076. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2077. {
  2078. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2079. }
  2080. else
  2081. {
  2082. sprintf((char*)txProfile.ValidTo, " ");
  2083. }
  2084. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2085. {
  2086. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2087. }
  2088. else
  2089. {
  2090. sprintf((char*)txProfile.RecurrencyKind, " ");
  2091. }
  2092. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2093. {
  2094. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2095. }
  2096. else
  2097. {
  2098. txProfile.TransactionId = -1;
  2099. }
  2100. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2101. {
  2102. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2103. }
  2104. else
  2105. {
  2106. txProfile.ChargingSchedule.Duration = 86400;
  2107. }
  2108. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2109. {
  2110. 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")));
  2111. }
  2112. else
  2113. {
  2114. 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));
  2115. }
  2116. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2117. {
  2118. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2119. }
  2120. else
  2121. {
  2122. txProfile.ChargingSchedule.MinChargingRate = -1;
  2123. }
  2124. }
  2125. }
  2126. }
  2127. else
  2128. {
  2129. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2130. {
  2131. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2132. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2133. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2134. }
  2135. txProfile.ChargingProfileId = -1;
  2136. txProfile.StackLevel = -1;
  2137. if(txProfile.ChargingProfileId == -1)
  2138. DEBUG_INFO("TxProfile found.\n");
  2139. else
  2140. DEBUG_INFO("TxProfile updated.\n");
  2141. // Required item
  2142. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2143. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2144. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2145. if(isUnitA)
  2146. {
  2147. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2148. 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++)
  2149. {
  2150. 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"));
  2151. 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?
  2152. 3:
  2153. 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")));
  2154. 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")));
  2155. }
  2156. }
  2157. else
  2158. {
  2159. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2160. 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++)
  2161. {
  2162. 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"));
  2163. 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?
  2164. 3:
  2165. 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")));
  2166. 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));
  2167. }
  2168. }
  2169. // Optional item
  2170. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2171. {
  2172. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2173. }
  2174. else
  2175. {
  2176. sprintf((char*)txProfile.ValidFrom, " ");
  2177. }
  2178. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2179. {
  2180. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2181. }
  2182. else
  2183. {
  2184. sprintf((char*)txProfile.ValidTo, " ");
  2185. }
  2186. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2187. {
  2188. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2189. }
  2190. else
  2191. {
  2192. sprintf((char*)txProfile.RecurrencyKind, " ");
  2193. }
  2194. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2195. {
  2196. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2197. }
  2198. else
  2199. {
  2200. txProfile.TransactionId = -1;
  2201. }
  2202. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2203. {
  2204. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2205. }
  2206. else
  2207. {
  2208. txProfile.ChargingSchedule.Duration = 86400;
  2209. }
  2210. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2211. {
  2212. 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")));
  2213. }
  2214. else
  2215. {
  2216. 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));
  2217. }
  2218. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2219. {
  2220. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2221. }
  2222. else
  2223. {
  2224. txProfile.ChargingSchedule.MinChargingRate = -1;
  2225. }
  2226. }
  2227. }
  2228. }
  2229. json_object_put(obj);
  2230. }
  2231. fclose(fp);
  2232. /*
  2233. if(txProfile.ChargingProfileId != -1)
  2234. {
  2235. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2236. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2237. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2238. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2239. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2240. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2241. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2242. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2243. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2244. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2245. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2246. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2247. {
  2248. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2249. {
  2250. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2251. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2252. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2253. }
  2254. }
  2255. }
  2256. else
  2257. DEBUG_INFO("TxProfile not found.\n");*/
  2258. }
  2259. // Search default tx profile
  2260. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2261. if((access(profileFileName, F_OK))==-1)
  2262. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2263. if((access(profileFileName, F_OK))!=-1)
  2264. {
  2265. fp = fopen(profileFileName, "r");
  2266. while(getline(&line, &len, fp) != -1)
  2267. {
  2268. json_object *obj = NULL;
  2269. obj = json_tokener_parse(line);
  2270. if(is_error(obj))
  2271. {
  2272. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2273. }
  2274. else
  2275. {
  2276. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2277. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2278. )
  2279. {
  2280. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2281. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2282. )
  2283. {
  2284. struct tm tmFrom, tmTo;
  2285. struct timeb tbFrom, tbTo;
  2286. 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) &&
  2287. (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))
  2288. {
  2289. tmFrom.tm_year -= 1900;
  2290. tmFrom.tm_mon -= 1;
  2291. tbFrom.time = mktime(&tmFrom);
  2292. tmTo.tm_year -= 1900;
  2293. tmTo.tm_mon -= 1;
  2294. tbTo.time = mktime(&tmTo);
  2295. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2296. {
  2297. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2298. {
  2299. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2300. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2301. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2302. }
  2303. defaultTxProfile.ChargingProfileId = -1;
  2304. defaultTxProfile.StackLevel = -1;
  2305. if(defaultTxProfile.ChargingProfileId == -1)
  2306. DEBUG_INFO("TxDefaultProfile found.\n");
  2307. else
  2308. DEBUG_INFO("TxDefaultProfile updated.\n");
  2309. // Required item
  2310. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2311. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2312. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2313. if(isUnitA)
  2314. {
  2315. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2316. 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++)
  2317. {
  2318. 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"));
  2319. 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?
  2320. 3:
  2321. 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")));
  2322. 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")));
  2323. }
  2324. }
  2325. else
  2326. {
  2327. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2328. 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++)
  2329. {
  2330. 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"));
  2331. 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?
  2332. 3:
  2333. 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")));
  2334. 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));
  2335. }
  2336. }
  2337. // Optional item
  2338. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2339. {
  2340. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2341. }
  2342. else
  2343. {
  2344. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2345. }
  2346. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2347. {
  2348. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2349. }
  2350. else
  2351. {
  2352. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2353. }
  2354. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2355. {
  2356. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2357. }
  2358. else
  2359. {
  2360. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2361. }
  2362. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2363. {
  2364. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2365. }
  2366. else
  2367. {
  2368. defaultTxProfile.TransactionId = -1;
  2369. }
  2370. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2371. {
  2372. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2373. }
  2374. else
  2375. {
  2376. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2377. }
  2378. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2379. {
  2380. 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")));
  2381. }
  2382. else
  2383. {
  2384. 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));
  2385. }
  2386. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2387. {
  2388. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2389. }
  2390. else
  2391. {
  2392. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2393. }
  2394. }
  2395. }
  2396. }
  2397. else
  2398. {
  2399. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2400. {
  2401. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2402. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2403. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2404. }
  2405. defaultTxProfile.ChargingProfileId = -1;
  2406. defaultTxProfile.StackLevel = -1;
  2407. if(defaultTxProfile.ChargingProfileId == -1)
  2408. DEBUG_INFO("TxDefaultProfile found.\n");
  2409. else
  2410. DEBUG_INFO("TxDefaultProfile updated.\n");
  2411. // Required item
  2412. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2413. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2414. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2415. if(isUnitA)
  2416. {
  2417. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2418. 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++)
  2419. {
  2420. 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"));
  2421. 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?
  2422. 3:
  2423. 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")));
  2424. 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")));
  2425. }
  2426. }
  2427. else
  2428. {
  2429. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2430. 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++)
  2431. {
  2432. 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"));
  2433. 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?
  2434. 3:
  2435. 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")));
  2436. 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));
  2437. }
  2438. }
  2439. // Optional item
  2440. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2441. {
  2442. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2443. }
  2444. else
  2445. {
  2446. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2447. }
  2448. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2449. {
  2450. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2451. }
  2452. else
  2453. {
  2454. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2455. }
  2456. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2457. {
  2458. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2459. }
  2460. else
  2461. {
  2462. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2463. }
  2464. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2465. {
  2466. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2467. }
  2468. else
  2469. {
  2470. defaultTxProfile.TransactionId = -1;
  2471. }
  2472. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2473. {
  2474. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2475. }
  2476. else
  2477. {
  2478. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2479. }
  2480. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2481. {
  2482. 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")));
  2483. }
  2484. else
  2485. {
  2486. 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));
  2487. }
  2488. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2489. {
  2490. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2491. }
  2492. else
  2493. {
  2494. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2495. }
  2496. }
  2497. }
  2498. }
  2499. json_object_put(obj);
  2500. }
  2501. fclose(fp);
  2502. /*
  2503. if(defaultTxProfile.ChargingProfileId != -1)
  2504. {
  2505. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2506. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2507. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2508. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2509. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2510. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2511. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2512. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2513. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2514. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2515. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2516. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2517. {
  2518. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2519. {
  2520. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2521. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2522. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2523. }
  2524. }
  2525. }
  2526. else
  2527. DEBUG_INFO("TxDefaultProfile not found.\n");
  2528. DEBUG_INFO("------------------------------------\n");*/
  2529. }
  2530. // Search max profile
  2531. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2532. if((access(profileFileName, F_OK))!=-1)
  2533. {
  2534. fp = fopen(profileFileName, "r");
  2535. while(getline(&line, &len, fp) != -1)
  2536. {
  2537. json_object *obj = NULL;
  2538. obj = json_tokener_parse(line);
  2539. if(is_error(obj))
  2540. {
  2541. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2542. }
  2543. else
  2544. {
  2545. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2546. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2547. )
  2548. {
  2549. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2550. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2551. )
  2552. {
  2553. struct tm tmFrom, tmTo;
  2554. struct timeb tbFrom, tbTo;
  2555. 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) &&
  2556. (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))
  2557. {
  2558. tmFrom.tm_year -= 1900;
  2559. tmFrom.tm_mon -= 1;
  2560. tbFrom.time = mktime(&tmFrom);
  2561. tmTo.tm_year -= 1900;
  2562. tmTo.tm_mon -= 1;
  2563. tbTo.time = mktime(&tmTo);
  2564. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2565. {
  2566. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2567. {
  2568. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2569. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2570. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2571. }
  2572. maxProfile.ChargingProfileId = -1;
  2573. maxProfile.StackLevel = -1;
  2574. if(maxProfile.ChargingProfileId == -1)
  2575. DEBUG_INFO("MaxProfile found.\n");
  2576. else
  2577. DEBUG_INFO("MaxProfile updated.\n");
  2578. // Required item
  2579. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2580. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2581. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2582. if(isUnitA)
  2583. {
  2584. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2585. 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++)
  2586. {
  2587. 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"));
  2588. 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?
  2589. 3:
  2590. 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")));
  2591. 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")));
  2592. }
  2593. }
  2594. else
  2595. {
  2596. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2597. 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++)
  2598. {
  2599. 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"));
  2600. 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?
  2601. 3:
  2602. 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")));
  2603. 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));
  2604. }
  2605. }
  2606. // Optional item
  2607. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2608. {
  2609. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2610. }
  2611. else
  2612. {
  2613. sprintf((char*)maxProfile.ValidFrom, " ");
  2614. }
  2615. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2616. {
  2617. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2618. }
  2619. else
  2620. {
  2621. sprintf((char*)maxProfile.ValidTo, " ");
  2622. }
  2623. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2624. {
  2625. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2626. }
  2627. else
  2628. {
  2629. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2630. }
  2631. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2632. {
  2633. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2634. }
  2635. else
  2636. {
  2637. maxProfile.TransactionId = -1;
  2638. }
  2639. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2640. {
  2641. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2642. }
  2643. else
  2644. {
  2645. maxProfile.ChargingSchedule.Duration = 86400;
  2646. }
  2647. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2648. {
  2649. 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")));
  2650. }
  2651. else
  2652. {
  2653. 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));
  2654. }
  2655. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2656. {
  2657. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2658. }
  2659. else
  2660. {
  2661. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2662. }
  2663. }
  2664. }
  2665. }
  2666. else
  2667. {
  2668. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2669. {
  2670. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2671. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2672. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2673. }
  2674. maxProfile.ChargingProfileId = -1;
  2675. maxProfile.StackLevel = -1;
  2676. if(maxProfile.ChargingProfileId == -1)
  2677. DEBUG_INFO("MaxProfile found.\n");
  2678. else
  2679. DEBUG_INFO("MaxProfile updated.\n");
  2680. // Required item
  2681. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2682. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2683. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2684. if(isUnitA)
  2685. {
  2686. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2687. 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++)
  2688. {
  2689. 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"));
  2690. 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?
  2691. 3:
  2692. 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")));
  2693. 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")));
  2694. }
  2695. }
  2696. else
  2697. {
  2698. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2699. 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++)
  2700. {
  2701. 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"));
  2702. 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?
  2703. 3:
  2704. 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")));
  2705. 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));
  2706. }
  2707. }
  2708. // Optional item
  2709. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2710. {
  2711. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2712. }
  2713. else
  2714. {
  2715. sprintf((char*)maxProfile.ValidFrom, " ");
  2716. }
  2717. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2718. {
  2719. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2720. }
  2721. else
  2722. {
  2723. sprintf((char*)maxProfile.ValidTo, " ");
  2724. }
  2725. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2726. {
  2727. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2728. }
  2729. else
  2730. {
  2731. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2732. }
  2733. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2734. {
  2735. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2736. }
  2737. else
  2738. {
  2739. maxProfile.TransactionId = -1;
  2740. }
  2741. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2742. {
  2743. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2744. }
  2745. else
  2746. {
  2747. maxProfile.ChargingSchedule.Duration = 86400;
  2748. }
  2749. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2750. {
  2751. 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")));
  2752. }
  2753. else
  2754. {
  2755. 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));
  2756. }
  2757. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2758. {
  2759. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2760. }
  2761. else
  2762. {
  2763. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2764. }
  2765. }
  2766. }
  2767. }
  2768. json_object_put(obj);
  2769. }
  2770. fclose(fp);
  2771. /*
  2772. if(maxProfile.ChargingProfileId !=-1)
  2773. {
  2774. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2775. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2776. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2777. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2778. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2779. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2780. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2781. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2782. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2783. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2784. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2785. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2786. {
  2787. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2788. {
  2789. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2790. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2791. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2792. }
  2793. }
  2794. }
  2795. else
  2796. DEBUG_INFO("MaxProfile not found.\n");
  2797. DEBUG_INFO("------------------------------------\n");*/
  2798. }
  2799. /*
  2800. * Align found profile start schedule & periods
  2801. */
  2802. //DEBUG_INFO("====================================\n");
  2803. /*
  2804. // For local test usage, force modify found profile start schedule info
  2805. 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);
  2806. 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);
  2807. 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);
  2808. */
  2809. if(txProfile.ChargingProfileId != -1)
  2810. {
  2811. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2812. {
  2813. if(txProfile.ChargingSchedule.Duration != -1)
  2814. {
  2815. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2816. 0:
  2817. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2818. }
  2819. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2820. {
  2821. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2822. {
  2823. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2824. 0:
  2825. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2826. if(idxPeriod > 0)
  2827. {
  2828. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2829. {
  2830. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2831. }
  2832. }
  2833. }
  2834. }
  2835. }
  2836. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2837. {
  2838. if(txProfile.ChargingSchedule.Duration != -1)
  2839. {
  2840. 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?
  2841. 0:
  2842. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2843. }
  2844. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2845. {
  2846. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2847. {
  2848. 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?
  2849. 0:
  2850. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2851. if(idxPeriod > 0)
  2852. {
  2853. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2854. {
  2855. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2856. }
  2857. }
  2858. }
  2859. }
  2860. }
  2861. else
  2862. {
  2863. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2864. {
  2865. if(txProfile.ChargingSchedule.Duration != -1)
  2866. {
  2867. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2868. 0:
  2869. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2870. }
  2871. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2872. {
  2873. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2874. {
  2875. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2876. 0:
  2877. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2878. if(idxPeriod > 0)
  2879. {
  2880. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2881. {
  2882. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2883. }
  2884. }
  2885. }
  2886. }
  2887. }
  2888. else
  2889. {
  2890. if(txProfile.ChargingSchedule.Duration != -1)
  2891. {
  2892. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2893. 0:
  2894. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2895. }
  2896. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2897. {
  2898. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2899. {
  2900. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2901. 0:
  2902. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2903. if(idxPeriod > 0)
  2904. {
  2905. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2906. {
  2907. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2908. }
  2909. }
  2910. }
  2911. }
  2912. }
  2913. }
  2914. /*
  2915. DEBUG_INFO("txProfile after align.\n");
  2916. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2917. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2918. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2919. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2920. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2921. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2922. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2923. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2924. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2925. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2926. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2927. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2928. {
  2929. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2930. {
  2931. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2932. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2933. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2934. }
  2935. }*/
  2936. }
  2937. if(defaultTxProfile.ChargingProfileId != -1)
  2938. {
  2939. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2940. {
  2941. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2942. {
  2943. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2944. 0:
  2945. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2946. }
  2947. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2948. {
  2949. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2950. {
  2951. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2952. 0:
  2953. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2954. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2955. {
  2956. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2957. }
  2958. if(idxPeriod > 0)
  2959. {
  2960. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2961. {
  2962. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2963. }
  2964. }
  2965. }
  2966. }
  2967. }
  2968. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2969. {
  2970. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2971. {
  2972. 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?
  2973. 0:
  2974. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2975. }
  2976. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2977. {
  2978. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2979. {
  2980. 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?
  2981. 0:
  2982. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2983. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2984. {
  2985. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2986. }
  2987. if(idxPeriod > 0)
  2988. {
  2989. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2990. {
  2991. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2992. }
  2993. }
  2994. }
  2995. }
  2996. }
  2997. else
  2998. {
  2999. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3000. {
  3001. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3002. {
  3003. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  3004. 0:
  3005. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  3006. }
  3007. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3008. {
  3009. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3010. {
  3011. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  3012. 0:
  3013. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  3014. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  3015. {
  3016. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3017. }
  3018. if(idxPeriod > 0)
  3019. {
  3020. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3021. {
  3022. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3023. }
  3024. }
  3025. }
  3026. }
  3027. }
  3028. else
  3029. {
  3030. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3031. {
  3032. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  3033. 0:
  3034. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  3035. }
  3036. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3037. {
  3038. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3039. {
  3040. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  3041. 0:
  3042. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  3043. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  3044. {
  3045. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3046. }
  3047. if(idxPeriod > 0)
  3048. {
  3049. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3050. {
  3051. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3052. }
  3053. }
  3054. }
  3055. }
  3056. }
  3057. }
  3058. /*
  3059. DEBUG_INFO("defaultTxProfile after align.\n");
  3060. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3061. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3062. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3063. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3064. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3065. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3066. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3067. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3068. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3069. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3070. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3071. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3072. {
  3073. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3074. {
  3075. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3076. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3077. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3078. }
  3079. }
  3080. DEBUG_INFO("------------------------------------\n");*/
  3081. }
  3082. if(maxProfile.ChargingProfileId != -1)
  3083. {
  3084. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3085. {
  3086. if(maxProfile.ChargingSchedule.Duration != -1)
  3087. {
  3088. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  3089. 0:
  3090. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  3091. }
  3092. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3093. {
  3094. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3095. {
  3096. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  3097. 0:
  3098. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  3099. if(idxPeriod > 0)
  3100. {
  3101. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3102. {
  3103. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3104. }
  3105. }
  3106. }
  3107. }
  3108. }
  3109. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3110. {
  3111. if(maxProfile.ChargingSchedule.Duration != -1)
  3112. {
  3113. 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?
  3114. 0:
  3115. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  3116. }
  3117. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3118. {
  3119. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3120. {
  3121. 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?
  3122. 0:
  3123. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  3124. if(idxPeriod > 0)
  3125. {
  3126. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3127. {
  3128. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3129. }
  3130. }
  3131. }
  3132. }
  3133. }
  3134. else
  3135. {
  3136. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3137. {
  3138. if(maxProfile.ChargingSchedule.Duration != -1)
  3139. {
  3140. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  3141. 0:
  3142. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  3143. }
  3144. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3145. {
  3146. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3147. {
  3148. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  3149. 0:
  3150. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  3151. if(idxPeriod > 0)
  3152. {
  3153. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3154. {
  3155. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3156. }
  3157. }
  3158. }
  3159. }
  3160. }
  3161. else
  3162. {
  3163. if(maxProfile.ChargingSchedule.Duration != -1)
  3164. {
  3165. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  3166. 0:
  3167. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  3168. }
  3169. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3170. {
  3171. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3172. {
  3173. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  3174. 0:
  3175. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  3176. if(idxPeriod > 0)
  3177. {
  3178. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3179. {
  3180. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3181. }
  3182. }
  3183. }
  3184. }
  3185. }
  3186. }
  3187. /*
  3188. DEBUG_INFO("MaxProfile after align.\n");
  3189. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3190. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3191. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3192. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3193. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3194. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3195. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3196. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3197. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3198. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3199. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3200. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3201. {
  3202. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3203. {
  3204. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3205. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3206. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3207. }
  3208. }
  3209. DEBUG_INFO("------------------------------------\n");*/
  3210. }
  3211. /*
  3212. * Merge to conposite schedule
  3213. */
  3214. //DEBUG_INFO("====================================\n");
  3215. // Find each profile period quantity
  3216. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3217. {
  3218. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3219. limitMax = idx+1;
  3220. }
  3221. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3222. {
  3223. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3224. limitDef = idx+1;
  3225. }
  3226. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3227. {
  3228. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3229. limitTx = idx+1;
  3230. }
  3231. // TxProfile found, composite schedule based on it
  3232. if(txProfile.ChargingProfileId != -1)
  3233. {
  3234. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3235. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3236. {
  3237. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3238. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3239. (txProfile.ChargingSchedule.Duration > 0))
  3240. {
  3241. if(maxProfile.ChargingProfileId != -1)
  3242. {
  3243. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3244. {
  3245. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3246. {
  3247. if((maxProfile.ChargingSchedule.Duration > 0))
  3248. {
  3249. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3250. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3251. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3252. }
  3253. else
  3254. {
  3255. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3256. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3257. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3258. }
  3259. }
  3260. if(idxMaxPeriod == (limitMax-1))
  3261. {
  3262. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3263. {
  3264. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3265. {
  3266. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3267. compositePeriodIdx++;
  3268. }
  3269. else
  3270. {
  3271. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3272. }
  3273. }
  3274. }
  3275. }
  3276. }
  3277. else
  3278. {
  3279. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3280. {
  3281. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3282. compositePeriodIdx++;
  3283. }
  3284. else
  3285. {
  3286. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3287. }
  3288. }
  3289. }
  3290. if(idxTxPeriod == (limitTx-1))
  3291. {
  3292. if(defaultTxProfile.ChargingProfileId != -1)
  3293. {
  3294. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  3295. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3296. {
  3297. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3298. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3299. (defaultTxProfile.ChargingSchedule.Duration>0))
  3300. {
  3301. if(maxProfile.ChargingProfileId != -1)
  3302. {
  3303. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3304. {
  3305. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3306. {
  3307. if((maxProfile.ChargingSchedule.Duration > 0))
  3308. {
  3309. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3310. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3311. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3312. }
  3313. else
  3314. {
  3315. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3316. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3317. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3318. }
  3319. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3320. {
  3321. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3322. {
  3323. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3324. compositePeriodIdx++;
  3325. }
  3326. else
  3327. {
  3328. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3329. }
  3330. }
  3331. // Delete duplicate period
  3332. if(compositePeriodIdx > 1)
  3333. {
  3334. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3335. {
  3336. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3337. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3338. compositePeriodIdx -= 1;
  3339. }
  3340. }
  3341. }
  3342. else
  3343. {
  3344. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3345. {
  3346. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3347. compositePeriodIdx++;
  3348. }
  3349. else
  3350. {
  3351. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3352. }
  3353. break;
  3354. }
  3355. }
  3356. }
  3357. else
  3358. {
  3359. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3360. {
  3361. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3362. compositePeriodIdx++;
  3363. }
  3364. else
  3365. {
  3366. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3367. }
  3368. }
  3369. }
  3370. }
  3371. }
  3372. }
  3373. }
  3374. }
  3375. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3376. else if(defaultTxProfile.ChargingProfileId != -1)
  3377. {
  3378. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3379. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3380. {
  3381. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3382. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3383. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3384. {
  3385. if(maxProfile.ChargingProfileId != -1)
  3386. {
  3387. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3388. {
  3389. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3390. {
  3391. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3392. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3393. if((maxProfile.ChargingSchedule.Duration > 0))
  3394. {
  3395. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3396. }
  3397. else
  3398. {
  3399. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3400. }
  3401. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3402. {
  3403. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3404. {
  3405. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3406. compositePeriodIdx++;
  3407. }
  3408. else
  3409. {
  3410. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3411. }
  3412. }
  3413. // Delete duplicate period
  3414. if(compositePeriodIdx > 1)
  3415. {
  3416. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3417. {
  3418. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3419. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3420. compositePeriodIdx -= 1;
  3421. }
  3422. }
  3423. }
  3424. else
  3425. {
  3426. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3427. {
  3428. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3429. compositePeriodIdx++;
  3430. }
  3431. else
  3432. {
  3433. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3434. }
  3435. break;
  3436. }
  3437. }
  3438. }
  3439. else
  3440. {
  3441. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3442. {
  3443. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3444. compositePeriodIdx++;
  3445. }
  3446. else
  3447. {
  3448. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3449. }
  3450. }
  3451. }
  3452. }
  3453. }
  3454. // Fill other period by MaxProfile
  3455. if(maxProfile.ChargingProfileId != -1)
  3456. {
  3457. if(compositePeriodIdx==0)
  3458. {
  3459. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3460. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3461. {
  3462. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3463. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3464. (maxProfile.ChargingSchedule.Duration > 0))
  3465. {
  3466. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3467. {
  3468. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3469. compositePeriodIdx++;
  3470. }
  3471. else
  3472. {
  3473. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3474. }
  3475. }
  3476. }
  3477. }
  3478. else
  3479. {
  3480. int lastCompositePeriodIdx = compositePeriodIdx;
  3481. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3482. {
  3483. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3484. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3485. (maxProfile.ChargingSchedule.Duration > 0))
  3486. {
  3487. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3488. {
  3489. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3490. {
  3491. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3492. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3493. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3494. }
  3495. else
  3496. {
  3497. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3498. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3499. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3500. }
  3501. }
  3502. if(tmpPeriod.Limit != -1)
  3503. {
  3504. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3505. {
  3506. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3507. {
  3508. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3509. compositePeriodIdx++;
  3510. }
  3511. else
  3512. {
  3513. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3514. }
  3515. }
  3516. // Delete duplicate period
  3517. if(compositePeriodIdx > 1)
  3518. {
  3519. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3520. {
  3521. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3522. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3523. compositePeriodIdx -= 1;
  3524. }
  3525. }
  3526. }
  3527. }
  3528. }
  3529. }
  3530. }
  3531. compositeProfile->ChargingSchedule.Duration = durationReq;
  3532. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3533. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3534. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3535. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3536. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3537. {
  3538. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3539. {
  3540. compositeProfile->ChargingProfileId = 1;
  3541. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3542. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3543. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3544. }
  3545. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3546. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3547. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3548. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3549. }
  3550. if(line)
  3551. free(line);
  3552. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3553. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3554. }
  3555. //==========================================
  3556. // Init all share memory
  3557. //==========================================
  3558. int InitShareMemory()
  3559. {
  3560. int result = PASS;
  3561. int MeterSMId;
  3562. //creat ShmSysConfigAndInfo
  3563. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3564. {
  3565. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3566. result = FAIL;
  3567. }
  3568. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3569. {
  3570. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3571. result = FAIL;
  3572. }
  3573. else
  3574. {}
  3575. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3576. {
  3577. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3578. result = FAIL;
  3579. }
  3580. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3581. {
  3582. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3583. result = FAIL;
  3584. }
  3585. else
  3586. {}
  3587. //creat ShmPsuData
  3588. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3589. {
  3590. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3591. result = FAIL;
  3592. }
  3593. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3594. {
  3595. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3596. result = FAIL;
  3597. }
  3598. else
  3599. {}
  3600. //creat ShmOCPP16Data
  3601. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3602. {
  3603. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3604. result = FAIL;
  3605. }
  3606. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3607. {
  3608. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3609. result = FAIL;
  3610. }
  3611. else
  3612. {}
  3613. /****************************** For Initial Settings************************************************/
  3614. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3615. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3616. // allocate Configuration memory address
  3617. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3618. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3619. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3620. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3621. //offline MeterValue Interval
  3622. TempMeterValueInterval = 0;
  3623. return result;
  3624. }
  3625. int ProcessShareMemory()
  3626. {
  3627. int result = PASS;
  3628. if(InitShareMemory() == FAIL)
  3629. {
  3630. DEBUG_ERROR("InitShareMemory NG\n");
  3631. if(ShmStatusCodeData!=NULL)
  3632. {
  3633. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3634. }
  3635. result = FAIL;
  3636. }
  3637. // Model name parsing
  3638. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3639. {
  3640. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3641. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3642. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3643. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3644. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3645. ) // 'D' means DC
  3646. {
  3647. // DO series
  3648. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3649. {
  3650. SystemInitial += 1;
  3651. gunTotalNumber += 1;
  3652. gunType[gun_index] = GUN_TYPE_DO;
  3653. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3654. {
  3655. case Gun_Type_Chademo:
  3656. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3657. break;
  3658. case Gun_Type_CCS_2:
  3659. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3660. break;
  3661. case Gun_Type_GB:
  3662. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3663. break;
  3664. case Gun_Type_AC:
  3665. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3666. break;
  3667. default:
  3668. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3669. break;
  3670. }
  3671. }
  3672. }
  3673. else
  3674. {
  3675. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3676. {
  3677. SystemInitial += 1;
  3678. gunTotalNumber += 1;
  3679. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3680. {
  3681. case Gun_Type_Chademo:
  3682. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3683. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3684. break;
  3685. case Gun_Type_CCS_2:
  3686. gunType[gun_index] = GUN_TYPE_CCS;
  3687. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3688. break;
  3689. case Gun_Type_GB:
  3690. gunType[gun_index] = GUN_TYPE_GBT;
  3691. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3692. break;
  3693. case Gun_Type_AC:
  3694. gunType[gun_index] = GUN_TYPE_AC;
  3695. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3696. break;
  3697. default:
  3698. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3699. break;
  3700. }
  3701. }
  3702. }
  3703. }
  3704. else
  3705. {
  3706. DEBUG_ERROR("Model name parsing fail.\n");
  3707. result = FAIL;
  3708. }
  3709. if(result != PASS)sleep(5);
  3710. return result;
  3711. }
  3712. void checkRemoteStart(uint8_t connectorIdInt)
  3713. {
  3714. uint8_t tempIndex;
  3715. int result = PASS;
  3716. char cmdBuf[512];
  3717. //check Transaction active
  3718. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3719. {
  3720. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3721. {
  3722. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3723. }
  3724. else
  3725. {
  3726. tempIndex = connectorIdInt -1;
  3727. }
  3728. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3729. {
  3730. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3731. {
  3732. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3733. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3734. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3735. {
  3736. //Reserved
  3737. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3738. }
  3739. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3740. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3741. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3742. {
  3743. //Reserved
  3744. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3745. result = FAIL;
  3746. goto end;
  3747. }
  3748. else
  3749. {
  3750. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3751. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3752. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3753. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3754. {
  3755. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  3756. result = FAIL;
  3757. goto end;
  3758. }
  3759. }//END FOR ELSE
  3760. }
  3761. }// END FOR CHAdeMO_QUANTITY
  3762. }
  3763. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3764. {
  3765. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3766. {
  3767. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3768. }
  3769. else
  3770. {
  3771. tempIndex = connectorIdInt -1;
  3772. }
  3773. for (int index = 0; index < CCS_QUANTITY; index++)
  3774. {
  3775. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3776. {
  3777. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3778. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3779. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3780. {
  3781. //Reserved
  3782. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3783. }
  3784. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3785. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3786. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3787. {
  3788. //Reserved
  3789. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3790. result = FAIL;
  3791. goto end;
  3792. }
  3793. else
  3794. {
  3795. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3796. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3797. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3798. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3799. {
  3800. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3801. result = FAIL;
  3802. goto end;
  3803. }
  3804. }// END FOR ELSE
  3805. }
  3806. }// END FOR CCS_QUANTITY
  3807. }
  3808. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3809. {
  3810. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3811. {
  3812. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3813. }
  3814. else
  3815. {
  3816. tempIndex = connectorIdInt -1;
  3817. }
  3818. for (int index = 0; index < GB_QUANTITY; index++)
  3819. {
  3820. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3821. {
  3822. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3823. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3824. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3825. {
  3826. //Reserved
  3827. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3828. }
  3829. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3830. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3831. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3832. {
  3833. //Reserved
  3834. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3835. result = FAIL;
  3836. goto end;
  3837. }
  3838. else
  3839. {
  3840. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3841. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3842. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3843. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3844. {
  3845. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  3846. result = FAIL;
  3847. goto end;
  3848. }
  3849. }// END FOR ELSE
  3850. }
  3851. } // END FOR GB_QUANTITY
  3852. }
  3853. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3854. {
  3855. tempIndex = connectorIdInt -1;
  3856. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3857. {
  3858. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3859. {
  3860. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3861. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3862. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3863. {
  3864. //Reserved
  3865. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3866. }
  3867. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3868. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3869. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3870. {
  3871. //Reserved
  3872. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3873. result = FAIL;
  3874. goto end;
  3875. }
  3876. else
  3877. {
  3878. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3879. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3880. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3881. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3882. {
  3883. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  3884. result = FAIL;
  3885. goto end;
  3886. }
  3887. }// END FOR ELSE
  3888. }
  3889. } // END FOR GB_QUANTITY
  3890. }
  3891. else
  3892. {
  3893. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3894. {
  3895. tempIndex = 2;
  3896. }
  3897. else
  3898. {
  3899. tempIndex = connectorIdInt -1;
  3900. }
  3901. for (int index = 0; index < AC_QUANTITY; index++)
  3902. {
  3903. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3904. {
  3905. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3906. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3907. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3908. {
  3909. //Reserved
  3910. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3911. }
  3912. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3913. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3914. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3915. {
  3916. //Reserved
  3917. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3918. result = FAIL;
  3919. goto end;
  3920. }
  3921. else
  3922. {
  3923. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3924. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3925. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3926. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3927. {
  3928. DEBUG_WARN("AC connector not allow start cause busy.\n");
  3929. result = FAIL;
  3930. goto end;
  3931. }
  3932. }//END FOR ELSE
  3933. }
  3934. }// END FOR AC_QUANTITY
  3935. }
  3936. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3937. {
  3938. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3939. {
  3940. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  3941. {
  3942. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3943. system(cmdBuf);
  3944. }
  3945. }
  3946. else
  3947. {
  3948. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3949. result = FAIL;
  3950. }
  3951. }
  3952. end:
  3953. if(result == PASS)
  3954. {
  3955. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3956. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3957. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3958. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3959. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3960. }
  3961. }
  3962. void CheckSystemValue(void)
  3963. {
  3964. char filenmae[100]={0};
  3965. char str[100]={0};
  3966. int tempIndex = 0;
  3967. //===============================
  3968. // send Heartbeat
  3969. //===============================
  3970. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3971. {
  3972. //parameter for test
  3973. sendHeartbeatRequest(0);
  3974. //===========================
  3975. // Reset Waiting Time
  3976. //===========================
  3977. HeartBeatWithNOResponse += 1;
  3978. }
  3979. //===============================
  3980. // Credit deduct report
  3981. //===============================
  3982. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  3983. {
  3984. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo, ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice, ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData);
  3985. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  3986. }
  3987. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3988. {
  3989. OCPP_query_deduct_info();
  3990. refreshStartTimer(&clientTime.TcciQueryDeduct);
  3991. }
  3992. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3993. {
  3994. // ClockAlign MeterValue
  3995. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3996. {
  3997. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3998. {
  3999. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4000. {
  4001. tempIndex = ((gun_index==2) ? 1: 0);
  4002. }
  4003. else
  4004. {
  4005. tempIndex = gun_index;
  4006. }
  4007. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4008. {
  4009. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4010. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4011. {
  4012. reqClockAlignMeter[gun_index] = 1;
  4013. }
  4014. }// End for CHAdeMO
  4015. }
  4016. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4017. {
  4018. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4019. {
  4020. tempIndex = ((gun_index==2) ? 1: 0);
  4021. }
  4022. else
  4023. {
  4024. tempIndex = gun_index;
  4025. }
  4026. for (int index = 0; index < CCS_QUANTITY; index++)
  4027. {
  4028. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4029. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4030. {
  4031. reqClockAlignMeter[gun_index] = 1;
  4032. }
  4033. } // End for CCS
  4034. }
  4035. else if(gunType[gun_index] == GUN_TYPE_GBT)
  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 < GB_QUANTITY; index++)
  4046. {
  4047. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4048. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4049. {
  4050. reqClockAlignMeter[gun_index] = 1;
  4051. }
  4052. }// End for GB
  4053. }
  4054. else if(gunType[gun_index] == GUN_TYPE_DO)
  4055. {
  4056. tempIndex = gun_index;
  4057. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4058. {
  4059. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4060. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4061. {
  4062. reqClockAlignMeter[gun_index] = 1;
  4063. }
  4064. }
  4065. }
  4066. else
  4067. {
  4068. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4069. {
  4070. tempIndex = 2;
  4071. }
  4072. else
  4073. {
  4074. tempIndex = gun_index;
  4075. }
  4076. for (int index = 0; index < AC_QUANTITY; index++)
  4077. {
  4078. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4079. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4080. {
  4081. reqClockAlignMeter[gun_index] = 1;
  4082. }
  4083. }//End for AC
  4084. }
  4085. }
  4086. }
  4087. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4088. {
  4089. //==========================================
  4090. // Check remote start without connector id
  4091. //==========================================
  4092. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4093. {
  4094. int connectorIdInt = -1;
  4095. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4096. {
  4097. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4098. {
  4099. connectorIdInt = (gun_index+1);
  4100. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4101. checkRemoteStart(connectorIdInt);
  4102. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4103. break;
  4104. }
  4105. }
  4106. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4107. {
  4108. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4109. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4110. }
  4111. }
  4112. //==========================================
  4113. // csu trigger DataTransferReq
  4114. //==========================================
  4115. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4116. {
  4117. sendDataTransferRequest(gun_index);
  4118. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4119. }
  4120. //==========================================
  4121. // CSU Trigger Authorize Request
  4122. //==========================================
  4123. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4124. {
  4125. sendAuthorizeRequest(0);
  4126. authorizeRetryTimes = authorizeRetryTimes + 1;
  4127. if(authorizeRetryTimes < 3)
  4128. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4129. }
  4130. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4131. {
  4132. authorizeRetryTimes = 0;
  4133. SetOcppConnStatus(FALSE);
  4134. server_sign = FALSE;
  4135. }
  4136. 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))
  4137. {
  4138. sendAuthorizeRequest(0);
  4139. }
  4140. //==========================================
  4141. // Charger start transaction
  4142. //==========================================
  4143. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4144. {
  4145. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4146. sendStartTransactionRequest(gun_index);
  4147. refreshStartTimer(&clientTime.StartTransaction);
  4148. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4149. storeTempStopTransaction(gun_index);
  4150. }
  4151. //==========================================
  4152. // Charger stop transaction
  4153. //==========================================
  4154. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4155. {
  4156. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4157. sendStopTransactionRequest(gun_index);
  4158. OCPP_updatePeriodEnergy(gun_index);
  4159. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4160. refreshStartTimer(&clientTime.StopTransaction);
  4161. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4162. }
  4163. //==========================================
  4164. // Charger status report
  4165. //==========================================
  4166. //--- Check Mode Change ---//
  4167. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4168. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4169. {
  4170. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4171. {
  4172. tempIndex = ((gun_index==2) ? 1: 0);
  4173. }
  4174. else
  4175. {
  4176. tempIndex = gun_index;
  4177. }
  4178. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4179. {
  4180. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4181. {
  4182. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4183. {
  4184. // Sent unplug message for California pricing logic
  4185. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  4186. {
  4187. uint8_t ts[20];
  4188. getNowDatetime(ts);
  4189. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4190. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4191. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4192. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4193. }
  4194. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4195. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4196. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4197. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4198. {
  4199. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4200. if((access(filenmae,F_OK))!=-1)
  4201. {
  4202. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4203. sprintf(str,"rm -f %s",filenmae);
  4204. system(str);
  4205. }
  4206. }
  4207. }
  4208. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4209. #if 1 // for TempStopTransaction
  4210. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4211. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4212. {
  4213. checkTempStopTransaction(gun_index);
  4214. }
  4215. #endif
  4216. }
  4217. }
  4218. }
  4219. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4220. {
  4221. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4222. {
  4223. tempIndex = ((gun_index==2) ? 1: 0);
  4224. }
  4225. else
  4226. {
  4227. tempIndex = gun_index;
  4228. }
  4229. for (int index = 0; index < CCS_QUANTITY; index++)
  4230. {
  4231. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4232. {
  4233. 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]*/ )
  4234. {
  4235. // Sent unplug message for California pricing logic
  4236. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  4237. {
  4238. uint8_t ts[20];
  4239. getNowDatetime(ts);
  4240. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4241. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4242. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4243. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4244. }
  4245. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4246. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4247. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4248. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4249. {
  4250. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4251. if((access(filenmae,F_OK))!=-1)
  4252. {
  4253. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4254. sprintf(str,"rm -f %s",filenmae);
  4255. system(str);
  4256. }
  4257. }
  4258. }
  4259. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4260. #if 1 // for TempStopTransaction
  4261. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4262. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4263. {
  4264. checkTempStopTransaction(gun_index);
  4265. }
  4266. #endif
  4267. }
  4268. }
  4269. }
  4270. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4271. {
  4272. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4273. {
  4274. tempIndex = ((gun_index==2) ? 1: 0);
  4275. }
  4276. else
  4277. {
  4278. tempIndex = gun_index;
  4279. }
  4280. for (int index = 0; index < GB_QUANTITY; index++)
  4281. {
  4282. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4283. {
  4284. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4285. {
  4286. // Sent unplug message for California pricing logic
  4287. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  4288. {
  4289. uint8_t ts[20];
  4290. getNowDatetime(ts);
  4291. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4292. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4293. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4294. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4295. }
  4296. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4297. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4298. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4299. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4300. {
  4301. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4302. if((access(filenmae,F_OK))!=-1)
  4303. {
  4304. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4305. sprintf(str,"rm -f %s",filenmae);
  4306. system(str);
  4307. }
  4308. }
  4309. }
  4310. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4311. #if 1 // for TempStopTransaction
  4312. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4313. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4314. {
  4315. checkTempStopTransaction(gun_index);
  4316. }
  4317. #endif
  4318. }
  4319. }
  4320. }
  4321. else if(gunType[gun_index] == GUN_TYPE_DO)
  4322. {
  4323. tempIndex = gun_index;
  4324. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4325. {
  4326. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4327. {
  4328. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4329. {
  4330. // Sent unplug message for California pricing logic
  4331. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  4332. {
  4333. uint8_t ts[20];
  4334. getNowDatetime(ts);
  4335. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4336. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4337. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4338. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4339. }
  4340. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4341. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4342. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4343. 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
  4344. {
  4345. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4346. if((access(filenmae,F_OK))!=-1)
  4347. {
  4348. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4349. sprintf(str,"rm -f %s",filenmae);
  4350. system(str);
  4351. }
  4352. }
  4353. }
  4354. 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);
  4355. #if 1 // for TempStopTransaction
  4356. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4357. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4358. {
  4359. checkTempStopTransaction(gun_index);
  4360. }
  4361. #endif
  4362. }
  4363. }
  4364. }
  4365. else
  4366. {
  4367. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4368. {
  4369. tempIndex = 2;
  4370. }
  4371. else
  4372. {
  4373. tempIndex = gun_index;
  4374. }
  4375. for (int index = 0; index < AC_QUANTITY; index++)
  4376. {
  4377. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4378. {
  4379. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4380. {
  4381. // Sent unplug message for California pricing logic
  4382. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  4383. {
  4384. uint8_t ts[20];
  4385. getNowDatetime(ts);
  4386. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4387. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4388. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4389. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4390. }
  4391. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4392. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4393. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4394. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4395. {
  4396. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4397. if((access(filenmae,F_OK))!=-1)
  4398. {
  4399. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4400. sprintf(str,"rm -f %s",filenmae);
  4401. system(str);
  4402. }
  4403. }
  4404. }
  4405. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4406. #if 1 // for TempStopTransaction
  4407. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4408. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4409. {
  4410. checkTempStopTransaction(gun_index);
  4411. }
  4412. #endif
  4413. }
  4414. }// END
  4415. }
  4416. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  4417. (
  4418. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4419. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4420. )
  4421. )
  4422. {
  4423. if(SystemInitial > 0)
  4424. SystemInitial -= 1;
  4425. sendStatusNotificationRequest(gun_index);
  4426. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4427. }
  4428. //==============================================
  4429. // CSU Trigger Smart Charging Profile
  4430. //==============================================
  4431. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4432. {
  4433. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4434. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4435. }
  4436. //==============================================
  4437. // Meter report
  4438. //==============================================
  4439. // Trigger MeterValue
  4440. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4441. {
  4442. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4443. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4444. }
  4445. // Clock-aligned Meter value
  4446. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4447. {
  4448. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4449. reqClockAlignMeter[gun_index] = 0;
  4450. }
  4451. // Sample period MeterValue
  4452. 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))))
  4453. {
  4454. //check Transaction active
  4455. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4456. {
  4457. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4458. {
  4459. tempIndex = ((gun_index==2) ? 1: 0);
  4460. }
  4461. else
  4462. {
  4463. tempIndex = gun_index;
  4464. }
  4465. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4466. {
  4467. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4468. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4469. {
  4470. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4471. {
  4472. reqSampleMeter[gun_index] = 1;
  4473. }
  4474. }
  4475. }// End for CHAdeMO
  4476. }
  4477. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4478. {
  4479. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4480. {
  4481. tempIndex = ((gun_index==2) ? 1: 0);
  4482. }
  4483. else
  4484. {
  4485. tempIndex = gun_index;
  4486. }
  4487. for (int index = 0; index < CCS_QUANTITY; index++)
  4488. {
  4489. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4490. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4491. {
  4492. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4493. {
  4494. reqSampleMeter[gun_index] = 1;
  4495. }
  4496. }
  4497. } // End for CCS
  4498. }
  4499. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4500. {
  4501. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4502. {
  4503. tempIndex = ((gun_index==2) ? 1: 0);
  4504. }
  4505. else
  4506. {
  4507. tempIndex = gun_index;
  4508. }
  4509. for (int index = 0; index < GB_QUANTITY; index++)
  4510. {
  4511. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4512. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4513. {
  4514. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4515. {
  4516. reqSampleMeter[gun_index] = 1;
  4517. }
  4518. }
  4519. }// End for GB
  4520. }
  4521. else if(gunType[gun_index] == GUN_TYPE_DO)
  4522. {
  4523. tempIndex = gun_index;
  4524. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4525. {
  4526. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4527. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4528. {
  4529. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4530. {
  4531. reqSampleMeter[gun_index] = 1;
  4532. }
  4533. }
  4534. }
  4535. }
  4536. else
  4537. {
  4538. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4539. {
  4540. tempIndex = 2;
  4541. }
  4542. else
  4543. {
  4544. tempIndex = gun_index;
  4545. }
  4546. for (int index = 0; index < AC_QUANTITY; index++)
  4547. {
  4548. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4549. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4550. {
  4551. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4552. {
  4553. reqSampleMeter[gun_index] = 1;
  4554. }
  4555. }
  4556. }//End for AC
  4557. }
  4558. if(reqSampleMeter[gun_index] == 1)
  4559. {
  4560. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4561. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4562. storeTempStopTransaction(gun_index);
  4563. reqSampleMeter[gun_index] = 0;
  4564. }
  4565. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4566. }
  4567. //==============================================
  4568. // Check Connector reserved
  4569. //==============================================
  4570. //===============================
  4571. // Check if Reserve is expired
  4572. //===============================
  4573. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4574. {
  4575. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4576. {
  4577. DEBUG_INFO("reserve expired.\n");
  4578. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4579. }
  4580. }//END OF Check if Reserve is expired
  4581. //==========================================
  4582. // csu trigger FirmwareStatusNotificationReq
  4583. //==========================================
  4584. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4585. {
  4586. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  4587. }
  4588. //==========================================
  4589. // csu trigger DiagnosticsStatusNotificationReq
  4590. //==========================================
  4591. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4592. {
  4593. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  4594. }
  4595. //==========================================
  4596. // csu trigger CancelReservationConf
  4597. //==========================================
  4598. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4599. {
  4600. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  4601. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4602. }
  4603. //==========================================
  4604. // csu trigger ChangeAvailabilityConf
  4605. //==========================================
  4606. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4607. {
  4608. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  4609. }
  4610. //==========================================
  4611. // csu trigger UnlockConnectorConf
  4612. //==========================================
  4613. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4614. {
  4615. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  4616. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4617. }
  4618. //==========================================
  4619. // csu trigger ReserveNowConf
  4620. //==========================================
  4621. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4622. {
  4623. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  4624. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4625. }
  4626. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  4627. {
  4628. sendSignCertificateRequest();
  4629. }
  4630. }
  4631. }
  4632. //==========================================
  4633. // send request routine
  4634. //==========================================
  4635. int sendAuthorizeRequest(int gun_index)
  4636. {
  4637. mtrace();
  4638. int result = FAIL;
  4639. char message[100]={0};
  4640. char guid[37];
  4641. char tempdata[65]={0};
  4642. DEBUG_INFO("sendAuthorizeRequest...\n");
  4643. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4644. //Local Authorize
  4645. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  4646. {
  4647. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4648. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4649. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4650. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4651. result = PASS;
  4652. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4653. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4654. authorizeRetryTimes = 0;
  4655. return result;
  4656. }
  4657. 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))||
  4658. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4659. {
  4660. // Query from cache
  4661. DEBUG_INFO("Authorize from cache.\n");
  4662. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4663. // Query from list
  4664. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4665. {
  4666. DEBUG_INFO("Authorize from list.\n");
  4667. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4668. }
  4669. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4670. {
  4671. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4672. {
  4673. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4674. }
  4675. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4676. {
  4677. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4678. }
  4679. if(!GetOcppConnStatus())
  4680. {
  4681. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4682. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4683. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4684. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4685. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4686. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4687. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4688. authorizeRetryTimes = 0;
  4689. return result;
  4690. }
  4691. }
  4692. else
  4693. {
  4694. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4695. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4696. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4697. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4698. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  4699. else
  4700. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4701. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4702. result = PASS;
  4703. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4704. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4705. authorizeRetryTimes = 0;
  4706. return result;
  4707. }
  4708. }
  4709. //initialize struct Authorize
  4710. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  4711. //get data from shared memory
  4712. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4713. random_uuid(guid);
  4714. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  4715. LWS_Send(message);
  4716. sprintf(tempdata, "Authorize,%d", gun_index);
  4717. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4718. {
  4719. result = PASS;
  4720. DEBUG_INFO("Authorize mapItem pass\n");
  4721. }
  4722. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4723. return result;
  4724. }
  4725. int sendBootNotificationRequest(void)
  4726. {
  4727. mtrace();
  4728. int result = FAIL;
  4729. char message[500]={0}, payload[700]={0};
  4730. char guid[37]={0};
  4731. char tempdata[65]={0};
  4732. // Fill BootNotification fields
  4733. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  4734. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4735. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4736. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4737. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4738. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4739. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4740. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4741. ShmOCPP16Data->ChargeBoxId
  4742. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4743. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4744. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4745. ,ShmOCPP16Data->BootNotification.CpFwVersion
  4746. ,ShmOCPP16Data->BootNotification.CpIccid
  4747. ,ShmOCPP16Data->BootNotification.CpImsi);
  4748. random_uuid(guid);
  4749. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4750. LWS_Send(message);
  4751. sprintf(tempdata, "BootNotification,0");
  4752. 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*/)
  4753. {
  4754. result = PASS;
  4755. }
  4756. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4757. strcpy(queuedata,message);
  4758. return result;
  4759. }
  4760. int sendDataTransferRequest(int gun_index)
  4761. {
  4762. mtrace();
  4763. char message[1000]={0};
  4764. char guid[37]={0};
  4765. char tempdata[65]={0};
  4766. int result = FAIL;
  4767. random_uuid(guid);
  4768. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4769. MESSAGE_TYPE_CALL,
  4770. guid,
  4771. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4772. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4773. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4774. LWS_Send(message);
  4775. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4776. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4777. {
  4778. result = PASS;
  4779. DEBUG_INFO("DataTransfer mapItem pass\n");
  4780. }
  4781. return result;
  4782. }
  4783. int sendDiagnosticsStatusNotificationRequest(char *status)
  4784. {
  4785. mtrace();
  4786. int result = FAIL;
  4787. char message[110]={0};
  4788. char guid[37]={0};
  4789. char tempdata[65]={0};
  4790. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4791. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4792. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4793. random_uuid(guid);
  4794. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4795. LWS_SendNow(message);
  4796. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4797. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4798. {
  4799. result = PASS;
  4800. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4801. }
  4802. //#ifdef SystemLogMessage
  4803. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4804. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4805. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4806. //#endif
  4807. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4808. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4809. //record status
  4810. if(strcmp(status,"Idle")==0)
  4811. {
  4812. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4813. }
  4814. else if(strcmp(status,"Uploaded")==0)
  4815. {
  4816. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4817. }
  4818. else if(strcmp(status,"UploadFailed")==0)
  4819. {
  4820. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4821. }
  4822. else if(strcmp(status,"Uploading")==0)
  4823. {
  4824. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4825. }
  4826. return result;
  4827. }
  4828. int sendFirmwareStatusNotificationRequest(char *status)
  4829. {
  4830. mtrace();
  4831. int result = FAIL;
  4832. char message[110]={0};
  4833. char guid[37]={0};
  4834. char tempdata[65]={0};
  4835. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4836. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4837. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4838. random_uuid(guid);
  4839. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4840. LWS_SendNow(message);
  4841. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4842. 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*/)
  4843. {
  4844. result = PASS;
  4845. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4846. }
  4847. //#ifdef SystemLogMessage
  4848. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4849. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4850. //#endif
  4851. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4852. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4853. //record status
  4854. if(strcmp(status,"Downloaded")==0)
  4855. {
  4856. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4857. }
  4858. else if(strcmp(status,"DownloadFailed")==0)
  4859. {
  4860. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4861. }
  4862. else if(strcmp(status,"Downloading")==0)
  4863. {
  4864. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4865. }
  4866. else if(strcmp(status,"Idle")==0)
  4867. {
  4868. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4869. }
  4870. else if(strcmp(status,"InstallationFailed")==0)
  4871. {
  4872. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4873. }
  4874. else if(strcmp(status,"Installing")==0)
  4875. {
  4876. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4877. }
  4878. else if(strcmp(status,"Installed")==0)
  4879. {
  4880. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4881. }
  4882. return result;
  4883. }
  4884. int sendHeartbeatRequest(int gun_index)
  4885. {
  4886. mtrace();
  4887. int result = FAIL;
  4888. char message[80]={0};
  4889. char guid[37]={0};
  4890. char tempdata[65]={0};
  4891. random_uuid(guid);
  4892. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4893. , MESSAGE_TYPE_CALL
  4894. , guid );
  4895. LWS_Send(message);
  4896. sprintf(tempdata, "Heartbeat,%d", 0);
  4897. 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*/)
  4898. {
  4899. result = PASS;
  4900. }
  4901. return result;
  4902. }
  4903. int sendStartTransactionRequest(int gun_index)
  4904. {
  4905. mtrace();
  4906. int result = FAIL;
  4907. char message[250]={0};
  4908. char guid[37]={0};
  4909. struct timeval tmnow;
  4910. struct tm *tm;
  4911. char buf[28];//, usec_buf[6];
  4912. char tempdata[65]={0};
  4913. int tempIndex = 0;
  4914. DEBUG_INFO("sendStartTransactionRequest...\n");
  4915. gettimeofday(&tmnow, NULL);
  4916. time_t t;
  4917. t = time(NULL);
  4918. /*UTC time and date*/
  4919. tm = gmtime(&t);
  4920. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4921. #if 0 // remove temporally
  4922. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4923. strcat(buf,".");
  4924. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4925. strcat(buf,usec_buf);
  4926. #endif
  4927. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4928. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4929. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4930. // clear StartTransaction Response
  4931. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4932. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4933. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4934. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4935. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4936. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4937. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4938. {
  4939. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4940. {
  4941. tempIndex = ((gun_index==2) ? 1: 0);
  4942. }
  4943. else
  4944. {
  4945. tempIndex = gun_index;
  4946. }
  4947. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4948. {
  4949. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4950. {
  4951. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4952. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4953. }
  4954. }
  4955. }
  4956. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4957. {
  4958. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4959. {
  4960. tempIndex = ((gun_index==2) ? 1: 0);
  4961. }
  4962. else
  4963. {
  4964. tempIndex = gun_index;
  4965. }
  4966. for (int index = 0; index < CCS_QUANTITY; index++)
  4967. {
  4968. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4969. {
  4970. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4971. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4972. }
  4973. }
  4974. }
  4975. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4976. {
  4977. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4978. {
  4979. tempIndex = ((gun_index==2) ? 1: 0);
  4980. }
  4981. else
  4982. {
  4983. tempIndex = gun_index;
  4984. }
  4985. for (int index = 0; index < GB_QUANTITY; index++)
  4986. {
  4987. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4988. {
  4989. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4990. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4991. }
  4992. }
  4993. }
  4994. else if(gunType[gun_index] == GUN_TYPE_DO)
  4995. {
  4996. tempIndex = gun_index;
  4997. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4998. {
  4999. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5000. {
  5001. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5002. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5003. }
  5004. }
  5005. }
  5006. else
  5007. {
  5008. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5009. {
  5010. tempIndex = 2;
  5011. }
  5012. else
  5013. {
  5014. tempIndex = gun_index;
  5015. }
  5016. for (int index = 0; index < AC_QUANTITY; index++)
  5017. {
  5018. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5019. {
  5020. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5021. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5022. }
  5023. }
  5024. }
  5025. random_uuid(guid);
  5026. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5027. {
  5028. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5029. , gun_index +1
  5030. , MESSAGE_TYPE_CALL
  5031. , guid
  5032. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5033. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5034. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5035. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5036. }
  5037. else
  5038. {
  5039. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5040. , gun_index +1
  5041. , MESSAGE_TYPE_CALL
  5042. , guid
  5043. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5044. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5045. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5046. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  5047. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5048. }
  5049. #if 1
  5050. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5051. 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*/)
  5052. {
  5053. result = PASS;
  5054. }
  5055. #endif
  5056. strcpy(queuedata, message);
  5057. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5058. OCPP_insert_transaction_msg(YES, queuedata);
  5059. return result;
  5060. }
  5061. int sendStatusNotificationRequest(int gun_index)
  5062. {
  5063. mtrace();
  5064. int result = FAIL;
  5065. char message[600]={0};
  5066. char guid[37];
  5067. int currentStatus = 0;
  5068. struct timeval tmnow;
  5069. struct tm *tm;
  5070. char buf[28];//, usec_buf[6];
  5071. char tempdata[65]={0};
  5072. int tempIndex = 0;
  5073. uint8_t isStateChanged = TRUE;
  5074. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5075. gettimeofday(&tmnow, NULL);
  5076. time_t t;
  5077. t = time(NULL);
  5078. /*UTC time and date*/
  5079. tm = gmtime(&t);
  5080. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5081. #if 0 // remove temporally
  5082. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5083. strcat(buf,".");
  5084. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5085. strcat(buf,usec_buf);
  5086. #endif
  5087. //printf("%s",buf);
  5088. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5089. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5090. // it's option
  5091. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5092. /*
  5093. enum _SYSTEM_STATUS
  5094. {
  5095. S_BOOTING = 0,
  5096. S_IDLE, = 1
  5097. S_AUTHORIZING, =2
  5098. S_REASSIGN_CHECK, =3
  5099. S_REASSIGN, =4
  5100. S_PRECHARGE, =5
  5101. S_PREPARING_FOR_EV, =6
  5102. S_PREPARING_FOR_EVSE, =7
  5103. S_CHARGING, =8
  5104. S_TERMINATING, =9
  5105. S_COMPLETE, =10
  5106. S_ALARM, =11
  5107. S_FAULT =12
  5108. }
  5109. */
  5110. //check Transaction active
  5111. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5112. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5113. {
  5114. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5115. {
  5116. tempIndex = ((gun_index==2) ? 1: 0);
  5117. }
  5118. else
  5119. {
  5120. tempIndex = gun_index;
  5121. }
  5122. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5123. {
  5124. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5125. {
  5126. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5127. {
  5128. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5129. {
  5130. currentStatus = Preparing; //OCPP Status: Preparing
  5131. }
  5132. else
  5133. {
  5134. currentStatus = Available; //OCPP Status: Available
  5135. }
  5136. }
  5137. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5138. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5139. ) //S_PRECHARGE
  5140. {
  5141. currentStatus = Preparing; //OCPP Status: Preparing
  5142. }
  5143. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5144. {
  5145. currentStatus = Charging; //OCPP Status: Charging
  5146. }
  5147. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5148. {
  5149. currentStatus = Finishing; //OCPP Status: Finishing
  5150. }
  5151. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5152. {
  5153. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5154. }
  5155. 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
  5156. {
  5157. currentStatus = Unavailable; //OCPP Status: Unavailable
  5158. }
  5159. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5160. {
  5161. currentStatus = Faulted; //OCPP Status: Faulted
  5162. }
  5163. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5164. {
  5165. currentStatus = Reserved; //OCPP Status: Reserved
  5166. }
  5167. } //end of the same index
  5168. }//end of for CHAdeMO_QUANTITY
  5169. }
  5170. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5171. {
  5172. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5173. {
  5174. tempIndex = ((gun_index==2) ? 1: 0);
  5175. }
  5176. else
  5177. {
  5178. tempIndex = gun_index;
  5179. }
  5180. for (int index = 0; index < CCS_QUANTITY; index++)
  5181. {
  5182. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5183. {
  5184. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5185. {
  5186. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5187. {
  5188. currentStatus = Preparing; //OCPP Status: Preparing
  5189. }
  5190. else
  5191. {
  5192. currentStatus = Available; //OCPP Status: Available
  5193. }
  5194. }
  5195. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5196. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5197. ) //S_PRECHARGE
  5198. {
  5199. currentStatus = Preparing; //OCPP Status: Preparing
  5200. }
  5201. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5202. {
  5203. currentStatus = Charging; //OCPP Status: Charging
  5204. }
  5205. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5206. {
  5207. currentStatus = Finishing; //OCPP Status: Finishing
  5208. }
  5209. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5210. {
  5211. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5212. }
  5213. 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
  5214. {
  5215. currentStatus = Unavailable; //OCPP Status : Unavailable
  5216. }
  5217. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5218. {
  5219. currentStatus = Faulted; //OCPP Status: Faulted
  5220. }
  5221. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5222. {
  5223. currentStatus = Reserved; //OCPP Status: Reserved
  5224. }
  5225. } //end of the same index
  5226. } // end of for CCS_QUANTITY
  5227. }
  5228. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5229. {
  5230. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5231. {
  5232. tempIndex = ((gun_index==2) ? 1: 0);
  5233. }
  5234. else
  5235. {
  5236. tempIndex = gun_index;
  5237. }
  5238. for (int index = 0; index < GB_QUANTITY; index++)
  5239. {
  5240. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5241. {
  5242. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5243. {
  5244. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5245. {
  5246. currentStatus = Preparing; //OCPP Status: Preparing
  5247. }
  5248. else
  5249. {
  5250. currentStatus = Available; //OCPP Status: Available
  5251. }
  5252. }
  5253. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5254. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5255. ) //S_PRECHARGE
  5256. {
  5257. currentStatus = Preparing; //OCPP Status: Preparing
  5258. }
  5259. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5260. {
  5261. currentStatus = Charging; //OCPP Status: Charging
  5262. }
  5263. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5264. {
  5265. currentStatus = Finishing; //OCPP Status: Finishing
  5266. }
  5267. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5268. {
  5269. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5270. }
  5271. 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
  5272. {
  5273. currentStatus = Unavailable; //OCPP Status: Unavailable
  5274. }
  5275. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5276. {
  5277. currentStatus = Faulted; //OCPP Status: Faulted
  5278. }
  5279. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5280. {
  5281. currentStatus = Reserved; //OCPP Status: Reserved
  5282. }
  5283. } //end of the same index
  5284. } // end of for GB_QUANTITY
  5285. }
  5286. else if(gunType[gun_index] == GUN_TYPE_DO)
  5287. {
  5288. tempIndex = gun_index;
  5289. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5290. {
  5291. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5292. {
  5293. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5294. {
  5295. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5296. {
  5297. currentStatus = Preparing; //OCPP Status: Preparing
  5298. }
  5299. else
  5300. {
  5301. currentStatus = Available; //OCPP Status: Available
  5302. }
  5303. }
  5304. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5305. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5306. ) //S_PRECHARGE
  5307. {
  5308. currentStatus = Preparing; //OCPP Status: Preparing
  5309. }
  5310. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5311. {
  5312. currentStatus = Charging; //OCPP Status: Charging
  5313. }
  5314. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5315. {
  5316. currentStatus = Finishing; //OCPP Status: Finishing
  5317. }
  5318. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5319. {
  5320. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5321. }
  5322. 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
  5323. {
  5324. currentStatus = Unavailable; //OCPP Status: Unavailable
  5325. }
  5326. 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
  5327. {
  5328. currentStatus = Faulted; //OCPP Status: Faulted
  5329. }
  5330. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5331. {
  5332. currentStatus = Reserved; //OCPP Status: Reserved
  5333. }
  5334. } //end of the same index
  5335. }
  5336. }
  5337. else
  5338. {
  5339. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5340. {
  5341. tempIndex = 2;
  5342. }
  5343. else
  5344. {
  5345. tempIndex = gun_index;
  5346. }
  5347. for (int index = 0; index < AC_QUANTITY; index++)
  5348. {
  5349. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5350. {
  5351. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5352. {
  5353. 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))
  5354. {
  5355. currentStatus = Preparing; //OCPP Status: Preparing
  5356. }
  5357. else
  5358. {
  5359. currentStatus = Available; //OCPP Status: Available
  5360. }
  5361. }
  5362. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5363. {
  5364. currentStatus = Preparing; //OCPP Status: Preparing
  5365. }
  5366. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5367. {
  5368. currentStatus = Charging; //OCPP Status: Charging
  5369. }
  5370. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5371. {
  5372. currentStatus = Finishing; //OCPP Status: Finishing
  5373. }
  5374. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5375. {
  5376. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5377. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5378. else
  5379. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5380. }
  5381. 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
  5382. {
  5383. currentStatus = Unavailable; //OCPP Status: Unavailable
  5384. }
  5385. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5386. {
  5387. currentStatus = Faulted; //OCPP Status: Faulted
  5388. }
  5389. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5390. {
  5391. currentStatus = Reserved; //OCPP Status: Reserved
  5392. }
  5393. }//end of the same index
  5394. }//end of for AC_QUANTITY
  5395. }
  5396. //it's option
  5397. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5398. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5399. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5400. {
  5401. isStateChanged = FALSE;
  5402. }
  5403. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5404. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5405. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5406. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5407. random_uuid(guid);
  5408. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5409. , MESSAGE_TYPE_CALL
  5410. , guid
  5411. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5412. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5413. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5414. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5415. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5416. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5417. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5418. if((server_sign == TRUE) && isStateChanged)
  5419. {
  5420. LWS_Send(message);
  5421. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5422. 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*/)
  5423. {
  5424. //DEBUG_ERROR("statusNotification mapitem pass");
  5425. result = PASS;
  5426. }
  5427. }
  5428. else
  5429. {
  5430. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5431. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5432. result = PASS;
  5433. }
  5434. return result;
  5435. }
  5436. int sendStopTransactionRequest(int gun_index)
  5437. {
  5438. mtrace();
  5439. int result = FAIL;
  5440. //char message[1500]={0};
  5441. char guid[37]={0};
  5442. char tempdata[65]={0};
  5443. int tempIndex = 0;
  5444. char TempStopTransaction[256];
  5445. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5446. //int idx_sample=0;
  5447. DEBUG_INFO("sendStopTransactionRequest \n");
  5448. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5449. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5450. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5451. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5452. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5453. {
  5454. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5455. {
  5456. tempIndex = ((gun_index==2) ? 1: 0);
  5457. }
  5458. else
  5459. {
  5460. tempIndex = gun_index;
  5461. }
  5462. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5463. {
  5464. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5465. {
  5466. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5467. }
  5468. }// END OF CHAdeMO_QUANTITY
  5469. }
  5470. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5471. {
  5472. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5473. {
  5474. tempIndex = ((gun_index==2) ? 1: 0);
  5475. }
  5476. else
  5477. {
  5478. tempIndex = gun_index;
  5479. }
  5480. for (int index = 0; index < CCS_QUANTITY; index++)
  5481. {
  5482. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5483. {
  5484. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5485. }
  5486. }// END OF CCS_QUANTITY
  5487. }
  5488. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5489. {
  5490. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5491. {
  5492. tempIndex = ((gun_index==2) ? 1: 0);
  5493. }
  5494. else
  5495. {
  5496. tempIndex = gun_index;
  5497. }
  5498. for (int index = 0; index < GB_QUANTITY; index++)
  5499. {
  5500. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5501. {
  5502. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5503. }
  5504. }// END OF GB_QUANTITY
  5505. }
  5506. else if(gunType[gun_index] == GUN_TYPE_DO)
  5507. {
  5508. tempIndex = gun_index;
  5509. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5510. {
  5511. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5512. {
  5513. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5514. }
  5515. }// END OF GB_QUANTITY
  5516. }
  5517. else
  5518. {
  5519. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5520. {
  5521. tempIndex = 2;
  5522. }
  5523. else
  5524. {
  5525. tempIndex = gun_index;
  5526. }
  5527. for (int index = 0; index < AC_QUANTITY; index++)
  5528. {
  5529. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5530. {
  5531. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5532. }
  5533. }// END OF AC_QUANTITY
  5534. }
  5535. //====================================== Stop Transaction Time =====================================================
  5536. struct timeval tmnow;
  5537. struct tm *tm;
  5538. char buf[28];//, usec_buf[6];
  5539. gettimeofday(&tmnow, NULL);
  5540. time_t t;
  5541. t = time(NULL);
  5542. /*UTC time and date*/
  5543. tm = gmtime(&t);
  5544. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5545. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  5546. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  5547. random_uuid(guid);
  5548. /***********************************transactionData******************************************************/
  5549. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5550. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5551. //=================================
  5552. // Transaction_Begin
  5553. //=================================
  5554. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5555. {
  5556. //============================================ Energy.Active.Import.Interval ================================
  5557. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5558. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5559. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5560. 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*/]);
  5561. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5562. 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))
  5563. {
  5564. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5565. }
  5566. else
  5567. {
  5568. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5569. }
  5570. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5571. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5572. }
  5573. //=================================
  5574. // Transaction_End
  5575. //=================================
  5576. // ================================= Current.Import L1 ===============================================
  5577. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5578. {
  5579. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5580. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5581. {
  5582. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5583. {
  5584. tempIndex = ((gun_index==2) ? 1: 0);
  5585. }
  5586. else
  5587. {
  5588. tempIndex = gun_index;
  5589. }
  5590. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5591. {
  5592. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5593. {
  5594. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5595. }
  5596. }// End of for CHAdeMO_QUANTITY
  5597. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5598. }
  5599. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5600. {
  5601. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5602. {
  5603. tempIndex = ((gun_index==2) ? 1: 0);
  5604. }
  5605. else
  5606. {
  5607. tempIndex = gun_index;
  5608. }
  5609. for (int index = 0; index < CCS_QUANTITY; index++)
  5610. {
  5611. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5612. {
  5613. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5614. }
  5615. }// End of for CCS_QUANTITY
  5616. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5617. }
  5618. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5619. {
  5620. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5621. {
  5622. tempIndex = ((gun_index==2) ? 1: 0);
  5623. }
  5624. else
  5625. {
  5626. tempIndex = gun_index;
  5627. }
  5628. for (int index = 0; index < GB_QUANTITY; index++)
  5629. {
  5630. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5631. {
  5632. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5633. }
  5634. }// End of for GB_QUANTITY
  5635. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5636. }
  5637. else if(gunType[gun_index] == GUN_TYPE_DO)
  5638. {
  5639. tempIndex = gun_index;
  5640. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5641. {
  5642. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5643. {
  5644. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5645. }
  5646. }
  5647. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5648. }
  5649. else
  5650. {
  5651. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5652. {
  5653. tempIndex = 2;
  5654. }
  5655. else
  5656. {
  5657. tempIndex = gun_index;
  5658. }
  5659. for (int index = 0; index < AC_QUANTITY; index++)
  5660. {
  5661. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5662. {
  5663. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5664. }
  5665. }// End of for AC_QUANTITY
  5666. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5667. }
  5668. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5669. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5670. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5671. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5672. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5673. }
  5674. // ================================= Energy.Active.Import.Interval ==============================================
  5675. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5676. {
  5677. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5678. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5679. {
  5680. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5681. {
  5682. tempIndex = ((gun_index==2) ? 1: 0);
  5683. }
  5684. else
  5685. {
  5686. tempIndex = gun_index;
  5687. }
  5688. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5689. {
  5690. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5691. {
  5692. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5693. }
  5694. }// END OF CHAdeMO_QUANTITY
  5695. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5696. }
  5697. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5698. {
  5699. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5700. {
  5701. tempIndex = ((gun_index==2) ? 1: 0);
  5702. }
  5703. else
  5704. {
  5705. tempIndex = gun_index;
  5706. }
  5707. for (int index = 0; index < CCS_QUANTITY; index++)
  5708. {
  5709. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5710. {
  5711. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5712. }
  5713. }// END OF CCS_QUANTITY
  5714. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5715. }
  5716. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5717. {
  5718. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5719. {
  5720. tempIndex = ((gun_index==2) ? 1: 0);
  5721. }
  5722. else
  5723. {
  5724. tempIndex = gun_index;
  5725. }
  5726. for (int index = 0; index < GB_QUANTITY; index++)
  5727. {
  5728. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5729. {
  5730. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5731. }
  5732. }// END OF GB_QUANTITY
  5733. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5734. }
  5735. else if(gunType[gun_index] == GUN_TYPE_DO)
  5736. {
  5737. tempIndex = gun_index;
  5738. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5739. {
  5740. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5741. {
  5742. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5743. }
  5744. }
  5745. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5746. }
  5747. else
  5748. {
  5749. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5750. {
  5751. tempIndex = 2;
  5752. }
  5753. else
  5754. {
  5755. tempIndex = gun_index;
  5756. }
  5757. for (int index = 0; index < AC_QUANTITY; index++)
  5758. {
  5759. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5760. {
  5761. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5762. }
  5763. }// END OF AC_QUANTITY
  5764. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5765. }
  5766. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5767. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5768. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5769. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5770. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5771. }
  5772. //=================================== Power.Active.Import ==================================================
  5773. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5774. {
  5775. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5776. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5777. {
  5778. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5779. {
  5780. tempIndex = ((gun_index==2) ? 1: 0);
  5781. }
  5782. else
  5783. {
  5784. tempIndex = gun_index;
  5785. }
  5786. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5787. {
  5788. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5789. {
  5790. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5791. }
  5792. } // End for CHAdeMO_QUANTITY
  5793. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5794. }
  5795. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5796. {
  5797. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5798. {
  5799. tempIndex = ((gun_index==2) ? 1: 0);
  5800. }
  5801. else
  5802. {
  5803. tempIndex = gun_index;
  5804. }
  5805. for (int index = 0; index < CCS_QUANTITY; index++)
  5806. {
  5807. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5808. {
  5809. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5810. }
  5811. } // END for CCS_QUANTITY
  5812. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5813. }
  5814. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5815. {
  5816. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5817. {
  5818. tempIndex = ((gun_index==2) ? 1: 0);
  5819. }
  5820. else
  5821. {
  5822. tempIndex = gun_index;
  5823. }
  5824. for (int index = 0; index < GB_QUANTITY; index++)
  5825. {
  5826. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5827. {
  5828. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5829. }
  5830. }// END for GB_QUANTITY
  5831. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5832. }
  5833. else if(gunType[gun_index] == GUN_TYPE_DO)
  5834. {
  5835. tempIndex = gun_index;
  5836. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5837. {
  5838. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5839. {
  5840. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5841. }
  5842. }
  5843. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5844. }
  5845. else
  5846. {
  5847. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5848. {
  5849. tempIndex = 2;
  5850. }
  5851. else
  5852. {
  5853. tempIndex = gun_index;
  5854. }
  5855. for (int index = 0; index < AC_QUANTITY; index++)
  5856. {
  5857. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5858. {
  5859. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5860. }
  5861. } // END for AC_QUANTITY
  5862. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5863. }
  5864. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5865. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5866. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5867. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5868. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5869. }
  5870. //============================ Voltage L1 ====================================
  5871. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5872. {
  5873. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5874. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5875. {
  5876. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5877. {
  5878. tempIndex = ((gun_index==2) ? 1: 0);
  5879. }
  5880. else
  5881. {
  5882. tempIndex = gun_index;
  5883. }
  5884. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5885. {
  5886. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5887. {
  5888. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5889. }
  5890. } // END OF FOR CHAdeMO_QUANTITY
  5891. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5892. }
  5893. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5894. {
  5895. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5896. {
  5897. tempIndex = ((gun_index==2) ? 1: 0);
  5898. }
  5899. else
  5900. {
  5901. tempIndex = gun_index;
  5902. }
  5903. for (int index = 0; index < CCS_QUANTITY; index++)
  5904. {
  5905. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5906. {
  5907. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5908. }
  5909. } // END OF FOR CCS_QUANTITY
  5910. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5911. }
  5912. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5913. {
  5914. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5915. {
  5916. tempIndex = ((gun_index==2) ? 1: 0);
  5917. }
  5918. else
  5919. {
  5920. tempIndex = gun_index;
  5921. }
  5922. for (int index = 0; index < GB_QUANTITY; index++)
  5923. {
  5924. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5925. {
  5926. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5927. }
  5928. } // END OF FOR GB_QUANTITY
  5929. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5930. }
  5931. else if(gunType[gun_index] == GUN_TYPE_DO)
  5932. {
  5933. tempIndex = gun_index;
  5934. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5935. {
  5936. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5937. {
  5938. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5939. }
  5940. }
  5941. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5942. }
  5943. else
  5944. {
  5945. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5946. {
  5947. tempIndex = 2;
  5948. }
  5949. else
  5950. {
  5951. tempIndex = gun_index;
  5952. }
  5953. for (int index = 0; index < AC_QUANTITY; index++)
  5954. {
  5955. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5956. {
  5957. 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
  5958. }
  5959. } // END OF FOR AC_QUANTITY
  5960. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5961. }
  5962. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5963. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5964. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5965. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5966. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5967. }
  5968. //====================== End SoC ================================
  5969. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5970. {
  5971. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5972. 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))
  5973. {
  5974. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5975. {
  5976. tempIndex = ((gun_index==2) ? 1: 0);
  5977. }
  5978. else
  5979. {
  5980. tempIndex = gun_index;
  5981. }
  5982. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5983. {
  5984. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5985. {
  5986. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5987. {
  5988. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5989. }
  5990. }
  5991. }
  5992. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5993. {
  5994. for (int index = 0; index < CCS_QUANTITY; index++)
  5995. {
  5996. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5997. {
  5998. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5999. }
  6000. }
  6001. }
  6002. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6003. {
  6004. for (int index = 0; index < GB_QUANTITY; index++)
  6005. {
  6006. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6007. {
  6008. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6009. }
  6010. }
  6011. }
  6012. else if(gunType[gun_index] == GUN_TYPE_DO)
  6013. {
  6014. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6015. {
  6016. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6017. {
  6018. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6019. }
  6020. }
  6021. }
  6022. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6023. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6024. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6025. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6026. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6027. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6028. } // END FOR DC CASE
  6029. }
  6030. // ================================= Current.Import L2 ===============================================
  6031. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6032. {
  6033. // AC 3 phse L2 current
  6034. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6035. {
  6036. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6037. {
  6038. tempIndex = 2;
  6039. }
  6040. else
  6041. {
  6042. tempIndex = gun_index;
  6043. }
  6044. for (int index = 0; index < AC_QUANTITY; index++)
  6045. {
  6046. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6047. {
  6048. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6049. }
  6050. }// End of for AC_QUANTITY
  6051. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6052. }
  6053. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6054. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6055. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6056. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6057. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6058. }
  6059. // ================================= Current.Import L3 ===============================================
  6060. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6061. {
  6062. // AC 3 phse L3 current
  6063. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6064. {
  6065. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6066. {
  6067. tempIndex = 2;
  6068. }
  6069. else
  6070. {
  6071. tempIndex = gun_index;
  6072. }
  6073. for (int index = 0; index < AC_QUANTITY; index++)
  6074. {
  6075. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6076. {
  6077. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6078. }
  6079. }// End of for AC_QUANTITY
  6080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6081. }
  6082. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6084. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6085. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6086. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6087. }
  6088. //============================ Voltage L2 ====================================
  6089. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6090. {
  6091. // AC 3 phse L2 voltage
  6092. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6093. {
  6094. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6095. {
  6096. tempIndex = 2;
  6097. }
  6098. else
  6099. {
  6100. tempIndex = gun_index;
  6101. }
  6102. for (int index = 0; index < AC_QUANTITY; index++)
  6103. {
  6104. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6105. {
  6106. 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
  6107. }
  6108. } // END OF FOR AC_QUANTITY
  6109. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6110. }
  6111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6112. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6113. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6114. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6115. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6116. }
  6117. //============================ Voltage L3 ====================================
  6118. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6119. {
  6120. // AC 3 phse L3 voltage
  6121. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6122. {
  6123. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6124. {
  6125. tempIndex = 2;
  6126. }
  6127. else
  6128. {
  6129. tempIndex = gun_index;
  6130. }
  6131. for (int index = 0; index < AC_QUANTITY; index++)
  6132. {
  6133. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6134. {
  6135. 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
  6136. }
  6137. } // END OF FOR AC_QUANTITY
  6138. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6139. }
  6140. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6141. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6142. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6143. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6144. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6145. }
  6146. //====================== Start SoC ================================
  6147. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6148. {
  6149. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6150. 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))
  6151. {
  6152. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6153. {
  6154. tempIndex = ((gun_index==2) ? 1: 0);
  6155. }
  6156. else
  6157. {
  6158. tempIndex = gun_index;
  6159. }
  6160. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6161. {
  6162. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6163. {
  6164. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6165. {
  6166. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6167. }
  6168. }
  6169. }
  6170. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6171. {
  6172. for (int index = 0; index < CCS_QUANTITY; index++)
  6173. {
  6174. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6175. {
  6176. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6177. }
  6178. }
  6179. }
  6180. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6181. {
  6182. for (int index = 0; index < GB_QUANTITY; index++)
  6183. {
  6184. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6185. {
  6186. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6187. }
  6188. }
  6189. }
  6190. else if(gunType[gun_index] == GUN_TYPE_DO)
  6191. {
  6192. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6193. {
  6194. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6195. {
  6196. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6197. }
  6198. }
  6199. }
  6200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6203. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6204. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6205. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6206. } // END FOR DC CASE
  6207. }
  6208. //================================================ Message create ====================================================
  6209. json_object *StopTransaction = json_object_new_object();
  6210. json_object *transactionDatas = json_object_new_array();
  6211. json_object *sampledValues = json_object_new_array();
  6212. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6213. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6214. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6215. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6216. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6217. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6218. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6219. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6220. {
  6221. json_object *transactionData = json_object_new_object();
  6222. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6223. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6224. {
  6225. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6226. {
  6227. json_object *sampledValue = json_object_new_object();
  6228. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6229. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6230. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6231. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6232. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6233. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6234. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6235. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6236. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6237. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6238. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6239. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6240. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6241. json_object_array_add(sampledValues, sampledValue);
  6242. }
  6243. }
  6244. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6245. json_object_array_add(transactionDatas, transactionData);
  6246. }
  6247. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6248. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6249. ,MESSAGE_TYPE_CALL
  6250. ,guid
  6251. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6252. json_object_put(StopTransaction);
  6253. #if 1 // for TempStopTransaction
  6254. //Delete TempStopTransaction
  6255. if((access(TempStopTransaction,F_OK))!=-1)
  6256. {
  6257. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6258. }
  6259. #endif
  6260. #if 1
  6261. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6262. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6263. {
  6264. result = PASS;
  6265. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6266. }
  6267. #endif
  6268. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6269. OCPP_insert_transaction_msg(NO, queuedata);
  6270. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6271. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6272. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6273. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6274. {
  6275. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6276. }
  6277. //for test
  6278. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6279. return result;
  6280. }
  6281. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6282. {
  6283. mtrace();
  6284. int result = FAIL;
  6285. char guid[37]={0};
  6286. char tempdata[65]={0};
  6287. int tempIndex = 0;
  6288. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6289. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6290. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6291. //set value
  6292. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6293. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6294. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6295. -1);
  6296. random_uuid(guid);
  6297. //UTC Date time
  6298. struct timeval tmnow;
  6299. struct tm *tm;
  6300. char buf[28];//, usec_buf[6];
  6301. gettimeofday(&tmnow, NULL);
  6302. time_t t;
  6303. t = time(NULL);
  6304. /*UTC time and date*/
  6305. tm = gmtime(&t);
  6306. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6307. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6308. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6309. //********************************(1)Current.Import L1************************************************/
  6310. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6311. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6312. (dataType == ReadingContext_Trigger))
  6313. {
  6314. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6315. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6316. {
  6317. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6318. {
  6319. tempIndex = ((gun_index==2) ? 1: 0);
  6320. }
  6321. else
  6322. {
  6323. tempIndex = gun_index;
  6324. }
  6325. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6326. {
  6327. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6328. {
  6329. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6330. }
  6331. }
  6332. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6333. }
  6334. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6335. {
  6336. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6337. {
  6338. tempIndex = ((gun_index==2) ? 1: 0);
  6339. }
  6340. else
  6341. {
  6342. tempIndex = gun_index;
  6343. }
  6344. for (int index = 0; index < CCS_QUANTITY; index++)
  6345. {
  6346. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6347. {
  6348. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6349. }
  6350. }
  6351. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6352. }
  6353. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6354. {
  6355. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6356. {
  6357. tempIndex = ((gun_index==2) ? 1: 0);
  6358. }
  6359. else
  6360. {
  6361. tempIndex = gun_index;
  6362. }
  6363. for (int index = 0; index < GB_QUANTITY; index++)
  6364. {
  6365. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6366. {
  6367. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6368. }
  6369. }
  6370. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6371. }
  6372. else if(gunType[gun_index] == GUN_TYPE_DO)
  6373. {
  6374. tempIndex = gun_index;
  6375. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6376. {
  6377. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6378. {
  6379. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6380. }
  6381. }
  6382. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6383. }
  6384. else
  6385. {
  6386. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6387. {
  6388. tempIndex = 2;
  6389. }
  6390. else
  6391. {
  6392. tempIndex = gun_index;
  6393. }
  6394. for (int index = 0; index < AC_QUANTITY; index++)
  6395. {
  6396. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6397. {
  6398. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6399. }
  6400. }
  6401. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6402. }
  6403. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6404. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6405. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6406. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6407. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6408. }
  6409. //********************************(2)Energy.Active.Import.Register ************************************************/
  6410. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6411. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6412. (dataType == ReadingContext_Trigger))
  6413. {
  6414. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6415. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6416. {
  6417. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6418. {
  6419. tempIndex = ((gun_index==2) ? 1: 0);
  6420. }
  6421. else
  6422. {
  6423. tempIndex = gun_index;
  6424. }
  6425. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6426. {
  6427. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6428. {
  6429. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6430. }
  6431. }
  6432. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6433. }
  6434. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6435. {
  6436. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6437. {
  6438. tempIndex = ((gun_index==2) ? 1: 0);
  6439. }
  6440. else
  6441. {
  6442. tempIndex = gun_index;
  6443. }
  6444. for (int index = 0; index < CCS_QUANTITY; index++)
  6445. {
  6446. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6447. {
  6448. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6449. }
  6450. }
  6451. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6452. }
  6453. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6454. {
  6455. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6456. {
  6457. tempIndex = ((gun_index==2) ? 1: 0);
  6458. }
  6459. else
  6460. {
  6461. tempIndex = gun_index;
  6462. }
  6463. for (int index = 0; index < GB_QUANTITY; index++)
  6464. {
  6465. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6466. {
  6467. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6468. }
  6469. }
  6470. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6471. }
  6472. else if(gunType[gun_index] == GUN_TYPE_DO)
  6473. {
  6474. tempIndex = gun_index;
  6475. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6476. {
  6477. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6478. {
  6479. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6480. }
  6481. }
  6482. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6483. }
  6484. else
  6485. {
  6486. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6487. {
  6488. tempIndex = 2;
  6489. }
  6490. else
  6491. {
  6492. tempIndex = gun_index;
  6493. }
  6494. for (int index = 0; index < AC_QUANTITY; index++)
  6495. {
  6496. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6497. {
  6498. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6499. }
  6500. }
  6501. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6502. }
  6503. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6504. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6505. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6506. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6507. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6508. }
  6509. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6510. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6511. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6512. (dataType == ReadingContext_Trigger))
  6513. {
  6514. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6515. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6516. {
  6517. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6518. {
  6519. tempIndex = ((gun_index==2) ? 1: 0);
  6520. }
  6521. else
  6522. {
  6523. tempIndex = gun_index;
  6524. }
  6525. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6526. {
  6527. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6528. {
  6529. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6530. }
  6531. } // END OF FOR CHAdeMO_QUANTITY
  6532. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6533. }
  6534. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6535. {
  6536. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6537. {
  6538. tempIndex = ((gun_index==2) ? 1: 0);
  6539. }
  6540. else
  6541. {
  6542. tempIndex = gun_index;
  6543. }
  6544. for (int index = 0; index < CCS_QUANTITY; index++)
  6545. {
  6546. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6547. {
  6548. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6549. }
  6550. } // END OF CCS_QUANTITY
  6551. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6552. }
  6553. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6554. {
  6555. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6556. {
  6557. tempIndex = ((gun_index==2) ? 1: 0);
  6558. }
  6559. else
  6560. {
  6561. tempIndex = gun_index;
  6562. }
  6563. for (int index = 0; index < GB_QUANTITY; index++)
  6564. {
  6565. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6566. {
  6567. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6568. }
  6569. } // END OF GB_QUANTITY
  6570. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6571. }
  6572. else if(gunType[gun_index] == GUN_TYPE_DO)
  6573. {
  6574. tempIndex = gun_index;
  6575. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6576. {
  6577. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6578. {
  6579. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6580. }
  6581. }
  6582. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6583. }
  6584. else
  6585. {
  6586. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6587. {
  6588. tempIndex = 2;
  6589. }
  6590. else
  6591. {
  6592. tempIndex = gun_index;
  6593. }
  6594. for (int index = 0; index < AC_QUANTITY; index++)
  6595. {
  6596. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6597. {
  6598. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6599. }
  6600. }
  6601. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6602. }
  6603. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6604. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6605. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6606. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6607. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6608. }
  6609. //********************************(4)Power.Active.Import************************************************/
  6610. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6611. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6612. (dataType == ReadingContext_Trigger))
  6613. {
  6614. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6615. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6616. {
  6617. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6618. {
  6619. tempIndex = ((gun_index==2) ? 1: 0);
  6620. }
  6621. else
  6622. {
  6623. tempIndex = gun_index;
  6624. }
  6625. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6626. {
  6627. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6628. {
  6629. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6630. }
  6631. } // END OF FOR
  6632. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6633. }
  6634. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6635. {
  6636. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6637. {
  6638. tempIndex = ((gun_index==2) ? 1: 0);
  6639. }
  6640. else
  6641. {
  6642. tempIndex = gun_index;
  6643. }
  6644. for (int index = 0; index < CCS_QUANTITY; index++)
  6645. {
  6646. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6647. {
  6648. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6649. }
  6650. }
  6651. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6652. }
  6653. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6654. {
  6655. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6656. {
  6657. tempIndex = ((gun_index==2) ? 1: 0);
  6658. }
  6659. else
  6660. {
  6661. tempIndex = gun_index;
  6662. }
  6663. for (int index = 0; index < GB_QUANTITY; index++)
  6664. {
  6665. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6666. {
  6667. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6668. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6669. }
  6670. }
  6671. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6672. }
  6673. else if(gunType[gun_index] == GUN_TYPE_DO)
  6674. {
  6675. tempIndex = gun_index;
  6676. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6677. {
  6678. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6679. {
  6680. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6681. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6682. }
  6683. }
  6684. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6685. }
  6686. else
  6687. {
  6688. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6689. {
  6690. tempIndex = 2;
  6691. }
  6692. else
  6693. {
  6694. tempIndex = gun_index;
  6695. }
  6696. for (int index = 0; index < AC_QUANTITY; index++)
  6697. {
  6698. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6699. {
  6700. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6701. }
  6702. }
  6703. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6704. }
  6705. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6706. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6707. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6708. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6709. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6710. }
  6711. //***********************************************(5)VOLTAGE L1******************************************************/
  6712. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6713. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6714. (dataType == ReadingContext_Trigger))
  6715. {
  6716. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6717. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6718. {
  6719. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6720. {
  6721. tempIndex = ((gun_index==2) ? 1: 0);
  6722. }
  6723. else
  6724. {
  6725. tempIndex = gun_index;
  6726. }
  6727. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6728. {
  6729. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6730. {
  6731. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6732. }
  6733. }
  6734. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6735. }
  6736. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6737. {
  6738. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6739. {
  6740. tempIndex = ((gun_index==2) ? 1: 0);
  6741. }
  6742. else
  6743. {
  6744. tempIndex = gun_index;
  6745. }
  6746. for (int index = 0; index < CCS_QUANTITY; index++)
  6747. {
  6748. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6749. {
  6750. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6751. }
  6752. }
  6753. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6754. }
  6755. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6756. {
  6757. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6758. {
  6759. tempIndex = ((gun_index==2) ? 1: 0);
  6760. }
  6761. else
  6762. {
  6763. tempIndex = gun_index;
  6764. }
  6765. for (int index = 0; index < GB_QUANTITY; index++)
  6766. {
  6767. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6768. {
  6769. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6770. }
  6771. }
  6772. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6773. }
  6774. else if(gunType[gun_index] == GUN_TYPE_DO)
  6775. {
  6776. tempIndex = gun_index;
  6777. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6778. {
  6779. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6780. {
  6781. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6782. }
  6783. }
  6784. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6785. }
  6786. else
  6787. {
  6788. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6789. {
  6790. tempIndex = 2;
  6791. }
  6792. else
  6793. {
  6794. tempIndex = gun_index;
  6795. }
  6796. for (int index = 0; index < AC_QUANTITY; index++)
  6797. {
  6798. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6799. {
  6800. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6801. }
  6802. }
  6803. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6804. }
  6805. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6806. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6807. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6808. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6809. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6810. }
  6811. //***********************************************(6)SOC******************************************************/
  6812. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6813. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6814. (dataType == ReadingContext_Trigger))
  6815. {
  6816. 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))
  6817. {
  6818. //idx_sample=5;
  6819. //sampledValue = NULL;
  6820. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6821. {
  6822. tempIndex = ((gun_index==2) ? 1: 0);
  6823. }
  6824. else
  6825. {
  6826. tempIndex = gun_index;
  6827. }
  6828. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6829. {
  6830. //tempIndex = ((gun_index==2) ? 1: 0);
  6831. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6832. {
  6833. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6834. {
  6835. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6836. }
  6837. }
  6838. }
  6839. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6840. {
  6841. //tempIndex = ((gun_index==2) ? 1: 0);
  6842. for (int index = 0; index < CCS_QUANTITY; index++)
  6843. {
  6844. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6845. {
  6846. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6847. }
  6848. }
  6849. }
  6850. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6851. {
  6852. //tempIndex = ((gun_index==2) ? 1: 0);
  6853. for (int index = 0; index < GB_QUANTITY; index++)
  6854. {
  6855. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6856. {
  6857. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6858. }
  6859. }
  6860. }
  6861. else if(gunType[gun_index] == GUN_TYPE_DO)
  6862. {
  6863. //tempIndex = ((gun_index==2) ? 1: 0);
  6864. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6865. {
  6866. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6867. {
  6868. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6869. }
  6870. }
  6871. }
  6872. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6873. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6874. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6875. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6876. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6877. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6878. }
  6879. }
  6880. //********************************(7)Current.Import L2************************************************/
  6881. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6882. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6883. (dataType == ReadingContext_Trigger))
  6884. {
  6885. // Only for AC 3 phase
  6886. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6887. {
  6888. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6889. {
  6890. tempIndex = 2;
  6891. }
  6892. else
  6893. {
  6894. tempIndex = gun_index;
  6895. }
  6896. for (int index = 0; index < AC_QUANTITY; index++)
  6897. {
  6898. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6899. {
  6900. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6901. }
  6902. }
  6903. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6904. }
  6905. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6906. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6907. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6908. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6909. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6910. }
  6911. //********************************(8)Current.Import L3************************************************/
  6912. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6913. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6914. (dataType == ReadingContext_Trigger))
  6915. {
  6916. // Only for AC 3 phase
  6917. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6918. {
  6919. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6920. {
  6921. tempIndex = 2;
  6922. }
  6923. else
  6924. {
  6925. tempIndex = gun_index;
  6926. }
  6927. for (int index = 0; index < AC_QUANTITY; index++)
  6928. {
  6929. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6930. {
  6931. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6932. }
  6933. }
  6934. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6935. }
  6936. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6937. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6938. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6939. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6940. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6941. }
  6942. //***********************************************(9)VOLTAGE L2******************************************************/
  6943. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6944. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6945. (dataType == ReadingContext_Trigger))
  6946. {
  6947. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6948. {
  6949. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6950. {
  6951. tempIndex = 2;
  6952. }
  6953. else
  6954. {
  6955. tempIndex = gun_index;
  6956. }
  6957. for (int index = 0; index < AC_QUANTITY; index++)
  6958. {
  6959. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6960. {
  6961. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6962. }
  6963. }
  6964. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6965. }
  6966. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6967. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6968. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6969. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6970. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6971. }
  6972. //***********************************************(10)VOLTAGE L3******************************************************/
  6973. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6974. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6975. (dataType == ReadingContext_Trigger))
  6976. {
  6977. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6978. {
  6979. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6980. {
  6981. tempIndex = 2;
  6982. }
  6983. else
  6984. {
  6985. tempIndex = gun_index;
  6986. }
  6987. for (int index = 0; index < AC_QUANTITY; index++)
  6988. {
  6989. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6990. {
  6991. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6992. }
  6993. }
  6994. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6995. }
  6996. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6997. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6998. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6999. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7000. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7001. }
  7002. //***********************************************(11)Current.Offered******************************************************/
  7003. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7004. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7005. (dataType == ReadingContext_Trigger))
  7006. {
  7007. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7008. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7009. {
  7010. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7011. {
  7012. tempIndex = ((gun_index==2) ? 1: 0);
  7013. }
  7014. else
  7015. {
  7016. tempIndex = gun_index;
  7017. }
  7018. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7019. {
  7020. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7021. {
  7022. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7023. }
  7024. } // END OF FOR CHAdeMO_QUANTITY
  7025. }
  7026. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7027. {
  7028. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7029. {
  7030. tempIndex = ((gun_index==2) ? 1: 0);
  7031. }
  7032. else
  7033. {
  7034. tempIndex = gun_index;
  7035. }
  7036. for (int index = 0; index < CCS_QUANTITY; index++)
  7037. {
  7038. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7039. {
  7040. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7041. }
  7042. } // END OF CCS_QUANTITY
  7043. }
  7044. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7045. {
  7046. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7047. {
  7048. tempIndex = ((gun_index==2) ? 1: 0);
  7049. }
  7050. else
  7051. {
  7052. tempIndex = gun_index;
  7053. }
  7054. for (int index = 0; index < GB_QUANTITY; index++)
  7055. {
  7056. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7057. {
  7058. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7059. }
  7060. } // END OF GB_QUANTITY
  7061. }
  7062. else if(gunType[gun_index] == GUN_TYPE_DO)
  7063. {
  7064. tempIndex = gun_index;
  7065. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7066. {
  7067. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7068. {
  7069. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7070. }
  7071. }
  7072. }
  7073. else
  7074. {
  7075. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7076. {
  7077. tempIndex = 2;
  7078. }
  7079. else
  7080. {
  7081. tempIndex = gun_index;
  7082. }
  7083. for (int index = 0; index < AC_QUANTITY; index++)
  7084. {
  7085. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7086. {
  7087. uint16_t currentOffer;
  7088. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7089. {
  7090. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7091. }
  7092. else
  7093. {
  7094. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7095. }
  7096. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7097. }
  7098. }
  7099. }
  7100. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7101. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7102. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7103. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7104. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7105. }
  7106. //***********************************************(12)Power.Offered******************************************************/
  7107. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7108. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7109. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7110. {
  7111. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7112. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7113. {
  7114. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7115. {
  7116. tempIndex = ((gun_index==2) ? 1: 0);
  7117. }
  7118. else
  7119. {
  7120. tempIndex = gun_index;
  7121. }
  7122. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7123. {
  7124. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7125. {
  7126. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7127. }
  7128. } // END OF FOR CHAdeMO_QUANTITY
  7129. }
  7130. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7131. {
  7132. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7133. {
  7134. tempIndex = ((gun_index==2) ? 1: 0);
  7135. }
  7136. else
  7137. {
  7138. tempIndex = gun_index;
  7139. }
  7140. for (int index = 0; index < CCS_QUANTITY; index++)
  7141. {
  7142. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7143. {
  7144. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7145. }
  7146. } // END OF CCS_QUANTITY
  7147. }
  7148. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7149. {
  7150. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7151. {
  7152. tempIndex = ((gun_index==2) ? 1: 0);
  7153. }
  7154. else
  7155. {
  7156. tempIndex = gun_index;
  7157. }
  7158. for (int index = 0; index < GB_QUANTITY; index++)
  7159. {
  7160. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7161. {
  7162. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7163. }
  7164. } // END OF GB_QUANTITY
  7165. }
  7166. else if(gunType[gun_index] == GUN_TYPE_DO)
  7167. {
  7168. tempIndex = gun_index;
  7169. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7170. {
  7171. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7172. {
  7173. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7174. }
  7175. }
  7176. }
  7177. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7178. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7179. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7180. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7181. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7182. }
  7183. // Message create ====================================================================================================
  7184. if(TRUE)
  7185. {
  7186. json_object *MeterValueReq = json_object_new_object();
  7187. json_object *MeterValues = json_object_new_array();
  7188. json_object *sampledValues = json_object_new_array();
  7189. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7190. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7191. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7192. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7193. {
  7194. json_object *MeterValue = json_object_new_object();
  7195. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7196. {
  7197. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7198. {
  7199. json_object *sampledValue = json_object_new_object();
  7200. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7201. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7202. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7203. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7204. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7205. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7206. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7207. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7208. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7209. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7210. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7211. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7212. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7213. json_object_array_add(sampledValues, sampledValue);
  7214. }
  7215. }
  7216. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7217. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7218. json_object_array_add(MeterValues, MeterValue);
  7219. }
  7220. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7221. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7222. ,gun_index + 1
  7223. ,MESSAGE_TYPE_CALL
  7224. ,guid
  7225. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7226. json_object_put(MeterValueReq);
  7227. }
  7228. // Put request guid to hash map
  7229. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7230. 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*/)
  7231. {
  7232. result = PASS;
  7233. //DEBUG_INFO("MeterValues mapitem pass\n");
  7234. }
  7235. if((dataType != ReadingContext_Trigger) &&
  7236. (dataType != ReadingContext_Sample_Clock) &&
  7237. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7238. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7239. else
  7240. {
  7241. if(FirstHeartBeat)
  7242. LWS_Send(queuedata +2);
  7243. }
  7244. return result;
  7245. }
  7246. int sendLogStatusNotificationRequest(char *status)
  7247. {
  7248. mtrace();
  7249. int result = PASS;
  7250. char message[4096]={0};
  7251. char guid[37]={0};
  7252. char tempdata[128]={0};
  7253. json_object *LogStatusNotification = json_object_new_object();
  7254. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7255. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7256. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7257. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7258. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7259. random_uuid(guid);
  7260. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7261. json_object_put(LogStatusNotification);
  7262. LWS_Send(message);
  7263. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7264. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7265. {
  7266. result = PASS;
  7267. }
  7268. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7269. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7270. return result;
  7271. }
  7272. int sendSecurityEventNotificationRequest()
  7273. {
  7274. mtrace();
  7275. int result = PASS;
  7276. char message[4096]={0};
  7277. char guid[37]={0};
  7278. char tempdata[128]={0};
  7279. json_object *SecurityEventNotification = json_object_new_object();
  7280. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7281. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7282. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7283. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7284. random_uuid(guid);
  7285. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7286. json_object_put(SecurityEventNotification);
  7287. LWS_Send(message);
  7288. sprintf(tempdata, "SecurityEventNotification,0");
  7289. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7290. {
  7291. result = PASS;
  7292. }
  7293. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7294. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7295. return result;
  7296. }
  7297. int sendSignCertificateRequest()
  7298. {
  7299. mtrace();
  7300. int result = PASS;
  7301. char message[4096]={0};
  7302. char guid[37]={0};
  7303. char tempdata[128]={0};
  7304. json_object *SignCertificate = json_object_new_object();
  7305. DEBUG_INFO("sendSignCertificateRequest...\n");
  7306. // Read csr file content
  7307. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7308. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7309. char *line = NULL;
  7310. size_t len = 0;
  7311. while(getline(&line, &len, fp) != -1)
  7312. {
  7313. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7314. {
  7315. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7316. }
  7317. }
  7318. fclose(fp);
  7319. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7320. random_uuid(guid);
  7321. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7322. json_object_put(SignCertificate);
  7323. LWS_Send(message);
  7324. sprintf(tempdata, "SignCertificate,0");
  7325. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7326. {
  7327. result = PASS;
  7328. }
  7329. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7330. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7331. return result;
  7332. }
  7333. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7334. {
  7335. mtrace();
  7336. int result = PASS;
  7337. char message[110]={0};
  7338. char guid[37]={0};
  7339. char tempdata[65]={0};
  7340. json_object *FirmwareStatusNotification = json_object_new_object();
  7341. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7342. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7343. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7344. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7345. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7346. random_uuid(guid);
  7347. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7348. json_object_put(FirmwareStatusNotification);
  7349. LWS_Send(message);
  7350. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7351. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7352. {
  7353. result = PASS;
  7354. }
  7355. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7356. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7357. return result;
  7358. }
  7359. //==========================================
  7360. // send confirm routine
  7361. //==========================================
  7362. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7363. {
  7364. mtrace();
  7365. int result = FAIL;
  7366. char message[100]={0};
  7367. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7368. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7369. LWS_Send(message);
  7370. result = TRUE;
  7371. return result;
  7372. }
  7373. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7374. {
  7375. mtrace();
  7376. int result = FAIL;
  7377. char message[100]={0};
  7378. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7379. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7380. LWS_Send(message);
  7381. result = TRUE;
  7382. return result;
  7383. }
  7384. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7385. {
  7386. mtrace();
  7387. int result = FAIL;
  7388. char message[100]={0};
  7389. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7390. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7391. LWS_Send(message);
  7392. result = TRUE;
  7393. return result;
  7394. }
  7395. int sendClearCacheConfirmation(char *uuid,char *payload)
  7396. {
  7397. mtrace();
  7398. int result = FAIL;
  7399. char message[500]={0};
  7400. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7401. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7402. LWS_Send(message);
  7403. return result;
  7404. }
  7405. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7406. {
  7407. mtrace();
  7408. int result = FAIL;
  7409. char message[500]={0};
  7410. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7411. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7412. LWS_Send(message);
  7413. return result;
  7414. }
  7415. int sendDataTransferConfirmation(char *uuid,char *payload)
  7416. {
  7417. mtrace();
  7418. char statusStr[20]={0};
  7419. char dataStr[10]={0};
  7420. char sstr[20]={0};
  7421. int c = 0;
  7422. char *loc;
  7423. int result = FAIL;
  7424. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7425. /**********************status**************************/
  7426. loc = strstr(payload, "status");
  7427. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7428. c = 0;
  7429. while (loc[3+strlen("status")+c] != '\"')
  7430. {
  7431. sstr[c] = loc[3+strlen("status")+c];
  7432. c++;
  7433. }
  7434. sstr[c] = '\0';
  7435. strcpy(statusStr, sstr);
  7436. /**********************data**************************/
  7437. loc = strstr(payload, "data");
  7438. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7439. c = 0;
  7440. while (loc[3+strlen("data")+c] != '\"')
  7441. {
  7442. sstr[c] = loc[3+strlen("data")+c];
  7443. c++;
  7444. }
  7445. sstr[c] = '\0';
  7446. strcpy(dataStr, sstr);
  7447. return result;
  7448. }
  7449. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7450. {
  7451. mtrace();
  7452. int result = FAIL;
  7453. char message[1000]={0};
  7454. int CompositeScheduleIndex = 0;
  7455. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7456. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7457. if(nPeriod == 0)
  7458. {
  7459. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7460. {
  7461. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7462. ,MESSAGE_TYPE_CALLRESULT
  7463. ,uuid
  7464. ,payload
  7465. ,connectorIdInt);
  7466. }
  7467. else
  7468. {
  7469. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7470. ,MESSAGE_TYPE_CALLRESULT
  7471. ,uuid
  7472. ,payload
  7473. ,connectorIdInt
  7474. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7475. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7476. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7477. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7478. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7479. }
  7480. }
  7481. else
  7482. {
  7483. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7484. ,MESSAGE_TYPE_CALLRESULT
  7485. ,uuid
  7486. ,payload
  7487. ,connectorIdInt
  7488. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7489. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7490. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7491. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7492. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7493. {
  7494. if (idx_sample == 0)
  7495. {
  7496. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7497. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7498. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7499. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7500. }
  7501. else
  7502. {
  7503. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7504. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7505. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7506. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7507. }
  7508. }
  7509. sprintf(message + strlen(message), "]}}]");
  7510. }
  7511. LWS_Send(message);
  7512. result = TRUE;
  7513. return result;
  7514. }
  7515. int sendGetConfigurationConfirmation(char *uuid)
  7516. {
  7517. mtrace();
  7518. int result = FAIL;
  7519. int MaxKeySupported = 0;
  7520. int sentConfigurationNumber= 0;
  7521. int sentunConfigurationNumber= 0;
  7522. char message[1024*10]={0};
  7523. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7524. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7525. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7526. ,MESSAGE_TYPE_CALLRESULT
  7527. ,uuid );
  7528. //configuration key
  7529. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7530. {
  7531. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7532. {
  7533. if (sentConfigurationNumber == 0)
  7534. {
  7535. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7536. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7537. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7538. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7539. }
  7540. else
  7541. {
  7542. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7543. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7544. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7545. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7546. }
  7547. sentConfigurationNumber = sentConfigurationNumber + 1;
  7548. }
  7549. }
  7550. sprintf(message + strlen(message), "]");
  7551. if(UnknownKeynum != 0)
  7552. {
  7553. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7554. //unkown key
  7555. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7556. {
  7557. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7558. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7559. if(sentunConfigurationNumber == 0)
  7560. {
  7561. sprintf(message + strlen(message), "\"%s\""
  7562. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7563. }
  7564. else
  7565. {
  7566. sprintf(message + strlen(message), ",\"%s\""
  7567. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7568. }
  7569. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7570. }
  7571. sprintf(message + strlen(message), "]");
  7572. }
  7573. sprintf(message + strlen(message), "}]");
  7574. LWS_Send(message);
  7575. return result;
  7576. }
  7577. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7578. {
  7579. mtrace();
  7580. int result = FAIL;
  7581. char message[400]={0};
  7582. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7583. if(strcmp(payload,"")==0)
  7584. {
  7585. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7586. }
  7587. else
  7588. {
  7589. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7590. }
  7591. LWS_Send(message);
  7592. result = TRUE;
  7593. return result;
  7594. }
  7595. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7596. {
  7597. mtrace();
  7598. int result = FAIL;
  7599. char message[80]={0};
  7600. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7601. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  7602. LWS_Send(message);
  7603. result = TRUE;
  7604. return result;
  7605. }
  7606. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7607. {
  7608. mtrace();
  7609. int result = FAIL;
  7610. char message[80]={0};
  7611. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7612. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7613. LWS_Send(message);
  7614. result = TRUE;
  7615. return result;
  7616. }
  7617. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7618. {
  7619. mtrace();
  7620. int result = FAIL;
  7621. char message[80]={0};
  7622. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7623. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7624. LWS_Send(message);
  7625. result = TRUE;
  7626. return result;
  7627. }
  7628. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7629. {
  7630. mtrace();
  7631. int result = FAIL;
  7632. char message[80]={0};
  7633. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7634. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7635. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7636. LWS_Send(message);
  7637. result = TRUE;
  7638. return result;
  7639. }
  7640. int sendResetConfirmation(char *uuid,char *payload)
  7641. {
  7642. mtrace();
  7643. int result = FAIL;
  7644. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7645. char message[80]={0};
  7646. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  7647. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7648. LWS_Send(message);
  7649. result = TRUE;
  7650. return result;
  7651. }
  7652. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7653. {
  7654. mtrace();
  7655. int result = FAIL;
  7656. char message[500]={0};
  7657. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7658. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7659. LWS_Send(message);
  7660. result = TRUE;
  7661. return result;
  7662. }
  7663. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7664. {
  7665. mtrace();
  7666. int result = FAIL;
  7667. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7668. char message[80]={0};
  7669. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7670. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7671. LWS_Send(message);
  7672. result = TRUE;
  7673. return result;
  7674. }
  7675. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7676. {
  7677. mtrace();
  7678. int result = FAIL;
  7679. char message[80]={0};
  7680. DEBUG_INFO("sendTriggerMessageConfirmation...\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 sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7687. {
  7688. mtrace();
  7689. int result = FAIL;
  7690. char message[80]={0};
  7691. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7692. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  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 sendUpdateFirmwareConfirmation(char *uuid)
  7699. {
  7700. mtrace();
  7701. int result = FAIL;
  7702. char message[60]={0};
  7703. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7704. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7705. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7706. LWS_Send(message);
  7707. result = TRUE;
  7708. return result;
  7709. }
  7710. int sendCertificateSignedConfirmation(char *uuid)
  7711. {
  7712. mtrace();
  7713. int result = PASS;
  7714. char message[4096]={0};
  7715. json_object *CertificateSigned = json_object_new_object();
  7716. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7717. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  7718. sprintf(message,"[%d,\"%s\",%s]"
  7719. ,MESSAGE_TYPE_CALLRESULT
  7720. ,uuid
  7721. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7722. json_object_put(CertificateSigned);
  7723. LWS_Send(message);
  7724. return result;
  7725. }
  7726. int sendDeleteCertificateConfirmation(char *uuid)
  7727. {
  7728. mtrace();
  7729. int result = PASS;
  7730. char message[4096]={0};
  7731. json_object *DeleteCertificate = json_object_new_object();
  7732. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7733. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  7734. sprintf(message,"[%d,\"%s\",%s]"
  7735. ,MESSAGE_TYPE_CALLRESULT
  7736. ,uuid
  7737. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7738. json_object_put(DeleteCertificate);
  7739. LWS_Send(message);
  7740. return result;
  7741. }
  7742. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7743. {
  7744. mtrace();
  7745. int result = PASS;
  7746. char message[4096]={0};
  7747. json_object *ExtendedTriggerMessage = json_object_new_object();
  7748. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7749. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  7750. sprintf(message,"[%d,\"%s\",%s]"
  7751. ,MESSAGE_TYPE_CALLRESULT
  7752. ,uuid
  7753. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7754. json_object_put(ExtendedTriggerMessage);
  7755. LWS_Send(message);
  7756. return result;
  7757. }
  7758. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7759. {
  7760. mtrace();
  7761. int result = PASS;
  7762. char message[4096]={0};
  7763. json_object *GetInstalledCertificateIds = json_object_new_object();
  7764. json_object *certificateHashDataDatas = json_object_new_array();
  7765. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7766. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  7767. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7768. {
  7769. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7770. {
  7771. json_object *certificateHashData = json_object_new_object();
  7772. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7773. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7774. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7775. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7776. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7777. }
  7778. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7779. }
  7780. else
  7781. {
  7782. json_object_put(certificateHashDataDatas);
  7783. }
  7784. sprintf(message,"[%d,\"%s\",%s]"
  7785. ,MESSAGE_TYPE_CALLRESULT
  7786. ,uuid
  7787. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7788. json_object_put(GetInstalledCertificateIds);
  7789. LWS_Send(message);
  7790. return result;
  7791. }
  7792. int sendGetLogConfirmation(char *uuid)
  7793. {
  7794. mtrace();
  7795. int result = PASS;
  7796. char message[4096]={0};
  7797. json_object *GetLog = json_object_new_object();
  7798. DEBUG_INFO("sendGetLogConfirmation...\n");
  7799. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  7800. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  7801. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  7802. sprintf(message,"[%d,\"%s\",%s]"
  7803. ,MESSAGE_TYPE_CALLRESULT
  7804. ,uuid
  7805. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7806. json_object_put(GetLog);
  7807. LWS_Send(message);
  7808. return result;
  7809. }
  7810. int sendInstallCertificateConfirmation(char *uuid)
  7811. {
  7812. mtrace();
  7813. int result = PASS;
  7814. char message[4096]={0};
  7815. json_object *InstallCertificate = json_object_new_object();
  7816. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7817. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  7818. sprintf(message,"[%d,\"%s\",%s]"
  7819. ,MESSAGE_TYPE_CALLRESULT
  7820. ,uuid
  7821. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7822. json_object_put(InstallCertificate);
  7823. LWS_Send(message);
  7824. return result;
  7825. }
  7826. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7827. {
  7828. mtrace();
  7829. int result = PASS;
  7830. char message[4096]={0};
  7831. json_object *SignedUpdateFirmware = json_object_new_object();
  7832. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7833. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  7834. sprintf(message,"[%d,\"%s\",%s]"
  7835. ,MESSAGE_TYPE_CALLRESULT
  7836. ,uuid
  7837. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7838. json_object_put(SignedUpdateFirmware);
  7839. LWS_Send(message);
  7840. return result;
  7841. }
  7842. int sendUnknownConfirmation(char *uuid)
  7843. {
  7844. mtrace();
  7845. int result = PASS;
  7846. char message[256]={0};
  7847. DEBUG_INFO("sendUnknownConfirmation...\n");
  7848. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7849. LWS_Send(message);
  7850. return result;
  7851. }
  7852. //==========================================
  7853. // Handle server request routine Start
  7854. //==========================================
  7855. int handleCancelReservationRequest(char *uuid, char *payload)
  7856. {
  7857. mtrace();
  7858. int result = FAIL;
  7859. int gunNO = 0;
  7860. int reservationIdInt = -1;
  7861. char comfirmstr[20];
  7862. DEBUG_INFO("handleCancelReservationRequest...\n");
  7863. json_object *CancelReservation;
  7864. CancelReservation = json_tokener_parse(payload);
  7865. if(!is_error(CancelReservation))
  7866. {
  7867. // Required data
  7868. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7869. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7870. }
  7871. json_object_put(CancelReservation);
  7872. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7873. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7874. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7875. if(reservationIdInt != -1)
  7876. {
  7877. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7878. //check Transaction active
  7879. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7880. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7881. {
  7882. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7883. {
  7884. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7885. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7886. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7887. {
  7888. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7889. }
  7890. else
  7891. {
  7892. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7893. }
  7894. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7895. goto end;
  7896. }
  7897. }
  7898. for (int index = 0; index < CCS_QUANTITY; index++)
  7899. {
  7900. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7901. {
  7902. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7903. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7904. if(gunType[2] == GUN_TYPE_CCS)
  7905. {
  7906. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7907. }
  7908. else
  7909. {
  7910. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7911. }
  7912. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7913. goto end;
  7914. }
  7915. }
  7916. for (int index = 0; index < GB_QUANTITY; index++)
  7917. {
  7918. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7919. {
  7920. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7921. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7922. if(gunType[2] == GUN_TYPE_GBT)
  7923. {
  7924. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7925. }
  7926. else
  7927. {
  7928. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7929. }
  7930. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7931. goto end;
  7932. }
  7933. }
  7934. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7935. {
  7936. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7937. {
  7938. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7939. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7940. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7941. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7942. goto end;
  7943. }
  7944. }
  7945. for (int index = 0; index < AC_QUANTITY; index++)
  7946. {
  7947. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7948. {
  7949. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7950. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7951. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7952. {
  7953. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7954. }
  7955. else
  7956. {
  7957. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7958. }
  7959. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7960. goto end;
  7961. }
  7962. }
  7963. }
  7964. //The reservationId does NOT match the reservationId
  7965. sendCancelReservationConfirmation(uuid, comfirmstr);
  7966. end:
  7967. // Fill in ocpp packet uuid
  7968. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  7969. return result;
  7970. }
  7971. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7972. {
  7973. mtrace();
  7974. int result = FAIL;
  7975. int gunIndex = -1;
  7976. char typeStr[16]={0};
  7977. char comfirmstr[20];
  7978. int specificId = FALSE;
  7979. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7980. json_object *ChangeAvailability;
  7981. ChangeAvailability = json_tokener_parse(payload);
  7982. if(!is_error(ChangeAvailability))
  7983. {
  7984. // Required data
  7985. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7986. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7987. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7988. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7989. }
  7990. json_object_put(ChangeAvailability);
  7991. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7992. {
  7993. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7994. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7995. }
  7996. else if(gunIndex == 0)
  7997. {
  7998. for(int i=0; i < gunTotalNumber; i++)
  7999. {
  8000. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8001. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8002. }
  8003. }
  8004. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8005. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8006. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8007. {
  8008. specificId = TRUE;
  8009. }
  8010. if(specificId == FALSE)
  8011. goto end;
  8012. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8013. {
  8014. //----------------------gunIndex is 0 ------------------------------------------------//
  8015. if(gunIndex == 0)
  8016. {
  8017. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8018. {
  8019. for(int i=0; i < gunTotalNumber; i++)
  8020. {
  8021. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8022. {
  8023. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8024. {
  8025. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8026. {
  8027. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8028. goto end;
  8029. }
  8030. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8031. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8032. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8033. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8034. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8035. {
  8036. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8037. goto end;
  8038. }
  8039. }
  8040. }//END FOR CHAdeMO_QUANTITY
  8041. for (int index = 0; index < CCS_QUANTITY; index++)
  8042. {
  8043. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8044. {
  8045. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8046. {
  8047. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8048. goto end;
  8049. }
  8050. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8051. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8052. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8053. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8054. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8055. {
  8056. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8057. goto end;
  8058. }
  8059. }
  8060. }//END FOR CCS_QUANTITY
  8061. for (int index = 0; index < GB_QUANTITY; index++)
  8062. {
  8063. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8064. {
  8065. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8066. {
  8067. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8068. goto end;
  8069. }
  8070. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8071. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8072. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8073. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8074. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8075. {
  8076. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8077. goto end;
  8078. }
  8079. }
  8080. }// END FOR GB_QUANTITY
  8081. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8082. {
  8083. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8084. {
  8085. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8086. {
  8087. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8088. goto end;
  8089. }
  8090. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8091. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8092. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8093. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8094. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8095. {
  8096. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8097. goto end;
  8098. }
  8099. }
  8100. }// END FOR GENERAL_GUN_QUANTITY
  8101. for (int index = 0; index < AC_QUANTITY; index++)
  8102. {
  8103. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8104. {
  8105. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8106. {
  8107. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8108. goto end;
  8109. }
  8110. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8111. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8112. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8113. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8114. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8115. {
  8116. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8117. goto end;
  8118. }
  8119. }
  8120. }//END FOR AC_QUANTITY
  8121. }// END FOR gunTotalNumber
  8122. }
  8123. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8124. {
  8125. for(int i=0; i < gunTotalNumber; i++)
  8126. {
  8127. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8128. {
  8129. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8130. goto end;
  8131. }
  8132. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8133. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8134. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8135. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8136. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8137. {
  8138. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8139. goto end;
  8140. }
  8141. }
  8142. }
  8143. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8144. goto end;
  8145. }
  8146. //----------------------gunIndex is not 0 ------------------------------------------------//
  8147. //check Transaction active
  8148. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8149. {
  8150. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8151. {
  8152. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8153. {
  8154. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8155. goto end;
  8156. }
  8157. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8158. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8159. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8160. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8161. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8162. {
  8163. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8164. goto end;
  8165. }
  8166. else
  8167. {
  8168. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8169. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8170. goto end;
  8171. }
  8172. }
  8173. }//END FOR CHAdeMO_QUANTITY
  8174. for (int index = 0; index < CCS_QUANTITY; index++)
  8175. {
  8176. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8177. {
  8178. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8179. {
  8180. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8181. goto end;
  8182. }
  8183. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8184. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8185. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8186. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8187. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8188. {
  8189. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8190. goto end;
  8191. }
  8192. else
  8193. {
  8194. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8195. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8196. goto end;
  8197. }
  8198. }
  8199. }//END FOR CCS_QUANTITY
  8200. for (int index = 0; index < GB_QUANTITY; index++)
  8201. {
  8202. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8203. {
  8204. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8205. {
  8206. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8207. goto end;
  8208. }
  8209. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8210. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8211. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8212. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8213. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8214. {
  8215. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8216. goto end;
  8217. }
  8218. else
  8219. {
  8220. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8221. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8222. goto end;
  8223. }
  8224. }
  8225. }// END FOR GB_QUANTITY
  8226. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8227. {
  8228. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8229. {
  8230. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8231. {
  8232. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8233. goto end;
  8234. }
  8235. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8236. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8237. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8238. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8239. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8240. {
  8241. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8242. goto end;
  8243. }
  8244. else
  8245. {
  8246. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8247. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8248. goto end;
  8249. }
  8250. }
  8251. }// END FOR GENERAL_GUN_QUANTITY
  8252. for (int index = 0; index < AC_QUANTITY; index++)
  8253. {
  8254. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8255. {
  8256. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8257. {
  8258. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8259. goto end;
  8260. }
  8261. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8262. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8263. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8264. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8265. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8266. {
  8267. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8268. goto end;
  8269. }
  8270. else
  8271. {
  8272. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8273. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8274. goto end;
  8275. }
  8276. }
  8277. }//END FOR AC_QUANTITY
  8278. }//END FOR AvailabilityTypeStr[Inoperative]
  8279. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8280. {
  8281. //----------------------gunIndex is 0 ------------------------------------------------//
  8282. if(gunIndex == 0)
  8283. {
  8284. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8285. {
  8286. for(int i=0; i < gunTotalNumber; i++)
  8287. {
  8288. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8289. {
  8290. 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
  8291. {
  8292. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8293. goto end;
  8294. }
  8295. }//END FOR CHAdeMO_QUANTITY
  8296. for (int index = 0; index < CCS_QUANTITY; index++)
  8297. {
  8298. 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
  8299. {
  8300. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8301. goto end;
  8302. }
  8303. }//END FOR CCS_QUANTITY
  8304. for (int index = 0; index < GB_QUANTITY; index++)
  8305. {
  8306. 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
  8307. {
  8308. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8309. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8310. goto end;
  8311. }
  8312. }// END FOR GB_QUANTITY
  8313. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8314. {
  8315. 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
  8316. {
  8317. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8318. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8319. goto end;
  8320. }
  8321. }// END FOR GENERAL_GUN_QUANTITY
  8322. for (int index = 0; index < AC_QUANTITY; index++)
  8323. {
  8324. 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
  8325. {
  8326. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8327. goto end;
  8328. }
  8329. }//END FOR CHAdeMO_QUANTITY
  8330. }// END FOR gunTotalNumber
  8331. }
  8332. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8333. {
  8334. for(int i=0; i < gunTotalNumber; i++)
  8335. {
  8336. for (int index = 0; index < AC_QUANTITY; index++)
  8337. {
  8338. 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
  8339. {
  8340. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8341. goto end;
  8342. }
  8343. }//END FOR CHAdeMO_QUANTITY
  8344. } // END FOR gunTotalNumber
  8345. }
  8346. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8347. goto end;
  8348. }
  8349. //----------------------gunIndex is not 0 ------------------------------------------------//
  8350. //check Transaction active
  8351. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8352. {
  8353. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8354. {
  8355. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8356. goto end;
  8357. }
  8358. }//END FOR CHAdeMO_QUANTITY
  8359. for (int index = 0; index < CCS_QUANTITY; index++)
  8360. {
  8361. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8362. {
  8363. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8364. goto end;
  8365. }
  8366. }//END FOR CCS_QUANTITY
  8367. for (int index = 0; index < GB_QUANTITY; index++)
  8368. {
  8369. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8370. {
  8371. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8372. goto end;
  8373. }
  8374. }// END FOR GB_QUANTITY
  8375. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8376. {
  8377. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8378. {
  8379. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8380. goto end;
  8381. }
  8382. }// END FOR GENERAL_GUN_QUANTITY
  8383. for (int index = 0; index < AC_QUANTITY; index++)
  8384. {
  8385. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8386. {
  8387. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8388. goto end;
  8389. }
  8390. }//END FOR AC_QUANTITY
  8391. }//END FOR AvailabilityTypeStr[Operative]
  8392. end:
  8393. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8394. {
  8395. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8396. }
  8397. else
  8398. {
  8399. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8400. }
  8401. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8402. {
  8403. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8404. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8405. }
  8406. else if(gunIndex == 0)
  8407. {
  8408. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8409. {
  8410. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8411. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8412. }
  8413. }
  8414. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8415. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8416. return result;
  8417. }
  8418. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8419. {
  8420. mtrace();
  8421. int valueInvalid = NO;
  8422. int result = FAIL;
  8423. char keystr[40]={0};
  8424. char valuestr[501]={0}; //value should be limited in 500 bytes
  8425. char comfirmstr[20]={0};
  8426. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8427. json_object *ChangeConfiguration;
  8428. ChangeConfiguration = json_tokener_parse(payload);
  8429. if(!is_error(ChangeConfiguration))
  8430. {
  8431. // Required data
  8432. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8433. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8434. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8435. {
  8436. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8437. }
  8438. else
  8439. {
  8440. valueInvalid = YES;
  8441. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8442. }
  8443. }
  8444. json_object_put(ChangeConfiguration);
  8445. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  8446. {
  8447. DEBUG_ERROR("Payload is null or value is invalid.\n");
  8448. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8449. }
  8450. else
  8451. {
  8452. int status = setKeyValue(keystr, valuestr);
  8453. switch(status)
  8454. {
  8455. case ConfigurationStatus_Accepted:
  8456. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8457. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8458. StoreConfigurationTable();
  8459. break;
  8460. case RebootRequired:
  8461. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8462. StoreConfigurationTable();
  8463. break;
  8464. case NotSupported:
  8465. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8466. break;
  8467. case ConfigurationStatus_Rejected:
  8468. default:
  8469. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8470. break;
  8471. }
  8472. }
  8473. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8474. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8475. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8476. {
  8477. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8478. SetOcppConnStatus(FALSE);
  8479. }
  8480. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8481. {
  8482. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8483. }
  8484. return result;
  8485. }
  8486. int handleClearCacheRequest(char *uuid, char *payload)
  8487. {
  8488. mtrace();
  8489. int result = FAIL;
  8490. char comfirmstr[20];
  8491. char rmFileCmd[100]={0};
  8492. struct stat stats;
  8493. DEBUG_INFO("handleClearCacheRequest...\n");
  8494. stat("/Storage/OCPP", &stats);
  8495. // Check for directory existence
  8496. if (S_ISDIR(stats.st_mode) == 1)
  8497. {}
  8498. else
  8499. {
  8500. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8501. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  8502. system(rmFileCmd);
  8503. }
  8504. if(OCPP_cleanLocalCache())
  8505. {
  8506. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8507. }
  8508. else
  8509. {
  8510. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8511. }
  8512. sendClearCacheConfirmation(uuid, comfirmstr);
  8513. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8514. return result;
  8515. }
  8516. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8517. {
  8518. mtrace();
  8519. int result = FAIL;
  8520. int resultRename;
  8521. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8522. char chargingProfilePurposeStr[26]={0};
  8523. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8524. char tempchargingProfilePurposeStr[26]={0};
  8525. char str[100]={0};
  8526. char fname[200]={0};
  8527. char comfirmstr[20]={0};
  8528. char word[1600]={0};
  8529. int clearflag = FALSE;
  8530. int chargingProfileIdIsNULL = FALSE;
  8531. int connectorIsNULL = FALSE;
  8532. int chargingProfilePurposeIsNULL = FALSE;
  8533. int stackLevelIsNULL = FALSE;
  8534. //int GotoEnd = FALSE;
  8535. FILE *fptr1, *fptr2;
  8536. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  8537. int n_chargingProfile=0;
  8538. int isEmptyFile = FALSE;
  8539. char sLineWord[1600]={0};
  8540. char chargingProfiles[10][100]={0};
  8541. int ChargeProfileCount = 0;
  8542. int ch;
  8543. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8544. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8545. json_object *ClearChargingProfile;
  8546. ClearChargingProfile = json_tokener_parse(payload);
  8547. if(!is_error(ClearChargingProfile))
  8548. {
  8549. // Optional data
  8550. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8551. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8552. else
  8553. chargingProfileIdIsNULL = TRUE;
  8554. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8555. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8556. else
  8557. connectorIsNULL = TRUE;
  8558. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8559. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8560. else
  8561. chargingProfilePurposeIsNULL = TRUE;
  8562. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8563. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8564. else
  8565. stackLevelIsNULL = TRUE;
  8566. }
  8567. json_object_put(ClearChargingProfile);
  8568. if(connectorIsNULL == FALSE)
  8569. {
  8570. switch(connectorIdInt)
  8571. {
  8572. case 0:
  8573. if(chargingProfilePurposeIsNULL == TRUE)
  8574. {
  8575. int l = 0;
  8576. strcpy(fname, ChargePointMaxProfile_JSON);
  8577. if((access(fname,F_OK))!=-1)
  8578. {
  8579. strcpy(chargingProfiles[l], fname);
  8580. l = l + 1;
  8581. }
  8582. strcpy(fname, TxDefaultProfile_0_JSON);
  8583. if((access(fname,F_OK))!=-1)
  8584. {
  8585. strcpy(chargingProfiles[l], fname);
  8586. l = l + 1;
  8587. }
  8588. ChargeProfileCount = l;
  8589. }
  8590. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8591. {
  8592. strcpy(fname, ChargePointMaxProfile_JSON);
  8593. if((access(fname,F_OK))!=-1)
  8594. {
  8595. strcpy(chargingProfiles[0], fname);
  8596. ChargeProfileCount = 1;
  8597. }
  8598. }
  8599. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8600. {
  8601. strcpy(fname, TxDefaultProfile_0_JSON);
  8602. if((access(fname,F_OK))!=-1)
  8603. {
  8604. strcpy(chargingProfiles[0], fname);
  8605. ChargeProfileCount = 1;
  8606. }
  8607. }
  8608. break;
  8609. default:
  8610. if(chargingProfilePurposeIsNULL == TRUE)
  8611. {
  8612. int m = 0;
  8613. memset(fname, 0, ARRAY_SIZE(fname));
  8614. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8615. if((access(fname,F_OK))!=-1)
  8616. {
  8617. strcpy(chargingProfiles[m], fname);
  8618. m = m + 1;
  8619. }
  8620. memset(fname, 0, ARRAY_SIZE(fname));
  8621. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8622. if((access(fname,F_OK))!=-1)
  8623. {
  8624. strcpy(chargingProfiles[m], fname);
  8625. m = m + 1;
  8626. }
  8627. ChargeProfileCount = m;
  8628. }
  8629. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8630. {
  8631. //strcpy(fname, TxDefaultProfile_1_JSON);
  8632. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8633. if((access(fname,F_OK))!=-1)
  8634. {
  8635. strcpy(chargingProfiles[0], fname);
  8636. ChargeProfileCount = 1;
  8637. }
  8638. }
  8639. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8640. {
  8641. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8642. if((access(fname,F_OK))!=-1)
  8643. {
  8644. strcpy(chargingProfiles[0], fname);
  8645. ChargeProfileCount = 1;
  8646. }
  8647. //strcpy(fname, TxProfile_1_JSON);
  8648. }
  8649. //strcpy(fname, ChargePointMaxProfile_JSON );
  8650. break;
  8651. }
  8652. }
  8653. else // Check all Charging Profiles
  8654. {
  8655. int i = 0;
  8656. char fnametemp[200]={0};
  8657. ChargeProfileCount = 0;
  8658. //Check ChargePointMaxProfile.json exit
  8659. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8660. {
  8661. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  8662. i = i + 1;
  8663. }
  8664. //Check TxDefaultProfile_0.json exit
  8665. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8666. {
  8667. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  8668. i = i + 1;
  8669. }
  8670. //Check TxDefaultProfile_%d.json
  8671. for(int j=1; j <= gunTotalNumber; j++)
  8672. {
  8673. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8674. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8675. if((access(fnametemp,F_OK))!=-1)
  8676. {
  8677. strcpy(chargingProfiles[i], fnametemp);
  8678. i = i + 1;
  8679. }
  8680. }
  8681. //Check TxProfile_%d.json
  8682. for(int j=1; j <= gunTotalNumber; j++)
  8683. {
  8684. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8685. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8686. if((access(fnametemp,F_OK))!=-1)
  8687. {
  8688. strcpy(chargingProfiles[i], fnametemp);
  8689. i = i + 1;
  8690. }
  8691. }
  8692. ChargeProfileCount = i;
  8693. }// End connectorIsNULL is TRUE
  8694. if(ChargeProfileCount == 0)
  8695. {
  8696. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8697. goto end;
  8698. }
  8699. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8700. {
  8701. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8702. goto end;
  8703. }
  8704. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8705. {
  8706. memset(str, 0, ARRAY_SIZE(str));
  8707. // clear temp file
  8708. sprintf(str,"rm -f %s",temp);
  8709. system(str);
  8710. for(int k=0; k < ChargeProfileCount; k++)
  8711. {
  8712. memset(str, 0, ARRAY_SIZE(str));
  8713. //clear file in C
  8714. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8715. system(str);
  8716. }
  8717. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8718. goto end;
  8719. }
  8720. else if(connectorIsNULL == TRUE)
  8721. {
  8722. for(int k=0; k < ChargeProfileCount; k++)
  8723. {
  8724. fptr1 = fopen(chargingProfiles[k], "r");
  8725. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  8726. //Check Charging Profile Count
  8727. while(fscanf(fptr1, "%s", word) != EOF)
  8728. {
  8729. //DEBUG_INFO("word=%s\n",word);
  8730. if(strstr(word, "chargingProfileId")!= NULL)
  8731. {
  8732. //DEBUG_INFO("test chargingProfileId \n");
  8733. n_chargingProfile = n_chargingProfile + 1;
  8734. //DEBUG_INFO("chargingProfileId Found\n");
  8735. }
  8736. }
  8737. rewind(fptr1);
  8738. //search Charging Profile Element
  8739. //int i= 0;
  8740. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8741. {
  8742. json_object *tmpProfilee;
  8743. tmpProfilee = json_tokener_parse(sLineWord);
  8744. if(!is_error(tmpProfilee))
  8745. {
  8746. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8747. {
  8748. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8749. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8750. }
  8751. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8752. {
  8753. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8754. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8755. }
  8756. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8757. {
  8758. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8759. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8760. }
  8761. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8762. {
  8763. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8764. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8765. }
  8766. }
  8767. json_object_put(tmpProfilee);
  8768. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8769. {
  8770. //------- not write to fptr2-------//
  8771. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8772. //clearflag = TRUE;
  8773. }
  8774. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8775. {
  8776. //------- not write to fptr2-------//
  8777. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8778. }
  8779. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8780. {
  8781. //------- not write to fptr2-------//
  8782. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8783. }
  8784. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8785. {
  8786. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8787. }
  8788. else
  8789. {
  8790. fprintf(fptr2, sLineWord);//writing data into file
  8791. }
  8792. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8793. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8794. if(clearflag == TRUE)
  8795. {
  8796. fclose(fptr1);
  8797. fclose(fptr2);
  8798. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8799. system(str);
  8800. // clear temp file
  8801. sprintf(str,"rm -f %s",temp);
  8802. system(str);
  8803. }
  8804. else
  8805. {
  8806. fclose(fptr1);
  8807. fclose(fptr2);
  8808. memset(str, 0, ARRAY_SIZE(str));
  8809. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8810. system(str);
  8811. resultRename = rename(temp, chargingProfiles[k]);
  8812. if(resultRename == 0)
  8813. {
  8814. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8815. }
  8816. else
  8817. {
  8818. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8819. }
  8820. if(comfirmstr[0]== 0)
  8821. {
  8822. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8823. }
  8824. //Check chargingProfile is empty file
  8825. /*------ Read the file ----------------*/
  8826. fptr1=fopen(chargingProfiles[k],"r");
  8827. ch=fgetc(fptr1);
  8828. rewind(fptr1);
  8829. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8830. if(ch!=EOF)
  8831. {
  8832. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8833. {
  8834. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8835. if(sLineWord[0]=='\0')
  8836. {
  8837. isEmptyFile = TRUE;
  8838. break;
  8839. }
  8840. else
  8841. {
  8842. isEmptyFile = FALSE;
  8843. break;
  8844. }
  8845. }
  8846. }
  8847. else
  8848. isEmptyFile = TRUE;
  8849. fclose(fptr1);
  8850. if(isEmptyFile == TRUE)
  8851. {
  8852. memset(str, 0, ARRAY_SIZE(str));
  8853. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8854. system(str);
  8855. }
  8856. }
  8857. }// End of while(int k=0; k < ChargePointCount; k++)
  8858. }
  8859. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8860. {
  8861. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8862. for(int k=0; k < ChargeProfileCount; k++)
  8863. {
  8864. fptr1 = fopen(chargingProfiles[k], "r");
  8865. fptr2 = fopen(temp, "w+");
  8866. //Check Charging Profile Count
  8867. while(fscanf(fptr1, "%s", word) != EOF)
  8868. {
  8869. //DEBUG_INFO("word=%s\n",word);
  8870. if(strstr(word, "chargingProfileId")!= NULL)
  8871. {
  8872. n_chargingProfile = n_chargingProfile + 1;
  8873. }
  8874. }
  8875. rewind(fptr1);
  8876. //search Charging Profile Element
  8877. //int i= 0;
  8878. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8879. {
  8880. json_object *tmpProfilee;
  8881. tmpProfilee = json_tokener_parse(sLineWord);
  8882. if(!is_error(tmpProfilee))
  8883. {
  8884. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8885. {
  8886. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8887. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8888. }
  8889. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8890. {
  8891. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8892. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8893. }
  8894. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8895. {
  8896. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8897. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8898. }
  8899. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8900. {
  8901. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8902. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8903. }
  8904. }
  8905. json_object_put(tmpProfilee);
  8906. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8907. {
  8908. //------- not write to fptr2-------//
  8909. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8910. //clearflag = TRUE;
  8911. }
  8912. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8913. {
  8914. //------- not write to fptr2-------//
  8915. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8916. }
  8917. else if(stackLevelIsNULL == TRUE)
  8918. {
  8919. //Clear Whole File
  8920. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8921. clearflag = TRUE;
  8922. break;
  8923. }
  8924. else
  8925. {
  8926. fprintf(fptr2, sLineWord);//writing data into file
  8927. }
  8928. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8929. }
  8930. if(clearflag == TRUE)
  8931. {
  8932. fclose(fptr1);
  8933. fclose(fptr2);
  8934. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8935. system(str);
  8936. // clear temp file
  8937. sprintf(str,"rm -f %s",temp);
  8938. system(str);
  8939. }
  8940. else
  8941. {
  8942. fclose(fptr1);
  8943. fclose(fptr2);
  8944. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8945. system(str);
  8946. resultRename = rename(temp, chargingProfiles[k]);
  8947. if(resultRename == 0)
  8948. {
  8949. DEBUG_INFO("File ChargingProfile renamed successfully");
  8950. }
  8951. else
  8952. {
  8953. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8954. }
  8955. if(comfirmstr[0]== 0)
  8956. {
  8957. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8958. }
  8959. //Check chargingProfile is empty file
  8960. /*------ Read the file ----------------*/
  8961. fptr1=fopen(chargingProfiles[k],"r");
  8962. ch=fgetc(fptr1);
  8963. rewind(fptr1);
  8964. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8965. if(ch!=EOF)
  8966. {
  8967. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8968. {
  8969. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8970. if(sLineWord[0]=='\0')
  8971. {
  8972. isEmptyFile = TRUE;
  8973. break;
  8974. }
  8975. else
  8976. {
  8977. isEmptyFile = FALSE;
  8978. break;
  8979. }
  8980. }
  8981. }
  8982. else
  8983. isEmptyFile = TRUE;
  8984. fclose(fptr1);
  8985. if(isEmptyFile == TRUE)
  8986. {
  8987. memset(str, 0, ARRAY_SIZE(str));
  8988. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8989. system(str);
  8990. }
  8991. /*------- End of reading ---------------*/
  8992. }
  8993. } // while(int k=0; k < ChargeProfileCount; k++)
  8994. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8995. end:
  8996. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8997. {
  8998. if(connectorIdInt == 0)
  8999. {
  9000. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9001. {
  9002. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9003. }
  9004. }
  9005. else
  9006. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9007. }
  9008. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9009. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9010. return result;
  9011. }
  9012. void createFirmwareVersionByDataTransfer(void)
  9013. {
  9014. json_object *FirmwareDataTransfer = json_object_new_object();
  9015. // AC & DC model
  9016. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9017. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9018. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9019. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9020. // DC model
  9021. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9022. {
  9023. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9024. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9025. (gunType[3] != GUN_TYPE_UNKNOWN))
  9026. {
  9027. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9028. }
  9029. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9030. {
  9031. // DS DM DW
  9032. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9033. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9034. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9035. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9036. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9037. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9038. }
  9039. else
  9040. {
  9041. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9042. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9043. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9044. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9045. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9046. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9047. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9048. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9049. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9050. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9051. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9052. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9053. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9054. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9055. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9056. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9057. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9058. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9059. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9060. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9061. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9062. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9063. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9064. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9065. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9066. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9067. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9068. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9069. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9070. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9071. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9072. }
  9073. }
  9074. // 4G model
  9075. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9076. {
  9077. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9078. }
  9079. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9080. json_object_put(FirmwareDataTransfer);
  9081. }
  9082. int handleDataTransferRequest(char *uuid, char *payload)
  9083. {
  9084. mtrace();
  9085. json_object *response = json_object_new_object();
  9086. int result = FAIL;
  9087. char tempvendorId[255]={0};
  9088. char tempmessageId[50]={0};
  9089. char tempdata[512]={0};
  9090. char message[2048]={0};
  9091. DEBUG_INFO("handleDataTransferRequest...\n");
  9092. if((uuid != NULL) && (payload != NULL))
  9093. {
  9094. json_object *DataTransfer;
  9095. DataTransfer = json_tokener_parse(payload);
  9096. if(!is_error(DataTransfer))
  9097. {
  9098. // Required data
  9099. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9100. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9101. // Optional data
  9102. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9103. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9104. if(json_object_object_get(DataTransfer, "data") != NULL)
  9105. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9106. result = PASS;
  9107. }
  9108. json_object_put(DataTransfer);
  9109. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9110. {
  9111. // Send all moudle firmware version on EVSE
  9112. createFirmwareVersionByDataTransfer();
  9113. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9114. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9115. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9116. json_object_put(response);
  9117. }
  9118. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9119. {
  9120. system("/usr/bin/run_tmate_restart.sh &");
  9121. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9122. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9123. json_object_put(response);
  9124. }
  9125. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9126. {
  9127. json_object *data;
  9128. data = json_tokener_parse(tempdata);
  9129. if(!is_error(data))
  9130. {
  9131. 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))
  9132. {
  9133. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9134. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9135. if(json_object_object_get(data, "SOC") != NULL)
  9136. {
  9137. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9138. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9139. }
  9140. if(json_object_object_get(data, "Energy") != NULL)
  9141. {
  9142. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9143. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9144. }
  9145. if(json_object_object_get(data, "Duration") != NULL)
  9146. {
  9147. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9148. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9149. }
  9150. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9151. }
  9152. else
  9153. {
  9154. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9155. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9156. }
  9157. }
  9158. else
  9159. {
  9160. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9161. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9162. }
  9163. json_object_put(data);
  9164. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9165. json_object_put(response);
  9166. }
  9167. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9168. {
  9169. json_object *data;
  9170. data = json_tokener_parse(tempdata);
  9171. if(!is_error(data))
  9172. {
  9173. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9174. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9175. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9176. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9177. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9178. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9179. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9180. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9181. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9182. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9183. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9184. }
  9185. else
  9186. {
  9187. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9188. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9189. }
  9190. json_object_put(data);
  9191. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9192. json_object_put(response);
  9193. }
  9194. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9195. {
  9196. json_object *data;
  9197. data = json_tokener_parse(tempdata);
  9198. if(!is_error(data))
  9199. {
  9200. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9201. if(json_object_object_get(data, "idToken") != NULL)
  9202. {
  9203. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9204. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9205. }
  9206. if(json_object_object_get(data, "price") != NULL)
  9207. {
  9208. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9209. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9210. }
  9211. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9212. }
  9213. else
  9214. {
  9215. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9216. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9217. }
  9218. json_object_put(data);
  9219. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9220. json_object_put(response);
  9221. }
  9222. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9223. {
  9224. json_object *data;
  9225. data = json_tokener_parse(tempdata);
  9226. if(!is_error(data))
  9227. {
  9228. if(json_object_object_get(data, "txId") != NULL)
  9229. {
  9230. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9231. for(int idx = 0;idx<gunTotalNumber;idx++)
  9232. {
  9233. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9234. {
  9235. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9236. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9237. if(json_object_object_get(data, "description") != NULL)
  9238. {
  9239. // California pricing V1.0
  9240. DEBUG_INFO("California pricing V1.0\n");
  9241. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9242. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9243. }
  9244. else
  9245. {
  9246. // California pricing V1.1
  9247. DEBUG_INFO("California pricing V1.1\n");
  9248. if(json_object_object_get(data, "timestamp") != NULL)
  9249. {
  9250. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9251. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9252. }
  9253. if(json_object_object_get(data, "meterValue") != NULL)
  9254. {
  9255. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9256. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9257. }
  9258. if(json_object_object_get(data, "cost") != NULL)
  9259. {
  9260. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9261. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9262. }
  9263. if(json_object_object_get(data, "state") != NULL)
  9264. {
  9265. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9266. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9267. }
  9268. if(json_object_object_get(data, "chargingPrice") != NULL)
  9269. {
  9270. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9271. {
  9272. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9273. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9274. }
  9275. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9276. {
  9277. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9278. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9279. }
  9280. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9281. {
  9282. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9283. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9284. }
  9285. }
  9286. if(json_object_object_get(data, "idlePrice") != NULL)
  9287. {
  9288. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9289. {
  9290. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9291. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9292. }
  9293. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9294. {
  9295. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9296. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9297. }
  9298. }
  9299. if(json_object_object_get(data, "nextPeriod") != NULL)
  9300. {
  9301. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9302. {
  9303. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9304. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9305. }
  9306. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9307. {
  9308. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9309. {
  9310. 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")));
  9311. 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"));
  9312. }
  9313. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9314. {
  9315. 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")));
  9316. 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"));
  9317. }
  9318. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9319. {
  9320. 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")));
  9321. 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"));
  9322. }
  9323. }
  9324. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9325. {
  9326. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9327. {
  9328. 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")));
  9329. 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"));
  9330. }
  9331. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9332. {
  9333. 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")));
  9334. 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"));
  9335. }
  9336. }
  9337. }
  9338. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9339. {
  9340. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9341. {
  9342. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9343. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9344. }
  9345. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9346. {
  9347. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9348. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9349. }
  9350. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9351. {
  9352. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9353. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9354. }
  9355. }
  9356. }
  9357. }
  9358. }
  9359. }
  9360. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9361. }
  9362. else
  9363. {
  9364. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9365. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9366. }
  9367. json_object_put(data);
  9368. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9369. json_object_put(response);
  9370. }
  9371. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9372. {
  9373. json_object *data;
  9374. data = json_tokener_parse(tempdata);
  9375. if(!is_error(data))
  9376. {
  9377. if(json_object_object_get(data, "txId") != NULL)
  9378. {
  9379. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9380. for(int idx = 0;idx<gunTotalNumber;idx++)
  9381. {
  9382. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9383. {
  9384. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9385. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9386. if(json_object_object_get(data, "description") != NULL)
  9387. {
  9388. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9389. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9390. }
  9391. }
  9392. }
  9393. }
  9394. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9395. }
  9396. else
  9397. {
  9398. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9399. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9400. }
  9401. json_object_put(data);
  9402. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9403. json_object_put(response);
  9404. }
  9405. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9406. {
  9407. json_object *data;
  9408. data = json_tokener_parse(tempdata);
  9409. if(!is_error(data))
  9410. {
  9411. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9412. if(json_object_object_get(data, "Content_Type") != NULL)
  9413. {
  9414. 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))
  9415. {
  9416. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9417. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9418. {
  9419. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9420. }
  9421. }
  9422. else
  9423. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9424. }
  9425. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9426. }
  9427. else
  9428. {
  9429. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9430. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9431. }
  9432. json_object_put(data);
  9433. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9434. json_object_put(response);
  9435. }
  9436. else if(strstr(tempmessageId, "ID_DisplayLcdPage") != NULL)
  9437. {
  9438. json_object *data;
  9439. data = json_tokener_parse(tempdata);
  9440. if(!is_error(data))
  9441. {
  9442. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9443. if(json_object_object_get(data, "ConnectorId") != NULL)
  9444. {
  9445. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9446. }
  9447. if(json_object_object_get(data, "Page_Index") != NULL)
  9448. {
  9449. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9450. }
  9451. if(json_object_object_get(data, "Duration") != NULL)
  9452. {
  9453. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9454. }
  9455. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9456. }
  9457. else
  9458. {
  9459. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9460. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9461. }
  9462. json_object_put(data);
  9463. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9464. json_object_put(response);
  9465. }
  9466. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9467. {
  9468. json_object *data;
  9469. data = json_tokener_parse(tempdata);
  9470. if(!is_error(data))
  9471. {
  9472. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9473. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9474. {
  9475. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9476. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9477. else
  9478. {
  9479. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9480. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9481. }
  9482. }
  9483. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9484. {
  9485. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9486. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9487. else
  9488. {
  9489. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9490. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9491. }
  9492. }
  9493. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9494. {
  9495. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9496. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9497. else
  9498. {
  9499. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9500. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9501. }
  9502. }
  9503. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9504. {
  9505. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9506. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  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. }
  9513. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9514. {
  9515. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9516. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9517. else
  9518. {
  9519. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9520. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9521. }
  9522. }
  9523. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9524. {
  9525. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9526. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9527. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9528. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9529. else
  9530. {
  9531. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9532. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9533. }
  9534. }
  9535. if(json_object_object_get(data, "isAuthentication") != NULL)
  9536. {
  9537. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9538. {
  9539. case 0:
  9540. case 1:
  9541. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9542. break;
  9543. default:
  9544. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9545. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9546. break;
  9547. }
  9548. }
  9549. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9550. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9551. }
  9552. else
  9553. {
  9554. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9555. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9556. }
  9557. json_object_put(data);
  9558. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9559. json_object_put(response);
  9560. }
  9561. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  9562. {
  9563. json_object *data;
  9564. data = json_tokener_parse(tempdata);
  9565. if(!is_error(data))
  9566. {
  9567. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9568. {
  9569. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  9570. {
  9571. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9572. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9573. }
  9574. else
  9575. {
  9576. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9577. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  9578. }
  9579. }
  9580. else
  9581. {
  9582. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9583. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9584. }
  9585. }
  9586. else
  9587. {
  9588. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9589. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9590. }
  9591. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9592. json_object_put(response);
  9593. }
  9594. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9595. {
  9596. json_object *data;
  9597. data = json_tokener_parse(tempdata);
  9598. if(!is_error(data))
  9599. {
  9600. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9601. if(json_object_object_get(data, "stationName") != NULL)
  9602. {
  9603. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9604. }
  9605. else
  9606. {
  9607. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9608. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9609. }
  9610. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9611. {
  9612. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  9613. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9614. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  9615. }
  9616. }
  9617. else
  9618. {
  9619. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9620. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9621. }
  9622. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9623. json_object_put(response);
  9624. }
  9625. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9626. {
  9627. json_object *data;
  9628. data = json_tokener_parse(tempdata);
  9629. if(!is_error(data))
  9630. {
  9631. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9632. if(json_object_object_get(data, "weatherId") != NULL)
  9633. {
  9634. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  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("weather data can not get."));
  9640. }
  9641. if(json_object_object_get(data, "Temperature") != NULL)
  9642. {
  9643. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9644. }
  9645. else
  9646. {
  9647. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9648. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9649. }
  9650. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9651. {
  9652. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  9653. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9654. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  9655. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  9656. );
  9657. }
  9658. }
  9659. else
  9660. {
  9661. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9662. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9663. }
  9664. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9665. json_object_put(response);
  9666. }
  9667. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9668. {
  9669. json_object *data;
  9670. data = json_tokener_parse(tempdata);
  9671. if(!is_error(data))
  9672. {
  9673. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9674. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9675. {
  9676. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9677. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9678. }
  9679. else
  9680. {
  9681. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9682. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9683. }
  9684. }
  9685. else
  9686. {
  9687. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9688. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9689. }
  9690. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9691. json_object_put(response);
  9692. }
  9693. else
  9694. {
  9695. // Can not find valid message id
  9696. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9697. }
  9698. }
  9699. else
  9700. {
  9701. // Payload is null
  9702. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9703. }
  9704. LWS_Send(message);
  9705. return result;
  9706. }
  9707. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9708. {
  9709. mtrace();
  9710. int result = FAIL;
  9711. int connectorIdInt, durationInt;
  9712. char chargingRateUnitStr[4]={0};
  9713. char comfirmstr[20];
  9714. int confirmPeriods = 0;
  9715. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9716. json_object *GetCompositeSchedule;
  9717. GetCompositeSchedule = json_tokener_parse(payload);
  9718. if(!is_error(GetCompositeSchedule))
  9719. {
  9720. // Required data
  9721. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9722. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9723. else
  9724. connectorIdInt = -1;
  9725. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9726. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9727. else
  9728. durationInt = 86400;
  9729. // Optional data
  9730. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9731. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9732. }
  9733. json_object_put(GetCompositeSchedule);
  9734. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9735. if((connectorIdInt == 0) ||
  9736. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9737. {
  9738. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9739. struct StructChargingProfile tmpProfile[1];
  9740. if(strstr(chargingRateUnitStr, "W") != NULL)
  9741. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9742. else
  9743. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9744. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9745. {
  9746. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9747. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9748. }
  9749. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9750. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9751. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9752. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9753. {
  9754. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9755. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9756. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9757. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9758. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9759. {
  9760. confirmPeriods = idx;
  9761. break;
  9762. }
  9763. }
  9764. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9765. {
  9766. confirmPeriods += 1;
  9767. }
  9768. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9769. }
  9770. else
  9771. {
  9772. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9773. }
  9774. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9775. return result;
  9776. }
  9777. int handleGetConfigurationRequest(char *uuid, char *payload)
  9778. {
  9779. mtrace();
  9780. int result = FAIL;
  9781. int MaxKeySupported = 0;
  9782. int n_keys = 0;
  9783. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9784. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9785. json_object *GetConfiguration;
  9786. GetConfiguration = json_tokener_parse(payload);
  9787. if(!is_error(GetConfiguration))
  9788. {
  9789. // Optional data
  9790. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9791. {
  9792. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9793. {
  9794. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9795. n_keys = idx + 1;
  9796. }
  9797. }
  9798. }
  9799. json_object_put(GetConfiguration);
  9800. UnknownKeynum = 0;
  9801. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9802. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9803. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9804. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9805. if(n_keys != 0)
  9806. {
  9807. for(int i=0;i<n_keys;i++)
  9808. {
  9809. getKeyValue(requestKey[i]);
  9810. }
  9811. }
  9812. else
  9813. {
  9814. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9815. getKeyValue("");
  9816. }
  9817. processUnkownKey();
  9818. sendGetConfigurationConfirmation(uuid);
  9819. return result;
  9820. }
  9821. static char fnamePlusPath[100]={0};
  9822. static char fnamePWithNoPath[60]={0};
  9823. void checkUploadLog(void)
  9824. {
  9825. FILE *fp;
  9826. /* Open the command for reading. */
  9827. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9828. if (fp == NULL) {
  9829. DEBUG_WARN("Failed to run command\n" );
  9830. exit(1);
  9831. }
  9832. int ftppathlen = 0;
  9833. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9834. int i = 0;
  9835. /* Read the output a line at a time - output it. */
  9836. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9837. if(i==0)
  9838. {
  9839. ftppathlen = strlen(fnamePlusPath);
  9840. DEBUG_INFO("%s\n", fnamePlusPath);
  9841. fnamePlusPath[ftppathlen]='\0';
  9842. break;
  9843. }
  9844. i= i+1;
  9845. }
  9846. /* close */
  9847. pclose(fp);
  9848. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9849. {
  9850. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9851. {
  9852. fnamePlusPath[k]='\0';
  9853. }
  9854. }
  9855. i=1;
  9856. //char fname[60]={0};
  9857. while(i < ftppathlen)
  9858. {
  9859. int len=ftppathlen-i;
  9860. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9861. {
  9862. DEBUG_INFO("compare '/' all right\n");
  9863. break;
  9864. }
  9865. i=i+1;
  9866. }
  9867. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9868. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9869. fnamePWithNoPath[i+1] = '\0';
  9870. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9871. {
  9872. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9873. {
  9874. fnamePWithNoPath[j]='\0';
  9875. }
  9876. }
  9877. FILE* fp1 = fopen(fnamePlusPath, "r");
  9878. if (fp1)
  9879. {
  9880. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9881. // file exists
  9882. fclose(fp1);
  9883. }
  9884. else
  9885. {
  9886. // file doesn't exist
  9887. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9888. }
  9889. }
  9890. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9891. {
  9892. mtrace();
  9893. int result = FAIL;
  9894. time_t CurrentTime;
  9895. struct tm *tm;
  9896. pthread_t th_Status;
  9897. CurrentTime = time(NULL);
  9898. tm = localtime(&CurrentTime);
  9899. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  9900. 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);
  9901. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9902. if(!interLock.isGetDiagnosticGoing)
  9903. {
  9904. interLock.isGetDiagnosticGoing = 1;
  9905. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9906. sleep(1);
  9907. }
  9908. else
  9909. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9910. return result;
  9911. }
  9912. void* GetDiagnosticsProcess(void* data)
  9913. {
  9914. pthread_detach(pthread_self());
  9915. mtrace();
  9916. int retriesInt=0, retryIntervalInt=0;
  9917. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9918. 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};
  9919. int port=0;
  9920. int isSuccess = FALSE;
  9921. char cmdBuf[2048];
  9922. struct tm *tmNow;
  9923. time_t CurrentTime;
  9924. struct tm tmStart;
  9925. struct tm tmStop;
  9926. CurrentTime = time(NULL);
  9927. tmNow=localtime(&CurrentTime);
  9928. uint16_t targetYear, targetMonth;
  9929. json_object *GetDiagnostics;
  9930. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9931. GetDiagnostics = json_tokener_parse(data);
  9932. if(!is_error(GetDiagnostics))
  9933. {
  9934. // Required data
  9935. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9936. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9937. // Optional data
  9938. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9939. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9940. else
  9941. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9942. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9943. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9944. else
  9945. retryIntervalInt = 30;
  9946. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9947. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9948. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9949. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9950. }
  9951. json_object_put(GetDiagnostics);
  9952. // Pack log to compress file
  9953. 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) &&
  9954. (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))
  9955. {
  9956. // Pack system log
  9957. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9958. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9959. targetYear = tmStart.tm_year;
  9960. targetMonth = tmStart.tm_mon;
  9961. do
  9962. {
  9963. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9964. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9965. if(targetMonth+1>=13)
  9966. {
  9967. targetYear += 1;
  9968. targetMonth = 1;
  9969. }
  9970. else
  9971. {
  9972. targetMonth += 1;
  9973. }
  9974. }while((targetYear < (tmNow->tm_year+1900)) ||
  9975. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9976. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9977. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9978. system(cmdBuf);
  9979. // Pack charging & event log
  9980. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9981. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9982. targetYear = tmStart.tm_year;
  9983. targetMonth = tmStart.tm_mon;
  9984. do
  9985. {
  9986. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9987. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9988. if(targetMonth+1>=13)
  9989. {
  9990. targetYear += 1;
  9991. targetMonth = 1;
  9992. }
  9993. else
  9994. {
  9995. targetMonth += 1;
  9996. }
  9997. }while((targetYear < (tmNow->tm_year+1900)) ||
  9998. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9999. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10000. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10001. system(cmdBuf);
  10002. // Combine log file
  10003. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10004. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10005. }
  10006. else
  10007. {
  10008. system("exec /root/logPackTools 'log' 6");
  10009. }
  10010. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10011. system(cmdBuf);
  10012. checkUploadLog();
  10013. //****************location*******************/
  10014. if(strcmp(locationstr,"")==0)
  10015. {
  10016. DEBUG_INFO("location is <Empty>!\n");
  10017. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10018. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10019. goto end;
  10020. }
  10021. memset(protocol, 0, ARRAY_SIZE(protocol));
  10022. memset(user, 0, ARRAY_SIZE(user) );
  10023. memset(password, 0, ARRAY_SIZE(password));
  10024. memset(host, 0, ARRAY_SIZE(host));
  10025. memset(path, 0, ARRAY_SIZE(path));
  10026. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10027. memset(host1, 0, ARRAY_SIZE(host1));
  10028. memset(path1, 0, ARRAY_SIZE(path1));
  10029. /*location: ftp://user:password@host:port/path*/
  10030. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10031. if((access(fnamePlusPath,F_OK))!=-1)
  10032. {
  10033. DEBUG_INFO("fnamePlusPath exist.\n");
  10034. }
  10035. else
  10036. {
  10037. DEBUG_INFO("fnamePlusPath not exist!\n");
  10038. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10039. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10040. goto end;
  10041. }
  10042. if(strchr(locationstr,'@')==NULL)
  10043. {
  10044. sscanf(locationstr,
  10045. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10046. protocol, host, &port, path);
  10047. strcpy(user,"anonymous");
  10048. strcpy(password,"");
  10049. }
  10050. else
  10051. {
  10052. //DEBUG_INFO("pch=%s\n", pch);
  10053. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10054. protocol, user, password, host, &port, path);
  10055. }
  10056. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10057. {
  10058. DEBUG_INFO("protocol is not ftp/http ! \n");
  10059. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10060. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10061. goto end;
  10062. }
  10063. if(strncmp(locationstr,"http", 4) == 0)
  10064. {
  10065. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10066. sprintf(ftppath,"/%s", path);
  10067. do
  10068. {
  10069. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10070. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10071. sleep(3);
  10072. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10073. if(!isSuccess)
  10074. {
  10075. DEBUG_INFO("Diagnostics fail.\n");
  10076. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10077. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10078. sleep(retryIntervalInt);
  10079. }
  10080. else
  10081. {
  10082. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10083. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10084. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10085. }
  10086. retriesInt--;
  10087. }while((isSuccess == 0)&&(retriesInt >= 0));
  10088. }
  10089. else
  10090. {
  10091. sscanf(host,"%[^/]%s",host1, path1);
  10092. if(strlen(path) > 0)
  10093. sprintf(ftppath,"/%s", path);
  10094. else
  10095. sprintf(ftppath,"/%s", path1);
  10096. int ftppathlen=strlen(ftppath);
  10097. int i=1;
  10098. char filenametemp[50];
  10099. while(i < ftppathlen)
  10100. {
  10101. int len=ftppathlen-i;
  10102. if(ftppath[len]== 47) // '/' ascll code: 47
  10103. {
  10104. DEBUG_INFO("find '/' all right\n");
  10105. break;
  10106. }
  10107. i=i+1;
  10108. }
  10109. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10110. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10111. filenametemp[i+1] = 0;
  10112. if(port == 0)
  10113. port = 21;
  10114. do
  10115. {
  10116. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10117. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10118. sleep(3);
  10119. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10120. if(!isSuccess)
  10121. {
  10122. DEBUG_INFO("Diagnostics fail.\n");
  10123. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10124. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10125. sleep(retryIntervalInt);
  10126. }
  10127. else
  10128. {
  10129. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10130. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10131. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10132. }
  10133. retriesInt--;
  10134. }while((!isSuccess)&&(retriesInt >= 0));
  10135. }
  10136. end:
  10137. system("rm -f /mnt/*");
  10138. sleep(5);
  10139. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10140. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10141. interLock.isGetDiagnosticGoing = 0;
  10142. pthread_exit(NULL);
  10143. }
  10144. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10145. {
  10146. mtrace();
  10147. int result = FAIL;
  10148. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10149. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10150. {
  10151. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10152. locallistVersion = -1;
  10153. }
  10154. else
  10155. {
  10156. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10157. OCPP_getListVerion();
  10158. }
  10159. //from db.OCPP_getListVerion
  10160. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10161. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  10162. sendGetLocalListVersionConfirmation(uuid,"");
  10163. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  10164. return result;
  10165. }
  10166. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10167. {
  10168. mtrace();
  10169. int result = FAIL;
  10170. int connectorIdInt=-1;
  10171. int tempIndex = 0;
  10172. int connectorIdIsNULL, chargingProfileIsNULL;
  10173. char comfirmstr[20]={0};
  10174. char cmdBuf[512];
  10175. json_object *RemoteStartTransaction;
  10176. FILE *fp;
  10177. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10178. if(server_pending == TRUE)
  10179. {
  10180. return 0;
  10181. }
  10182. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10183. RemoteStartTransaction = json_tokener_parse(payload);
  10184. if(!is_error(RemoteStartTransaction))
  10185. {
  10186. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10187. {
  10188. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10189. }
  10190. else
  10191. {
  10192. connectorIdIsNULL = TRUE;
  10193. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10194. {
  10195. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10196. {
  10197. connectorIdIsNULL = FALSE;
  10198. connectorIdInt = (gun_index+1);
  10199. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10200. break;
  10201. }
  10202. }
  10203. }
  10204. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10205. {
  10206. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10207. // Required data
  10208. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10209. // Optional data
  10210. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10211. {
  10212. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10213. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10214. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10215. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10216. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10217. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10218. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10219. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10220. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10221. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10222. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10223. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10224. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10225. {
  10226. 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")));
  10227. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10228. 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"));
  10229. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10230. 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"));
  10231. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10232. 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")));
  10233. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10234. {
  10235. 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++)
  10236. {
  10237. 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"));
  10238. 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"));
  10239. 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)
  10240. 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"));
  10241. }
  10242. }
  10243. }
  10244. }
  10245. else
  10246. {
  10247. chargingProfileIsNULL = TRUE;
  10248. }
  10249. }
  10250. }
  10251. else
  10252. {
  10253. connectorIdIsNULL = TRUE;
  10254. }
  10255. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10256. {
  10257. DEBUG_WARN("Connector id is NULL\n.");
  10258. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10259. goto end;
  10260. }
  10261. /*
  10262. enum _SYSTEM_STATUS
  10263. {
  10264. S_BOOTING = 0,
  10265. S_IDLE, = 1
  10266. S_AUTHORIZING, = 2
  10267. S_REASSIGN_CHECK, = 3
  10268. S_REASSIGN, = 4
  10269. S_PRECHARGE, = 5
  10270. S_PREPARING_FOR_EV, = 6
  10271. S_PREPARING_FOR_EVSE, = 7
  10272. S_CHARGING, = 8
  10273. S_TERMINATING, = 9
  10274. S_COMPLETE, = 10
  10275. S_ALARM, = 11
  10276. S_FAULT = 12
  10277. }
  10278. */
  10279. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10280. {
  10281. //check Transaction active
  10282. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10283. {
  10284. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10285. {
  10286. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10287. }
  10288. else
  10289. {
  10290. tempIndex = connectorIdInt -1;
  10291. }
  10292. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10293. {
  10294. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10295. {
  10296. 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))
  10297. {
  10298. //Reserved
  10299. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10300. }
  10301. 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))
  10302. {
  10303. //Reserved
  10304. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10305. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10306. goto end;
  10307. }
  10308. else
  10309. {
  10310. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10311. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10312. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10313. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10314. {
  10315. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10316. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10317. goto end;
  10318. }
  10319. }//END FOR ELSE
  10320. }
  10321. }// END FOR CHAdeMO_QUANTITY
  10322. }
  10323. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10324. {
  10325. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10326. {
  10327. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10328. }
  10329. else
  10330. {
  10331. tempIndex = connectorIdInt -1;
  10332. }
  10333. for (int index = 0; index < CCS_QUANTITY; index++)
  10334. {
  10335. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10336. {
  10337. 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))
  10338. {
  10339. //Reserved
  10340. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10341. }
  10342. 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))
  10343. {
  10344. //Reserved
  10345. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10346. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10347. goto end;
  10348. }
  10349. else
  10350. {
  10351. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10352. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10353. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10354. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10355. {
  10356. DEBUG_WARN("CCS connector not allow start\n.");
  10357. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10358. goto end;
  10359. }
  10360. }// END FOR ELSE
  10361. }
  10362. }// END FOR CCS_QUANTITY
  10363. }
  10364. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10365. {
  10366. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10367. {
  10368. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10369. }
  10370. else
  10371. {
  10372. tempIndex = connectorIdInt -1;
  10373. }
  10374. for (int index = 0; index < GB_QUANTITY; index++)
  10375. {
  10376. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10377. {
  10378. 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))
  10379. {
  10380. //Reserved
  10381. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10382. }
  10383. 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))
  10384. {
  10385. //Reserved
  10386. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10387. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10388. goto end;
  10389. }
  10390. else
  10391. {
  10392. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10393. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10394. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10395. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10396. {
  10397. DEBUG_WARN("GB connector not allow start\n.");
  10398. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10399. goto end;
  10400. }
  10401. }// END FOR ELSE
  10402. }
  10403. } // END FOR GB_QUANTITY
  10404. }
  10405. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10406. {
  10407. tempIndex = connectorIdInt -1;
  10408. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10409. {
  10410. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10411. {
  10412. 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))
  10413. {
  10414. //Reserved
  10415. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10416. }
  10417. 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))
  10418. {
  10419. //Reserved
  10420. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10421. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10422. goto end;
  10423. }
  10424. else
  10425. {
  10426. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10427. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10428. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10429. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10430. {
  10431. DEBUG_WARN("GB connector not allow start\n.");
  10432. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10433. goto end;
  10434. }
  10435. }// END FOR ELSE
  10436. }
  10437. } // END FOR GB_QUANTITY
  10438. }
  10439. else
  10440. {
  10441. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10442. {
  10443. tempIndex = 2;
  10444. }
  10445. else
  10446. {
  10447. tempIndex = connectorIdInt -1;
  10448. }
  10449. for (int index = 0; index < AC_QUANTITY; index++)
  10450. {
  10451. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10452. {
  10453. 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))
  10454. {
  10455. //Reserved
  10456. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10457. }
  10458. 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))
  10459. {
  10460. //Reserved
  10461. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10462. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10463. goto end;
  10464. }
  10465. else
  10466. {
  10467. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10468. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10469. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10470. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10471. {
  10472. DEBUG_WARN("AC connector not allow start\n.");
  10473. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10474. goto end;
  10475. }
  10476. }//END FOR ELSE
  10477. }
  10478. }// END FOR AC_QUANTITY
  10479. }
  10480. if(chargingProfileIsNULL == FALSE)
  10481. {
  10482. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10483. {
  10484. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10485. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10486. //memset idTag
  10487. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10488. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10489. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10490. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10491. // Save profile to file
  10492. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10493. system(cmdBuf);
  10494. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10495. fp = fopen(cmdBuf, "w");
  10496. 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));
  10497. fclose(fp);
  10498. }
  10499. else
  10500. {
  10501. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10502. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10503. }
  10504. }
  10505. else
  10506. {
  10507. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10508. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10509. //memset idTag
  10510. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10511. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10512. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10513. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10514. }
  10515. }
  10516. else
  10517. {
  10518. DEBUG_WARN("Connector id over\n.");
  10519. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10520. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10521. }
  10522. end:
  10523. json_object_put(RemoteStartTransaction);
  10524. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10525. {
  10526. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10527. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10528. }
  10529. //OCPP send RemoteStartConfirmation by first.
  10530. sendRemoteStartConfirmation(uuid, comfirmstr);
  10531. return result;
  10532. }
  10533. int handleRemoteStartRequest(char *uuid, char *payload)
  10534. {
  10535. mtrace();
  10536. int result = PASS;
  10537. int connectorIdInt=-1;
  10538. int tempIndex = 0;
  10539. char comfirmstr[20]={0};
  10540. char cmdBuf[512];
  10541. json_object *RemoteStartTransaction;
  10542. FILE *fp;
  10543. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10544. if(server_pending == TRUE)
  10545. {
  10546. result = FAIL;
  10547. }
  10548. RemoteStartTransaction = json_tokener_parse(payload);
  10549. if(!is_error(RemoteStartTransaction))
  10550. {
  10551. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10552. {
  10553. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10554. }
  10555. else
  10556. {
  10557. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10558. {
  10559. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10560. {
  10561. connectorIdInt = (gun_index+1);
  10562. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10563. break;
  10564. }
  10565. }
  10566. }
  10567. if(connectorIdInt == 0)
  10568. {
  10569. DEBUG_WARN("Connector id shall not equal 0.\n");
  10570. result = FAIL;
  10571. }
  10572. else if(connectorIdInt == -1)
  10573. {
  10574. DEBUG_INFO("Connector id does not specific.\n");
  10575. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10576. {
  10577. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10578. // Required data
  10579. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10580. // Optional data
  10581. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10582. {
  10583. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10584. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10585. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10586. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10587. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10588. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10589. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10590. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10591. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10592. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10593. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10594. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10595. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10596. {
  10597. 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")));
  10598. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10599. 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"));
  10600. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10601. 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"));
  10602. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10603. 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")));
  10604. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10605. {
  10606. 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++)
  10607. {
  10608. 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"));
  10609. 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"));
  10610. 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)
  10611. 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"));
  10612. }
  10613. }
  10614. }
  10615. }
  10616. else
  10617. {
  10618. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10619. }
  10620. }
  10621. }
  10622. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10623. {
  10624. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10625. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10626. // Required data
  10627. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10628. // Optional data
  10629. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10630. {
  10631. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10632. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10633. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10634. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10635. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10636. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10637. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10638. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10639. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10640. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10641. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10642. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10643. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10644. {
  10645. 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")));
  10646. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10647. 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"));
  10648. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10649. 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"));
  10650. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10651. 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")));
  10652. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10653. {
  10654. 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++)
  10655. {
  10656. 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"));
  10657. 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"));
  10658. 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)
  10659. 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"));
  10660. }
  10661. }
  10662. }
  10663. }
  10664. else
  10665. {
  10666. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10667. }
  10668. }
  10669. else
  10670. {
  10671. DEBUG_WARN("Connector id is over maximun value.\n");
  10672. result = FAIL;
  10673. }
  10674. }
  10675. if(result == PASS)
  10676. {
  10677. if(connectorIdInt > 0)
  10678. {
  10679. //check Transaction active
  10680. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10681. {
  10682. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10683. {
  10684. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10685. }
  10686. else
  10687. {
  10688. tempIndex = connectorIdInt -1;
  10689. }
  10690. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10691. {
  10692. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10693. {
  10694. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10695. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10696. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10697. {
  10698. //Reserved
  10699. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10700. }
  10701. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10702. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10703. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10704. {
  10705. //Reserved
  10706. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10707. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10708. goto end;
  10709. }
  10710. else
  10711. {
  10712. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10713. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10714. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10715. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10716. {
  10717. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10718. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10719. goto end;
  10720. }
  10721. }//END FOR ELSE
  10722. }
  10723. }// END FOR CHAdeMO_QUANTITY
  10724. }
  10725. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10726. {
  10727. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10728. {
  10729. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10730. }
  10731. else
  10732. {
  10733. tempIndex = connectorIdInt -1;
  10734. }
  10735. for (int index = 0; index < CCS_QUANTITY; index++)
  10736. {
  10737. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10738. {
  10739. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10740. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10741. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10742. {
  10743. //Reserved
  10744. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10745. }
  10746. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10747. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10748. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10749. {
  10750. //Reserved
  10751. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10752. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10753. goto end;
  10754. }
  10755. else
  10756. {
  10757. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10758. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10759. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10760. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10761. {
  10762. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10763. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10764. goto end;
  10765. }
  10766. }// END FOR ELSE
  10767. }
  10768. }// END FOR CCS_QUANTITY
  10769. }
  10770. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10771. {
  10772. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10773. {
  10774. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10775. }
  10776. else
  10777. {
  10778. tempIndex = connectorIdInt -1;
  10779. }
  10780. for (int index = 0; index < GB_QUANTITY; index++)
  10781. {
  10782. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10783. {
  10784. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10785. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10786. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10787. {
  10788. //Reserved
  10789. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10790. }
  10791. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10792. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10793. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10794. {
  10795. //Reserved
  10796. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10797. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10798. goto end;
  10799. }
  10800. else
  10801. {
  10802. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10803. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10804. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10805. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10806. {
  10807. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10808. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10809. goto end;
  10810. }
  10811. }// END FOR ELSE
  10812. }
  10813. } // END FOR GB_QUANTITY
  10814. }
  10815. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10816. {
  10817. tempIndex = connectorIdInt -1;
  10818. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10819. {
  10820. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10821. {
  10822. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10823. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10824. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10825. {
  10826. //Reserved
  10827. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10828. }
  10829. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10830. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10831. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10832. {
  10833. //Reserved
  10834. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10835. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10836. goto end;
  10837. }
  10838. else
  10839. {
  10840. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10841. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10842. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10843. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10844. {
  10845. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10846. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10847. goto end;
  10848. }
  10849. }// END FOR ELSE
  10850. }
  10851. } // END FOR GB_QUANTITY
  10852. }
  10853. else
  10854. {
  10855. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10856. {
  10857. tempIndex = 2;
  10858. }
  10859. else
  10860. {
  10861. tempIndex = connectorIdInt -1;
  10862. }
  10863. for (int index = 0; index < AC_QUANTITY; index++)
  10864. {
  10865. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10866. {
  10867. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10868. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10869. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10870. {
  10871. //Reserved
  10872. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10873. }
  10874. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10875. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10876. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10877. {
  10878. //Reserved
  10879. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10880. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10881. goto end;
  10882. }
  10883. else
  10884. {
  10885. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10886. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10887. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10888. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10889. {
  10890. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10891. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10892. goto end;
  10893. }
  10894. }//END FOR ELSE
  10895. }
  10896. }// END FOR AC_QUANTITY
  10897. }
  10898. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10899. {
  10900. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10901. {
  10902. // Save profile to file
  10903. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10904. system(cmdBuf);
  10905. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10906. fp = fopen(cmdBuf, "w");
  10907. 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));
  10908. fclose(fp);
  10909. }
  10910. else
  10911. {
  10912. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10913. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10914. goto end;
  10915. }
  10916. }
  10917. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10918. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10919. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10920. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10921. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10922. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10923. }
  10924. else
  10925. {
  10926. uint8_t isHasIdleConnector = FALSE;
  10927. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10928. {
  10929. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10930. {
  10931. isHasIdleConnector = TRUE;
  10932. break;
  10933. }
  10934. }
  10935. if(isHasIdleConnector == TRUE)
  10936. {
  10937. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10938. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10939. {
  10940. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10941. {
  10942. // Save profile to file
  10943. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  10944. system(cmdBuf);
  10945. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  10946. fp = fopen(cmdBuf, "w");
  10947. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10948. fclose(fp);
  10949. refreshStartTimer(&clientTime.RemoteStartWait);
  10950. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  10951. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10952. }
  10953. else
  10954. {
  10955. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10956. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10957. }
  10958. }
  10959. else
  10960. {
  10961. refreshStartTimer(&clientTime.RemoteStartWait);
  10962. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  10963. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10964. }
  10965. }
  10966. else
  10967. {
  10968. DEBUG_INFO("There is not any connector is idle.\n");
  10969. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10970. }
  10971. }
  10972. }
  10973. else
  10974. {
  10975. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10976. }
  10977. end:
  10978. json_object_put(RemoteStartTransaction);
  10979. sendRemoteStartConfirmation(uuid, comfirmstr);
  10980. return result;
  10981. }
  10982. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10983. {
  10984. mtrace();
  10985. int result = FAIL;
  10986. int match = FALSE;
  10987. int GunNO = 0;
  10988. int tempIndex = 0;
  10989. int transactionIdInt=0;
  10990. int transactionIdIsNULL= TRUE;
  10991. char comfirmstr[20];
  10992. json_object *RemoteStopTransaction;
  10993. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10994. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10995. if(server_pending == TRUE)
  10996. {
  10997. return 0;
  10998. }
  10999. RemoteStopTransaction = json_tokener_parse(payload);
  11000. if(!is_error(RemoteStopTransaction))
  11001. {
  11002. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11003. {
  11004. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11005. transactionIdIsNULL = FALSE;
  11006. }
  11007. }
  11008. json_object_put(RemoteStopTransaction);
  11009. if(transactionIdIsNULL == FALSE)
  11010. {
  11011. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11012. {
  11013. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11014. {
  11015. //check Transaction active
  11016. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11017. {
  11018. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11019. {
  11020. tempIndex = ((gun_index==2) ? 1: 0);
  11021. }
  11022. else
  11023. {
  11024. tempIndex = gun_index;
  11025. }
  11026. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11027. {
  11028. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11029. {
  11030. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11031. {
  11032. match = TRUE;
  11033. GunNO = gun_index;
  11034. }
  11035. }
  11036. }// END FOR CHAdeMO_QUANTITY
  11037. }
  11038. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11039. {
  11040. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11041. {
  11042. tempIndex = ((gun_index==2) ? 1: 0);
  11043. }
  11044. else
  11045. {
  11046. tempIndex = gun_index;
  11047. }
  11048. for (int index = 0; index < CCS_QUANTITY; index++)
  11049. {
  11050. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11051. {
  11052. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11053. {
  11054. match = TRUE;
  11055. GunNO = gun_index;
  11056. }
  11057. }
  11058. }// END FOR CCS_QUANTITY
  11059. }
  11060. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11061. {
  11062. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11063. {
  11064. tempIndex = ((gun_index==2) ? 1: 0);
  11065. }
  11066. else
  11067. {
  11068. tempIndex = gun_index;
  11069. }
  11070. for (int index = 0; index < GB_QUANTITY; index++)
  11071. {
  11072. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11073. {
  11074. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11075. {
  11076. match = TRUE;
  11077. GunNO = gun_index;
  11078. }
  11079. }
  11080. }// END FOR GB_QUANTITY
  11081. }
  11082. else if(gunType[gun_index] == GUN_TYPE_DO)
  11083. {
  11084. tempIndex = gun_index;
  11085. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11086. {
  11087. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11088. {
  11089. 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
  11090. {
  11091. match = TRUE;
  11092. GunNO = gun_index;
  11093. }
  11094. }
  11095. }// END FOR GB_QUANTITY
  11096. }
  11097. else
  11098. {
  11099. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11100. {
  11101. tempIndex = 2;
  11102. }
  11103. else
  11104. {
  11105. tempIndex = gun_index;
  11106. }
  11107. for (int index = 0; index < AC_QUANTITY; index++)
  11108. {
  11109. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11110. {
  11111. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11112. {
  11113. match = TRUE;
  11114. GunNO = gun_index;
  11115. }
  11116. }
  11117. }// END FOR CHAdeMO_QUANTITY
  11118. } // END FOR AC ELSE
  11119. }// CHECK IF ResponseTransactionId == transactionIdInt
  11120. }//END FOR
  11121. if( match == TRUE)
  11122. {
  11123. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11124. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11125. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11126. }
  11127. else
  11128. {
  11129. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11130. }
  11131. }
  11132. else
  11133. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11134. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11135. return result;
  11136. }
  11137. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11138. {
  11139. mtrace();
  11140. int result = FAIL;
  11141. int connectorIdInt=0, reservationIdInt=0;
  11142. int tempIndex = 0;
  11143. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  11144. char comfirmstr[20]={0};
  11145. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11146. int c = 0;
  11147. char *loc;
  11148. //char *ptr;
  11149. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11150. strcpy(sstrtemp, stringtrimspace(payload));
  11151. //***(1)connectorId ****/
  11152. c=0;
  11153. loc = strstr(sstrtemp, "connectorId");
  11154. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11155. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11156. {
  11157. sstr[c] = loc[strlen("connectorId")+2+c];
  11158. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11159. c++;
  11160. }
  11161. sstr[c] = '\0';
  11162. connectorIdInt = atoi(sstr);
  11163. //***(2)expiryDate ****/
  11164. loc = strstr(sstrtemp, "expiryDate");
  11165. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11166. c = 0;
  11167. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11168. {
  11169. sstr[c] = loc[3+strlen("expiryDate")+c];
  11170. c++;
  11171. }
  11172. sstr[c] = '\0';
  11173. strcpy(expiryDatestr, sstr);
  11174. //***(3)idTag ****/
  11175. loc = strstr(sstrtemp, "idTag");
  11176. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11177. c = 0;
  11178. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11179. {
  11180. sstr[c] = loc[3+strlen("idTag")+c];
  11181. c++;
  11182. }
  11183. sstr[c] = '\0';
  11184. strcpy(idTagstr, sstr);
  11185. //***(4)parentIdTag ****/
  11186. loc = strstr(sstrtemp, "parentIdTag");
  11187. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11188. c = 0;
  11189. if(loc == NULL)
  11190. {
  11191. strcpy(parentIdTagstr, "");
  11192. }
  11193. else
  11194. {
  11195. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11196. {
  11197. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11198. c++;
  11199. }
  11200. sstr[c] = '\0';
  11201. strcpy(parentIdTagstr, sstr);
  11202. }
  11203. //***(5)reservationId ****/
  11204. c=0;
  11205. loc = strstr(sstrtemp, "reservationId");
  11206. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11207. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11208. {
  11209. sstr[c] = loc[strlen("reservationId")+2+c];
  11210. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11211. c++;
  11212. }
  11213. sstr[c] = '\0';
  11214. reservationIdInt = atoi(sstr);
  11215. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11216. /*
  11217. enum SYSTEM_STATUS
  11218. {
  11219. SYS_MODE_BOOTING = 0,
  11220. SYS_MODE_IDLE = 1,
  11221. SYS_MODE_AUTHORIZING = 2,
  11222. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11223. SYS_MODE_REASSIGN = 4,
  11224. SYS_MODE_PREPARING = 5,
  11225. SYS_MODE_PREPARE_FOR_EV = 6,
  11226. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11227. SYS_MODE_CHARGING = 8,
  11228. SYS_MODE_TERMINATING = 9,
  11229. SYS_MODE_COMPLETE = 10,
  11230. SYS_MODE_ALARM = 11,
  11231. SYS_MODE_FAULT = 12,
  11232. SYS_MODE_RESERVATION = 13,
  11233. SYS_MODE_BOOKING = 14,
  11234. SYS_MODE_MAINTAIN = 15,
  11235. SYS_MODE_DEBUG = 16,
  11236. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11237. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11238. SYS_MODE_UPDATE = 19
  11239. };
  11240. */
  11241. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11242. {
  11243. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11244. goto end;
  11245. }
  11246. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11247. {
  11248. //check Transaction active
  11249. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11250. {
  11251. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11252. {
  11253. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11254. }
  11255. else
  11256. {
  11257. tempIndex = connectorIdInt -1;
  11258. }
  11259. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11260. {
  11261. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11262. {
  11263. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11264. {
  11265. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11266. {
  11267. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11268. {
  11269. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11270. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11271. }
  11272. 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'))
  11273. {
  11274. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11275. }
  11276. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11277. {
  11278. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11279. }
  11280. else
  11281. {
  11282. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11283. }
  11284. }
  11285. 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
  11286. {
  11287. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11288. }
  11289. }
  11290. else
  11291. {
  11292. //replace reservation
  11293. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11294. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11295. }
  11296. }
  11297. } // END FOR CHAdeMO_QUANTITY
  11298. }
  11299. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11300. {
  11301. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11302. {
  11303. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11304. }
  11305. else
  11306. {
  11307. tempIndex = connectorIdInt -1;
  11308. }
  11309. for (int index = 0; index < CCS_QUANTITY; index++)
  11310. {
  11311. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11312. {
  11313. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11314. {
  11315. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11316. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11317. {
  11318. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11319. {
  11320. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11321. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11322. }
  11323. 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'))
  11324. {
  11325. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11326. }
  11327. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11328. {
  11329. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11330. }
  11331. else
  11332. {
  11333. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11334. }
  11335. }
  11336. 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
  11337. {
  11338. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11339. }
  11340. }
  11341. else
  11342. {
  11343. //replace reservation
  11344. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11345. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11346. }
  11347. }
  11348. } // END FOR CCS_QUANTITY
  11349. }
  11350. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11351. {
  11352. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11353. {
  11354. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11355. }
  11356. else
  11357. {
  11358. tempIndex = connectorIdInt -1;
  11359. }
  11360. for (int index = 0; index < GB_QUANTITY; index++)
  11361. {
  11362. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11363. {
  11364. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11365. {
  11366. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11367. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11368. {
  11369. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11370. {
  11371. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11372. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11373. }
  11374. 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'))
  11375. {
  11376. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11377. }
  11378. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11379. {
  11380. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11381. }
  11382. else
  11383. {
  11384. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11385. }
  11386. }
  11387. 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
  11388. {
  11389. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11390. }
  11391. }
  11392. else
  11393. {
  11394. //replace reservation
  11395. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11396. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11397. }
  11398. }
  11399. }// END FOR GB_QUANTITY
  11400. }
  11401. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11402. {
  11403. tempIndex = connectorIdInt -1;
  11404. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11405. {
  11406. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11407. {
  11408. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11409. {
  11410. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11411. 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
  11412. {
  11413. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11414. {
  11415. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11416. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11417. }
  11418. 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'))
  11419. {
  11420. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11421. }
  11422. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11423. {
  11424. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11425. }
  11426. else
  11427. {
  11428. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11429. }
  11430. }
  11431. 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
  11432. {
  11433. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11434. }
  11435. }
  11436. else
  11437. {
  11438. //replace reservation
  11439. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11440. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11441. }
  11442. }
  11443. }// END FOR GB_QUANTITY
  11444. }
  11445. else
  11446. {
  11447. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11448. {
  11449. tempIndex = 2;
  11450. }
  11451. else
  11452. {
  11453. tempIndex = (connectorIdInt -1);
  11454. }
  11455. for (int index = 0; index < AC_QUANTITY; index++)
  11456. {
  11457. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11458. {
  11459. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11460. {
  11461. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11462. {
  11463. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11464. {
  11465. 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))
  11466. {
  11467. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11468. }
  11469. else
  11470. {
  11471. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11472. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11473. }
  11474. }
  11475. 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'))
  11476. {
  11477. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11478. }
  11479. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11480. {
  11481. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11482. }
  11483. else
  11484. {
  11485. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11486. }
  11487. }
  11488. 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
  11489. {
  11490. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11491. }
  11492. }
  11493. else
  11494. {
  11495. //replace reservation
  11496. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11497. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11498. }
  11499. }
  11500. } // END FOR AC_QUANTITY
  11501. }
  11502. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11503. }
  11504. else if(connectorIdInt == 0)
  11505. {
  11506. //check Transaction active
  11507. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11508. {
  11509. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11510. {
  11511. 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'))
  11512. {
  11513. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11514. goto end;
  11515. }
  11516. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11517. {
  11518. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11519. goto end;
  11520. }
  11521. 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
  11522. {
  11523. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11524. goto end;
  11525. }
  11526. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11527. {
  11528. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11529. goto end;
  11530. }
  11531. }
  11532. }// END FOR CHAdeMO_QUANTITY
  11533. for (int index = 0; index < CCS_QUANTITY; index++)
  11534. {
  11535. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11536. {
  11537. 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'))
  11538. {
  11539. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11540. goto end;
  11541. }
  11542. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11543. {
  11544. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11545. goto end;
  11546. }
  11547. 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
  11548. {
  11549. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11550. goto end;
  11551. }
  11552. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11553. {
  11554. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11555. goto end;
  11556. }
  11557. }
  11558. } // END FOR CCS_QUANTITY
  11559. for (int index = 0; index < GB_QUANTITY; index++)
  11560. {
  11561. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11562. {
  11563. 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'))
  11564. {
  11565. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11566. goto end;
  11567. }
  11568. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11569. {
  11570. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11571. goto end;
  11572. }
  11573. 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
  11574. {
  11575. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11576. goto end;
  11577. }
  11578. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11579. {
  11580. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11581. goto end;
  11582. }
  11583. }
  11584. } // END FOR GB_QUANTITY
  11585. for (int index = 0; index < AC_QUANTITY; index++)
  11586. {
  11587. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11588. {
  11589. 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'))
  11590. {
  11591. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11592. goto end;
  11593. }
  11594. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11595. {
  11596. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11597. goto end;
  11598. }
  11599. 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
  11600. {
  11601. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11602. goto end;
  11603. }
  11604. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11605. {
  11606. 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))
  11607. {
  11608. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11609. goto end;
  11610. }
  11611. }
  11612. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11613. {
  11614. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11615. goto end;
  11616. }
  11617. }
  11618. }// END FOR AC_QUANTITY
  11619. //The connectorId is 0
  11620. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  11621. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11622. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11623. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  11624. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11625. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  11626. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11627. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  11628. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  11629. result = TRUE;
  11630. return result;
  11631. }
  11632. else
  11633. {
  11634. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11635. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11636. }
  11637. if(strcmp(comfirmstr,"Accepted") == 0)
  11638. {
  11639. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11640. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11641. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11642. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11643. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11644. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  11645. result = TRUE;
  11646. return result;
  11647. }
  11648. end:
  11649. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11650. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11651. return result;
  11652. }
  11653. int handleResetRequest(char *uuid, char *payload)
  11654. {
  11655. mtrace();
  11656. int result = FAIL;
  11657. char sstr[10]={0},sstrtemp[30]={ 0 };
  11658. char typestr[10]={0};
  11659. char comfirmstr[20]={0};
  11660. int c = 0;
  11661. char *loc;
  11662. DEBUG_INFO("handleResetRequest...\n");
  11663. strcpy(sstrtemp, stringtrimspace(payload));
  11664. loc = strstr(sstrtemp, "type");
  11665. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11666. c = 0;
  11667. while (loc[3+strlen("type")+c] != '\"')
  11668. {
  11669. sstr[c] = loc[3+strlen("type")+c];
  11670. c++;
  11671. }
  11672. sstr[c] = '\0';
  11673. strcpy(typestr,sstr);
  11674. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11675. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11676. {
  11677. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11678. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  11679. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11680. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11681. }
  11682. else
  11683. {
  11684. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11685. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11686. result = PASS;
  11687. }
  11688. sendResetConfirmation(uuid, comfirmstr);
  11689. return result;
  11690. }
  11691. int handleSendLocalListRequest(char *uuid, char *payload)
  11692. {
  11693. mtrace();
  11694. int result = FAIL;
  11695. char comfirmstr[20];
  11696. int checkState_Faulted = FALSE;
  11697. json_object *SendLocalList;
  11698. DEBUG_INFO("handleSendLocalListRequest...\n");
  11699. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11700. {
  11701. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11702. goto end;
  11703. }
  11704. //check Charge Point state
  11705. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11706. {
  11707. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11708. {
  11709. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11710. }
  11711. }
  11712. for (int index = 0; index < CCS_QUANTITY; index++)
  11713. {
  11714. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11715. {
  11716. checkState_Faulted = TRUE; //OCPP Status
  11717. }
  11718. }
  11719. for (int index = 0; index < GB_QUANTITY; index++)
  11720. {
  11721. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11722. {
  11723. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11724. }
  11725. }
  11726. //check Charge Point state
  11727. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11728. {
  11729. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11730. {
  11731. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11732. }
  11733. }
  11734. //check Charge Point state
  11735. for (int index = 0; index < AC_QUANTITY; index++)
  11736. {
  11737. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11738. {
  11739. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11740. }
  11741. }
  11742. if(checkState_Faulted == TRUE)
  11743. {
  11744. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11745. goto end;
  11746. }
  11747. // Parsing payload
  11748. SendLocalList = json_tokener_parse(payload);
  11749. if(!is_error(SendLocalList))
  11750. {
  11751. // Required data
  11752. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11753. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11754. // Optional data
  11755. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11756. {
  11757. //Check UpdateType
  11758. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11759. {
  11760. //Local list full update
  11761. DEBUG_INFO("Local list full update.\n");
  11762. OCPP_getListVerion();
  11763. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11764. {
  11765. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11766. goto end;
  11767. }
  11768. OCPP_cleanLocalList();
  11769. }
  11770. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11771. {
  11772. //Local list different update
  11773. DEBUG_INFO("Local list different update.\n");
  11774. OCPP_getListVerion();
  11775. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11776. {
  11777. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11778. goto end;
  11779. }
  11780. }
  11781. else
  11782. {
  11783. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11784. goto end;
  11785. }
  11786. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11787. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11788. {
  11789. 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")));
  11790. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11791. {
  11792. 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")));
  11793. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11794. 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")));
  11795. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11796. 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")));
  11797. }
  11798. // Add to db
  11799. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11800. {
  11801. //Local list full update
  11802. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11803. idx,
  11804. ShmOCPP16Data->SendLocalList.ListVersion,
  11805. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11806. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11807. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11808. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11809. // update list
  11810. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11811. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11812. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11813. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11814. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11815. }
  11816. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11817. {
  11818. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11819. idx,
  11820. ShmOCPP16Data->SendLocalList.ListVersion,
  11821. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11822. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11823. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11824. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11825. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11826. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11827. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11828. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11829. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11830. }
  11831. }
  11832. }
  11833. else
  11834. {
  11835. //Check UpdateType
  11836. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11837. {
  11838. //Local list full update
  11839. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11840. OCPP_cleanLocalList();
  11841. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11842. goto end;
  11843. }
  11844. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11845. {
  11846. //Local list different update
  11847. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11848. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11849. goto end;
  11850. }
  11851. }
  11852. result = PASS;
  11853. }
  11854. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11855. end:
  11856. json_object_put(SendLocalList);
  11857. sendSendLocalListConfirmation(uuid, comfirmstr);
  11858. return result;
  11859. }
  11860. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11861. {
  11862. mtrace();
  11863. int result = FAIL;
  11864. struct StructSetChargingProfile SetProfileReq = {0};
  11865. int tempchargingProfileIdInt;
  11866. int chargingSchedulePeriodCount = 0;
  11867. char comfirmstr[20]={0};
  11868. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  11869. char rmFileCmd[128]={0};
  11870. int profileQuantity = 0;
  11871. json_object *SetChargingProfile;
  11872. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11873. SetChargingProfile = json_tokener_parse(payload);
  11874. if(!is_error(SetChargingProfile))
  11875. {
  11876. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11877. {
  11878. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11879. }
  11880. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11881. {
  11882. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11883. {
  11884. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11885. }
  11886. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11887. {
  11888. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11889. }
  11890. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11891. {
  11892. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11893. }
  11894. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11895. {
  11896. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11897. }
  11898. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11899. {
  11900. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11901. }
  11902. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11903. {
  11904. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11905. }
  11906. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11907. {
  11908. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11909. }
  11910. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11911. {
  11912. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11913. }
  11914. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11915. {
  11916. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11917. {
  11918. 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")));
  11919. }
  11920. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11921. {
  11922. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11923. }
  11924. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11925. {
  11926. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11927. }
  11928. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11929. {
  11930. 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")));
  11931. }
  11932. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11933. {
  11934. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11935. if(chargingSchedulePeriodCount <= 10)
  11936. {
  11937. 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++)
  11938. {
  11939. 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)
  11940. {
  11941. 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"));
  11942. }
  11943. 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)
  11944. {
  11945. 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"));
  11946. }
  11947. 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)
  11948. {
  11949. 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"));
  11950. }
  11951. }
  11952. }
  11953. }
  11954. }
  11955. }
  11956. }
  11957. // Profile periods quantity check
  11958. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11959. {
  11960. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11961. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11962. goto end;
  11963. }
  11964. // Check invalid limit
  11965. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11966. {
  11967. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11968. {
  11969. 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)))) ||
  11970. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11971. {
  11972. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11973. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11974. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11975. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11976. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11977. goto end;
  11978. }
  11979. }
  11980. }
  11981. else
  11982. {
  11983. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11984. {
  11985. 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))
  11986. {
  11987. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11988. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11989. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11990. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11991. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11992. goto end;
  11993. }
  11994. }
  11995. }
  11996. // Profile purpose info check
  11997. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11998. {
  11999. FILE *fp;
  12000. char dataLine[4096]={0};
  12001. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12002. if(SetProfileReq.ConnectorId != 0)
  12003. {
  12004. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12005. DEBUG_WARN("Profile connector id is not 0.\n");
  12006. goto end;
  12007. }
  12008. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12009. if (!fp)
  12010. {
  12011. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12012. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12013. }
  12014. else
  12015. {
  12016. while(fscanf(fp, "%s", dataLine) != EOF)
  12017. {
  12018. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12019. {
  12020. profileQuantity += 1;
  12021. }
  12022. }
  12023. }
  12024. fclose(fp);
  12025. }
  12026. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12027. {
  12028. FILE *fp;
  12029. char dataLine[4096]={0};
  12030. char filename[128]={0};
  12031. int tmpProfileQuantity;
  12032. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12033. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12034. {
  12035. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12036. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12037. goto end;
  12038. }
  12039. if(SetProfileReq.ConnectorId == 0)
  12040. {
  12041. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12042. {
  12043. tmpProfileQuantity = 0;
  12044. memset(filename, 0, ARRAY_SIZE(filename));
  12045. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12046. fp = fopen(filename, "r");
  12047. if (!fp)
  12048. {
  12049. DEBUG_INFO("%s does not create.\n", filename);
  12050. fp = fopen(filename, "w+");
  12051. }
  12052. else
  12053. {
  12054. while(fscanf(fp, "%s", dataLine) != EOF)
  12055. {
  12056. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12057. {
  12058. tmpProfileQuantity += 1;
  12059. }
  12060. }
  12061. }
  12062. fclose(fp);
  12063. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12064. }
  12065. }
  12066. else
  12067. {
  12068. memset(filename, 0, ARRAY_SIZE(filename));
  12069. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12070. fp = fopen(filename, "r");
  12071. if (!fp)
  12072. {
  12073. DEBUG_INFO("%s does not create.\n", filename);
  12074. fp = fopen(filename, "w+");
  12075. }
  12076. else
  12077. {
  12078. while(fscanf(fp, "%s", dataLine) != EOF)
  12079. {
  12080. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12081. {
  12082. profileQuantity += 1;
  12083. }
  12084. }
  12085. }
  12086. fclose(fp);
  12087. }
  12088. }
  12089. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12090. {
  12091. int isMatchTransactiodId= FALSE;
  12092. FILE *fp;
  12093. char dataLine[4096]={0};
  12094. char filename[128]={0};
  12095. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12096. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12097. if(SetProfileReq.ConnectorId == 0)
  12098. {
  12099. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12100. DEBUG_WARN("Profile connector id is 0.\n");
  12101. goto end;
  12102. }
  12103. int tempIndex = 0;
  12104. //check Transaction active
  12105. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12106. {
  12107. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12108. {
  12109. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12110. }
  12111. else
  12112. {
  12113. tempIndex = SetProfileReq.ConnectorId -1;
  12114. }
  12115. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12116. {
  12117. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12118. {
  12119. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12120. {
  12121. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12122. {
  12123. isMatchTransactiodId = TRUE;
  12124. break;
  12125. }
  12126. }
  12127. }
  12128. }
  12129. }
  12130. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12131. {
  12132. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12133. {
  12134. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12135. }
  12136. else
  12137. {
  12138. tempIndex = SetProfileReq.ConnectorId -1;
  12139. }
  12140. for (int index = 0; index < CCS_QUANTITY; index++)
  12141. {
  12142. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12143. {
  12144. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12145. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12146. {
  12147. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12148. {
  12149. isMatchTransactiodId = TRUE;
  12150. break;
  12151. }
  12152. }
  12153. }
  12154. }
  12155. }
  12156. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12157. {
  12158. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12159. {
  12160. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12161. }
  12162. else
  12163. {
  12164. tempIndex = SetProfileReq.ConnectorId -1;
  12165. }
  12166. for (int index = 0; index < GB_QUANTITY; index++)
  12167. {
  12168. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12169. {
  12170. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12171. {
  12172. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12173. {
  12174. isMatchTransactiodId = TRUE;
  12175. break;
  12176. }
  12177. }
  12178. }
  12179. }
  12180. }
  12181. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12182. {
  12183. tempIndex = SetProfileReq.ConnectorId -1;
  12184. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12185. {
  12186. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12187. {
  12188. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12189. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12190. {
  12191. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12192. {
  12193. isMatchTransactiodId = TRUE;
  12194. break;
  12195. }
  12196. }
  12197. }
  12198. }
  12199. }
  12200. else
  12201. {
  12202. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12203. {
  12204. tempIndex = 2;
  12205. }
  12206. else
  12207. {
  12208. tempIndex = (SetProfileReq.ConnectorId -1);
  12209. }
  12210. for (int index = 0; index < AC_QUANTITY; index++)
  12211. {
  12212. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12213. {
  12214. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12215. {
  12216. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12217. {
  12218. isMatchTransactiodId = TRUE;
  12219. break;
  12220. }
  12221. }
  12222. }
  12223. }
  12224. }
  12225. //check Transaction active
  12226. if(isMatchTransactiodId == FALSE)
  12227. {
  12228. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12229. DEBUG_WARN("Tx profile transaction id is not match.\n");
  12230. goto end;
  12231. }
  12232. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12233. {
  12234. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12235. DEBUG_WARN("Connector id is over max gun number.\n");
  12236. goto end;
  12237. }
  12238. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12239. fp = fopen(filename, "r");
  12240. if (!fp)
  12241. {
  12242. DEBUG_INFO("%s does not create.\n", filename);
  12243. fp = fopen(filename, "w+");
  12244. }
  12245. else
  12246. {
  12247. //Check Charging Profile Count
  12248. while(fscanf(fp, "%s", dataLine) != EOF)
  12249. {
  12250. //DEBUG_INFO("word=%s\n",word);
  12251. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12252. {
  12253. profileQuantity += 1;
  12254. }
  12255. }
  12256. }
  12257. fclose(fp);
  12258. }
  12259. // Check ChargeProfileMaxStackLevel
  12260. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12261. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12262. {
  12263. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12264. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12265. goto end;
  12266. }
  12267. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12268. {
  12269. FILE *fp;
  12270. char dataLine[4096]={0};
  12271. char fnametemp[128]={0};
  12272. int tmpProfileQuantity;
  12273. //Check ChargePointMaxProfile.json exit
  12274. profileQuantity = 0;
  12275. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12276. {
  12277. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  12278. //Check Charging Profile Count
  12279. tmpProfileQuantity = 0;
  12280. while(fscanf(fp, "%s", dataLine) != EOF)
  12281. {
  12282. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12283. {
  12284. profileQuantity += 1;
  12285. tmpProfileQuantity += 1;
  12286. }
  12287. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12288. }
  12289. fclose(fp);
  12290. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12291. }
  12292. //Check TxDefaultProfile_%d.json
  12293. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12294. {
  12295. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12296. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12297. if((access(fnametemp,F_OK))!=-1)
  12298. {
  12299. fp = fopen(fnametemp, "r");
  12300. //Check Charging Profile Count
  12301. tmpProfileQuantity = 0;
  12302. while(fscanf(fp, "%s", dataLine) != EOF)
  12303. {
  12304. //DEBUG_INFO("word=%s\n",word);
  12305. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12306. {
  12307. profileQuantity += 1;
  12308. tmpProfileQuantity += 1;
  12309. }
  12310. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12311. }
  12312. fclose(fp);
  12313. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12314. }
  12315. }
  12316. //Check TxProfile_%d.json
  12317. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12318. {
  12319. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12320. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  12321. if((access(fnametemp,F_OK))!=-1)
  12322. {
  12323. fp = fopen(fnametemp, "r");
  12324. //Check Charging Profile Count
  12325. tmpProfileQuantity = 0;
  12326. while(fscanf(fp, "%s", dataLine) != EOF)
  12327. {
  12328. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12329. {
  12330. profileQuantity += 1;
  12331. tmpProfileQuantity += 1;
  12332. }
  12333. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12334. }
  12335. fclose(fp);
  12336. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12337. }
  12338. }
  12339. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12340. if(profileQuantity > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12341. {
  12342. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12343. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12344. goto end;
  12345. }
  12346. }
  12347. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12348. //**********************************Write to File********************************************************/
  12349. {
  12350. FILE *infile;
  12351. FILE *outfile;
  12352. char dataLine[4096]={0};
  12353. char filename[128]={0};
  12354. int chkChar=0;
  12355. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12356. {
  12357. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12358. {
  12359. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12360. }
  12361. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12362. {
  12363. if(SetProfileReq.ConnectorId==0)
  12364. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12365. else
  12366. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12367. }
  12368. else
  12369. {
  12370. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12371. }
  12372. infile = fopen (filename, "r");
  12373. outfile = fopen (tempfile, "w");
  12374. chkChar = fgetc(infile);
  12375. rewind(infile);
  12376. if(chkChar == EOF)
  12377. {
  12378. // Profile is empty
  12379. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12380. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12381. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12382. fclose(infile);
  12383. fclose(outfile);
  12384. sprintf(rmFileCmd,"rm -f %s",filename);
  12385. system(rmFileCmd);
  12386. rename(tempfile, filename);
  12387. }
  12388. else
  12389. {
  12390. // Profile is not empty
  12391. int ChargingProfileAdded = FALSE;
  12392. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12393. {
  12394. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12395. json_object *tmpChargingProfile;
  12396. tmpChargingProfile = json_tokener_parse(dataLine);
  12397. if(!is_error(SetChargingProfile))
  12398. {
  12399. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12400. {
  12401. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12402. {
  12403. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12404. }
  12405. }
  12406. }
  12407. json_object_put(tmpChargingProfile);
  12408. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12409. {
  12410. if(ChargingProfileAdded == FALSE)
  12411. {
  12412. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12413. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12414. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12415. ChargingProfileAdded = TRUE;
  12416. }
  12417. }
  12418. else
  12419. {
  12420. fprintf(outfile,"%s\n",dataLine);
  12421. if(ChargingProfileAdded == FALSE)
  12422. {
  12423. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12424. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12425. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12426. ChargingProfileAdded = TRUE;
  12427. }
  12428. }
  12429. } // end of while loop
  12430. fclose(infile);
  12431. fclose(outfile);
  12432. sprintf(rmFileCmd,"rm -f %s",filename);
  12433. system(rmFileCmd);
  12434. rename(tempfile, filename);
  12435. }
  12436. }
  12437. sleep(1);
  12438. result = TRUE;
  12439. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12440. }
  12441. end:
  12442. json_object_put(SetChargingProfile);
  12443. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12444. {
  12445. if(SetProfileReq.ConnectorId == 0)
  12446. {
  12447. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12448. {
  12449. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  12450. }
  12451. }
  12452. else
  12453. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12454. }
  12455. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12456. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12457. return result;
  12458. }
  12459. int handleTriggerMessageRequest(char *uuid, char *payload)
  12460. {
  12461. mtrace();
  12462. int result = FAIL;
  12463. int connectorIdIsNULL = FALSE;
  12464. int connectorIdInt =0;
  12465. char sstr[40]={0},sstrtemp[100]={ 0 };
  12466. char requestedMessagestr[40]={0};
  12467. char comfirmstr[20]={0};
  12468. int c = 0;
  12469. char *loc;
  12470. DEBUG_INFO("handleTriggerMessageRequest\n");
  12471. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12472. strcpy(sstrtemp, stringtrimspace(payload));
  12473. c = 0;
  12474. loc = strstr(sstrtemp, "requestedMessage");
  12475. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12476. {
  12477. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12478. c++;
  12479. }
  12480. sstr[c] = '\0';
  12481. strcpy(requestedMessagestr, sstr);
  12482. c = 0;
  12483. loc = strstr(sstrtemp, "connectorId");
  12484. if(loc == NULL)
  12485. {
  12486. connectorIdIsNULL = TRUE;
  12487. }
  12488. else
  12489. {
  12490. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12491. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12492. {
  12493. sstr[c] = loc[strlen("connectorId")+2+c];
  12494. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12495. c++;
  12496. }
  12497. sstr[c] = '\0';
  12498. connectorIdInt = atoi(sstr);
  12499. }
  12500. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12501. {
  12502. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12503. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12504. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12505. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12506. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12507. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12508. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12509. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12510. {
  12511. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12512. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12513. return TRUE;
  12514. }
  12515. else
  12516. {
  12517. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12518. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12519. }
  12520. }
  12521. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12522. {
  12523. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12524. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12525. return TRUE;
  12526. }
  12527. //==========================
  12528. // Trigger message
  12529. //==========================
  12530. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12531. {
  12532. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12533. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12534. {
  12535. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12536. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12537. }
  12538. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12539. }
  12540. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12541. {
  12542. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  12543. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12544. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12545. }
  12546. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12547. {
  12548. //sendBootNotificationRequest();
  12549. server_sign = FALSE;
  12550. }
  12551. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12552. {
  12553. refreshStartTimer(&clientTime.Heartbeat);
  12554. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  12555. }
  12556. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12557. {
  12558. if(connectorIdIsNULL == FALSE)
  12559. {
  12560. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12561. {
  12562. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12563. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12564. }
  12565. }
  12566. else
  12567. {
  12568. for(int idx=0;idx< gunTotalNumber;idx++)
  12569. {
  12570. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12571. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12572. }
  12573. }
  12574. }
  12575. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12576. {
  12577. if(connectorIdIsNULL == FALSE)
  12578. {
  12579. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  12580. {
  12581. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12582. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  12583. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12584. }
  12585. }
  12586. else
  12587. {
  12588. for(int idx=0;idx< gunTotalNumber;idx++)
  12589. {
  12590. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  12591. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12592. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12593. }
  12594. }
  12595. }
  12596. return result;
  12597. }
  12598. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12599. {
  12600. mtrace();
  12601. int result = FAIL;
  12602. int connectorIdInt =0;
  12603. char comfirmstr[20]={0};
  12604. int tempIndex = 0;
  12605. json_object *UnlockConnector;
  12606. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12607. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12608. UnlockConnector = json_tokener_parse(payload);
  12609. if(!is_error(UnlockConnector))
  12610. {
  12611. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12612. {
  12613. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12614. }
  12615. }
  12616. json_object_put(UnlockConnector);
  12617. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12618. if(gunTotalNumber == 0)
  12619. {
  12620. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12621. goto end;
  12622. }
  12623. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12624. {
  12625. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12626. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12627. goto end;
  12628. }
  12629. else
  12630. {
  12631. //check Transaction active
  12632. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12633. {
  12634. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12635. {
  12636. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12637. }
  12638. else
  12639. {
  12640. tempIndex = connectorIdInt -1;
  12641. }
  12642. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12643. {
  12644. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12645. {
  12646. //stop Transaction
  12647. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12648. }
  12649. }
  12650. }
  12651. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12652. {
  12653. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12654. {
  12655. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12656. }
  12657. else
  12658. {
  12659. tempIndex = connectorIdInt -1;
  12660. }
  12661. for (int index = 0; index < CCS_QUANTITY; index++)
  12662. {
  12663. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12664. {
  12665. //stop Transaction
  12666. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12667. }
  12668. }
  12669. }
  12670. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12671. {
  12672. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12673. {
  12674. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12675. }
  12676. else
  12677. {
  12678. tempIndex = connectorIdInt -1;
  12679. }
  12680. for (int index = 0; index < GB_QUANTITY; index++)
  12681. {
  12682. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12683. {
  12684. //stop Transaction
  12685. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12686. }
  12687. }
  12688. }
  12689. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12690. {
  12691. tempIndex = connectorIdInt -1;
  12692. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12693. {
  12694. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12695. {
  12696. //stop Transaction
  12697. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12698. }
  12699. }
  12700. }
  12701. else
  12702. {
  12703. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12704. {
  12705. tempIndex = 2;
  12706. }
  12707. else
  12708. {
  12709. tempIndex = connectorIdInt-1;
  12710. }
  12711. for (int index = 0; index < AC_QUANTITY; index++)
  12712. {
  12713. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12714. {
  12715. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12716. }
  12717. }
  12718. }
  12719. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12720. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  12721. result = TRUE;
  12722. return result;
  12723. }
  12724. end:
  12725. //json_object_put(obj); --- remove temporally
  12726. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12727. return result;
  12728. }
  12729. static char UpdateFirmwarepayloadData[300]={0};
  12730. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12731. {
  12732. mtrace();
  12733. int result = FAIL;
  12734. pthread_t t;
  12735. sendUpdateFirmwareConfirmation(uuid);
  12736. memset(UpdateFirmwarepayloadData, 0, 300);
  12737. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12738. if(!interLock.isUpdateFirmwareGoing)
  12739. {
  12740. interLock.isUpdateFirmwareGoing = 1;
  12741. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12742. sleep(1);
  12743. }
  12744. else
  12745. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12746. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  12747. return result;
  12748. }
  12749. void *UpdateFirmwareProcess(void *data)
  12750. {
  12751. pthread_detach(pthread_self());
  12752. mtrace();
  12753. int retriesInt =0, retryIntervalInt=0;
  12754. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  12755. int port=0;
  12756. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  12757. int isSuccess = 0;
  12758. char ftpbuf[1024];
  12759. char temp[1024];
  12760. char * pch;
  12761. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12762. json_object *UpdateFirmware;
  12763. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12764. if(!is_error(UpdateFirmware))
  12765. {
  12766. // Required data
  12767. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12768. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12769. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12770. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12771. // Optional data
  12772. if(json_object_object_get(UpdateFirmware, "retries"))
  12773. {
  12774. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12775. }
  12776. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12777. {
  12778. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12779. }
  12780. }
  12781. json_object_put(UpdateFirmware);
  12782. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12783. memset(path, 0, ARRAY_SIZE(path));
  12784. // Wait retrieveData
  12785. if(strlen(retrieveDatestr) > 10)
  12786. {
  12787. do
  12788. {
  12789. sleep(1);
  12790. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12791. }
  12792. // Ready to download
  12793. system("rm -f /mnt/*");
  12794. if(strncmp(locationstr,"http", 4) == 0)
  12795. {
  12796. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12797. sprintf(ftppath,"/%s", path);
  12798. DEBUG_INFO("locationstr: %s\n", locationstr);
  12799. DEBUG_INFO("protocol: %s\n",protocol);
  12800. DEBUG_INFO("host: %s\n",host);
  12801. DEBUG_INFO("path: %s\n",path);
  12802. DEBUG_INFO("ftppath: %s\n",ftppath);
  12803. int ftppathlen=strlen(ftppath);
  12804. int i=1;
  12805. char filenametemp[50];
  12806. while(i < ftppathlen)
  12807. {
  12808. int len=ftppathlen-i;
  12809. if(ftppath[len]== 47) // '/' ascll code: 47
  12810. {
  12811. DEBUG_INFO("compare '/' all right\n");
  12812. break;
  12813. }
  12814. i=i+1;
  12815. }
  12816. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12817. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12818. filenametemp[i+1] = 0;
  12819. do
  12820. {
  12821. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12822. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12823. sleep(1);
  12824. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12825. if(!isSuccess)
  12826. {
  12827. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12828. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12829. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12830. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12831. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12832. }
  12833. else
  12834. {
  12835. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12836. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12837. }
  12838. retriesInt--;
  12839. }while((isSuccess == 0)&&(retriesInt >= 0));
  12840. }
  12841. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12842. {
  12843. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12844. memset(temp, 0, ARRAY_SIZE(temp));
  12845. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12846. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12847. int ftppathlen=strlen(ftpbuf);
  12848. int i=1;
  12849. char filenametemp[50];
  12850. while(i < ftppathlen)
  12851. {
  12852. int len=ftppathlen-i;
  12853. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12854. {
  12855. DEBUG_INFO(" compare '/' all right\n");
  12856. break;
  12857. }
  12858. i=i+1;
  12859. }
  12860. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12861. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12862. filenametemp[i+1] = 0;
  12863. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12864. pch=strchr(temp,'@');
  12865. if(pch==NULL)
  12866. {
  12867. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12868. protocol, host, &port, path);
  12869. strcpy(user,"anonymous");
  12870. strcpy(password,"");
  12871. }
  12872. else
  12873. {
  12874. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12875. protocol, user, password, host, &port, path);
  12876. }
  12877. sscanf(host,"%[^/]%s",host1, path1);
  12878. sprintf(ftppath,"%s", path1);
  12879. //DEBUG_INFO("protocol =%s\n",protocol);
  12880. //DEBUG_INFO("user =%s\n",user);
  12881. //DEBUG_INFO("password =%s\n",password);
  12882. //DEBUG_INFO("host1 =%s\n",host1);
  12883. //DEBUG_INFO("port =%d\n",port);
  12884. //DEBUG_INFO("path1 =%s\n",path1);
  12885. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12886. //ftpFile(host, user, password, port, ftppath, fname);
  12887. //download firmware pthred
  12888. if(port == 0)
  12889. {
  12890. port = 21;
  12891. }
  12892. do
  12893. {
  12894. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12895. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12896. sleep(1);
  12897. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12898. if(!isSuccess)
  12899. {
  12900. //BulldogUtil.sleepMs(interval*1000);
  12901. DEBUG_INFO("Update firmware request and download file fail.\n");
  12902. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12903. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12904. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12905. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12906. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12907. }
  12908. else
  12909. {
  12910. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12911. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12912. }
  12913. retriesInt--;
  12914. }while((!isSuccess)&&(retriesInt >= 0));
  12915. }
  12916. else
  12917. {
  12918. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12919. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12920. sleep(1);
  12921. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12922. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12923. }
  12924. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12925. interLock.isUpdateFirmwareGoing = 0;
  12926. pthread_exit(NULL);
  12927. }
  12928. int handleCertificateSignedRequest(char *uuid, char *payload)
  12929. {
  12930. mtrace();
  12931. int result = PASS;
  12932. json_object *CertificateSigned;
  12933. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12934. CertificateSigned = json_tokener_parse(payload);
  12935. if(!is_error(CertificateSigned))
  12936. {
  12937. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  12938. }
  12939. json_object_put(CertificateSigned);
  12940. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  12941. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  12942. fclose(fp);
  12943. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12944. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  12945. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  12946. sendCertificateSignedConfirmation(uuid);
  12947. return result;
  12948. }
  12949. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12950. {
  12951. mtrace();
  12952. int result = PASS;
  12953. json_object *DeleteCertificate;
  12954. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12955. DeleteCertificate = json_tokener_parse(payload);
  12956. if(!is_error(DeleteCertificate))
  12957. {
  12958. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12959. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12960. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12961. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12962. }
  12963. json_object_put(DeleteCertificate);
  12964. /*
  12965. * TODO: Delete certificateSigned process
  12966. */
  12967. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  12968. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  12969. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  12970. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  12971. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  12972. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  12973. sendDeleteCertificateConfirmation(uuid);
  12974. return result;
  12975. }
  12976. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12977. {
  12978. mtrace();
  12979. int result = PASS;
  12980. json_object *ExtendedTriggerMessage;
  12981. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12982. ExtendedTriggerMessage = json_tokener_parse(payload);
  12983. if(!is_error(ExtendedTriggerMessage))
  12984. {
  12985. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12986. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12987. {
  12988. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12989. }
  12990. else
  12991. {
  12992. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  12993. }
  12994. }
  12995. json_object_put(ExtendedTriggerMessage);
  12996. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  12997. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  12998. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  12999. {
  13000. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13001. }
  13002. else
  13003. {
  13004. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13005. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13006. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13007. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13008. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13009. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13010. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13011. {
  13012. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13013. }
  13014. else
  13015. {
  13016. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13017. }
  13018. }
  13019. sendExtendedTriggerMessageConfirmation(uuid);
  13020. //==========================
  13021. // Trigger message
  13022. //==========================
  13023. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13024. {
  13025. //sendBootNotificationRequest();
  13026. server_sign = FALSE;
  13027. }
  13028. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13029. {
  13030. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13031. }
  13032. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13033. {
  13034. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13035. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13036. {
  13037. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13038. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13039. }
  13040. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13041. }
  13042. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13043. {
  13044. refreshStartTimer(&clientTime.Heartbeat);
  13045. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13046. }
  13047. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13048. {
  13049. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13050. {
  13051. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13052. }
  13053. else
  13054. {
  13055. for(int idx=0;idx< gunTotalNumber;idx++)
  13056. {
  13057. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13058. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13059. }
  13060. }
  13061. }
  13062. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13063. {
  13064. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  13065. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13066. {
  13067. 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\" &");
  13068. }
  13069. }
  13070. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13071. {
  13072. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13073. {
  13074. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13075. }
  13076. else
  13077. {
  13078. for(int idx=0;idx< gunTotalNumber;idx++)
  13079. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13080. }
  13081. }
  13082. return result;
  13083. }
  13084. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13085. {
  13086. mtrace();
  13087. int result = PASS;
  13088. json_object *GetInstalledCertificateIds;
  13089. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13090. GetInstalledCertificateIds = json_tokener_parse(payload);
  13091. if(!is_error(GetInstalledCertificateIds))
  13092. {
  13093. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13094. }
  13095. json_object_put(GetInstalledCertificateIds);
  13096. /*
  13097. * TODO: Return installed certificate process
  13098. */
  13099. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13100. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  13101. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13102. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13103. sendGetInstalledCertificateIdsConfirmation(uuid);
  13104. return result;
  13105. }
  13106. int handleGetLogRequest(char *uuid, char *payload)
  13107. {
  13108. mtrace();
  13109. int result = PASS;
  13110. json_object *GetLog;
  13111. DEBUG_INFO("handleGetLogRequest...\n");
  13112. GetLog = json_tokener_parse(payload);
  13113. if(!is_error(GetLog))
  13114. {
  13115. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13116. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13117. if(json_object_object_get(GetLog, "retries") != NULL)
  13118. {
  13119. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13120. }
  13121. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13122. {
  13123. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13124. }
  13125. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13126. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13127. {
  13128. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13129. }
  13130. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13131. {
  13132. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13133. }
  13134. }
  13135. json_object_put(GetLog);
  13136. /*
  13137. * TODO: Upload log process
  13138. */
  13139. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  13140. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  13141. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  13142. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  13143. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  13144. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  13145. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  13146. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  13147. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  13148. sendGetLogConfirmation(uuid);
  13149. return result;
  13150. }
  13151. int handleInstallCertificateRequest(char *uuid, char *payload)
  13152. {
  13153. mtrace();
  13154. int result = PASS;
  13155. json_object *InstallCertificate;
  13156. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13157. InstallCertificate = json_tokener_parse(payload);
  13158. if(!is_error(InstallCertificate))
  13159. {
  13160. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13161. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13162. /*
  13163. * TODO: Install certificate process
  13164. */
  13165. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  13166. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  13167. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  13168. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  13169. sendInstallCertificateConfirmation(uuid);
  13170. }
  13171. json_object_put(InstallCertificate);
  13172. return result;
  13173. }
  13174. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13175. {
  13176. mtrace();
  13177. int result = PASS;
  13178. json_object *SignedUpdateFirmware;
  13179. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13180. SignedUpdateFirmware = json_tokener_parse(payload);
  13181. if(!is_error(SignedUpdateFirmware))
  13182. {
  13183. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13184. {
  13185. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13186. }
  13187. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13188. {
  13189. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13190. }
  13191. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13192. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13193. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13194. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13195. {
  13196. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13197. }
  13198. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13199. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13200. }
  13201. json_object_put(SignedUpdateFirmware);
  13202. /*
  13203. * TODO: Upgrade firmware process
  13204. */
  13205. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13206. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  13207. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  13208. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  13209. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  13210. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  13211. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  13212. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  13213. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  13214. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  13215. sendInstallCertificateConfirmation(uuid);
  13216. return result;
  13217. }
  13218. int handleUnknownRequest(char *uuid, char *payload)
  13219. {
  13220. mtrace();
  13221. int result = PASS;
  13222. DEBUG_INFO("handleUnknownRequest...\n");
  13223. sendUnknownConfirmation(uuid);
  13224. result = PASS;
  13225. return result;
  13226. }
  13227. //==========================================
  13228. // Handle server response routine
  13229. //==========================================
  13230. void handleAuthorizeResponse(char *payload, int gun_index)
  13231. {
  13232. mtrace();
  13233. char expiryDatestr[30]={0};
  13234. char parentIdTagstr[20]={0};
  13235. char statusstr[20]={0};
  13236. int expiryDateISNULL=FALSE;
  13237. int parentIdTagISNULL=FALSE;
  13238. DEBUG_INFO("handleAuthorizeResponse...\n");
  13239. json_object *Authorize;
  13240. Authorize = json_tokener_parse(payload);
  13241. if(!is_error(Authorize))
  13242. {
  13243. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13244. {
  13245. // Required data
  13246. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13247. // Optional data
  13248. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13249. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13250. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13251. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13252. }
  13253. }
  13254. json_object_put(Authorize);
  13255. if(expiryDateISNULL == FALSE)
  13256. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13257. if(parentIdTagISNULL == FALSE)
  13258. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13259. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  13260. //Update idTag information to authorization cache if supproted
  13261. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13262. {
  13263. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13264. }
  13265. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  13266. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13267. authorizeRetryTimes = 0;
  13268. }
  13269. void handleBootNotificationResponse(char *payload, int gun_index)
  13270. {
  13271. mtrace();
  13272. char statusStr[12]={0};
  13273. char currentTimeStr[30]={0};
  13274. int intervalInt = 0;
  13275. DEBUG_INFO("handleBootNotificationResponse...\n");
  13276. json_object *BootNotification;
  13277. BootNotification = json_tokener_parse(payload);
  13278. if(!is_error(BootNotification))
  13279. {
  13280. // Required data
  13281. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13282. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13283. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13284. }
  13285. json_object_put(BootNotification);
  13286. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13287. BootNotificationInterval = intervalInt;
  13288. //write back to ShmOCPP16Data->BootNotification
  13289. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  13290. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13291. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  13292. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13293. {
  13294. if((intervalInt == 0) || (intervalInt >= 10))
  13295. {
  13296. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13297. HeartBeatWaitTime = intervalInt;
  13298. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13299. }
  13300. server_sign = TRUE;
  13301. server_pending =FALSE;
  13302. }
  13303. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13304. {
  13305. server_pending = TRUE;
  13306. }
  13307. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  13308. srand(time(NULL));
  13309. refreshStartTimer(&clientTime.Heartbeat);
  13310. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13311. SetOcppConnStatus(TRUE);
  13312. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  13313. }
  13314. void handleDataTransferResponse(char *payload, int gun_index)
  13315. {
  13316. json_object *DataTransfer = json_tokener_parse(payload);
  13317. if(!is_error(DataTransfer))
  13318. {
  13319. // Required data
  13320. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13321. // Optional data
  13322. if(json_object_object_get(DataTransfer, "data") != NULL)
  13323. {
  13324. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13325. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13326. if(!is_error(Data))
  13327. {
  13328. if(json_object_object_get(Data, "msgId") != NULL)
  13329. {
  13330. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13331. {
  13332. 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")));
  13333. }
  13334. }
  13335. }
  13336. json_object_put(Data);
  13337. }
  13338. }
  13339. json_object_put(DataTransfer);
  13340. }
  13341. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13342. {
  13343. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13344. //struct json_object *obj;
  13345. // obj = json_tokener_parse(payload);
  13346. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13347. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13348. //No fields are defined.
  13349. }
  13350. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13351. {
  13352. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13353. //struct json_object *obj;
  13354. // obj = json_tokener_parse(payload);
  13355. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13356. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13357. //No fields are defined.
  13358. }
  13359. void handleHeartbeatResponse(char *payload, int gun_index)
  13360. {
  13361. mtrace();
  13362. DEBUG_INFO("handleHeartbeatResponse...\n");
  13363. json_object *Heartbeat;
  13364. Heartbeat = json_tokener_parse(payload);
  13365. if(!is_error(Heartbeat))
  13366. {
  13367. // Required data
  13368. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13369. }
  13370. json_object_put(Heartbeat);
  13371. if(FirstHeartBeat == 0)
  13372. {
  13373. FirstHeartBeat = 1;
  13374. DEBUG_INFO("FirstHeartBeat \n");
  13375. }
  13376. HeartBeatWithNOResponse = 0;
  13377. refreshStartTimer(&clientTime.Heartbeat);
  13378. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  13379. }
  13380. void handleMeterValuesResponse(char *payload, int gun_index)
  13381. {
  13382. mtrace();
  13383. DEBUG_INFO("handleMeterValuesResponse...\n");
  13384. isQueueSendable = 1;
  13385. }
  13386. void handleStartTransactionResponse(char *payload, int gun_index)
  13387. {
  13388. mtrace();
  13389. //int transactionIdInt = 0;
  13390. FILE *outfile;
  13391. char data[100]={0};
  13392. DEBUG_INFO("handleStartTransactionResponse...\n");
  13393. json_object *StartTransaction;
  13394. StartTransaction = json_tokener_parse(payload);
  13395. if(!is_error(StartTransaction))
  13396. {
  13397. // Required data
  13398. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13399. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13400. // Optional data
  13401. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13402. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13403. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13404. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13405. }
  13406. json_object_put(StartTransaction);
  13407. isQueueSendable = 1;
  13408. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13409. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13410. //-----------Start : write to the Queue TransactionId file -----------------//
  13411. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  13412. {}
  13413. else
  13414. {
  13415. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  13416. if(log == NULL)
  13417. {
  13418. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13419. return ;
  13420. }
  13421. else
  13422. {
  13423. fclose(log);
  13424. }
  13425. }
  13426. // open file for writing
  13427. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13428. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  13429. {
  13430. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  13431. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13432. fputs(data, outfile);
  13433. fclose (outfile);
  13434. }
  13435. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13436. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13437. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13438. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  13439. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13440. }
  13441. void handleStatusNotificationResponse(char *payload, int gun_index)
  13442. {
  13443. mtrace();
  13444. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13445. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13446. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13447. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13448. }
  13449. void handleStopTransactionnResponse(char *payload, int gun_index)
  13450. {
  13451. mtrace();
  13452. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13453. json_object *StopTransaction;
  13454. StopTransaction = json_tokener_parse(payload);
  13455. if(!is_error(StopTransaction))
  13456. {
  13457. // Optional data
  13458. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13459. {
  13460. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13461. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13462. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13463. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13464. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13465. }
  13466. }
  13467. json_object_put(StopTransaction);
  13468. isQueueSendable = 1;
  13469. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13470. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13471. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13472. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13473. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13474. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13475. }
  13476. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13477. {
  13478. mtrace();
  13479. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13480. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  13481. }
  13482. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13483. {
  13484. mtrace();
  13485. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13486. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  13487. }
  13488. void handleSignCertificateResponse(char *payload, int gun_index)
  13489. {
  13490. mtrace();
  13491. DEBUG_INFO("handleSignCertificateResponse...\n");
  13492. json_object *SignCertificate;
  13493. SignCertificate = json_tokener_parse(payload);
  13494. if(!is_error(SignCertificate))
  13495. {
  13496. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13497. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  13498. }
  13499. json_object_put(SignCertificate);
  13500. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  13501. }
  13502. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13503. {
  13504. mtrace();
  13505. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13506. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13507. }
  13508. //==========================================
  13509. // Handle Error routine
  13510. //==========================================
  13511. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13512. {
  13513. mtrace();
  13514. #ifdef SystemLogMessage
  13515. DEBUG_INFO("errorCode: %s\n", errorCode);
  13516. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13517. DEBUG_INFO("errorDetails: %s\n", payload);
  13518. #endif
  13519. }
  13520. //===============================================
  13521. // Common routine
  13522. //===============================================
  13523. int initialConfigurationTable(void)
  13524. {
  13525. //clock_t start_t, end_t, total_t;
  13526. FILE *fp;
  13527. FILE *outfile;
  13528. char str[512]={0};
  13529. char sstr[256]={0};
  13530. int c = 0;
  13531. char *loc;
  13532. int confVersion = 13;
  13533. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13534. //start_t = clock();
  13535. //printf("Starting of the program, start_t = %ld\n", start_t);
  13536. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13537. // Check configuration file size is correct
  13538. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  13539. {
  13540. struct stat st;
  13541. stat("/Storage/OCPP/OCPPConfiguration", &st);
  13542. if(st.st_size < 3100)
  13543. {
  13544. system("rm -f /Storage/OCPP/OCPPConfiguration");
  13545. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13546. }
  13547. }
  13548. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  13549. {
  13550. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13551. if(outfile == NULL)
  13552. {
  13553. DEBUG_INFO("Error opening file\n");
  13554. return FALSE;
  13555. }
  13556. /*Core Profile*/
  13557. //AllowOfflineTxForUnknownId
  13558. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13561. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13562. //AuthorizationCacheEnabled
  13563. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13564. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13565. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13566. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13567. //AuthorizeRemoteTxRequests
  13568. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13571. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13572. //BlinkRepeat
  13573. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13576. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13577. //ClockAlignedDataInterval
  13578. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13580. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13581. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13582. //ConnectionTimeOut
  13583. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13586. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13587. //GetConfigurationMaxKeys
  13588. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13590. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13591. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13592. // HeartbeatInterval
  13593. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13596. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13597. // LightIntensity
  13598. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13600. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13601. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13602. // LocalAuthorizeOffline
  13603. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13606. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13607. // LocalPreAuthorize
  13608. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13611. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13612. // MaxEnergyOnInvalidId
  13613. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13616. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13617. // MeterValuesAlignedData
  13618. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13620. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13621. 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" );
  13622. else
  13623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13624. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13625. // MeterValuesAlignedDataMaxLength
  13626. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13628. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13629. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13630. else
  13631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13632. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13633. // MeterValuesSampledData
  13634. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13636. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13637. 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" );
  13638. else
  13639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13640. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13641. // MeterValuesSampledDataMaxLength
  13642. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13644. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13646. else
  13647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13648. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13649. // MeterValueSampleInterval
  13650. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13654. // MinimumStatusDuration
  13655. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13658. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13659. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13660. // NumberOfConnectors
  13661. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13663. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13664. {
  13665. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13666. }
  13667. else
  13668. {
  13669. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13670. }
  13671. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13672. // ResetRetries
  13673. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13676. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13677. // ConnectorPhaseRotation
  13678. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13681. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13682. // ConnectorPhaseRotationMaxLength
  13683. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13686. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13687. // StopTransactionOnEVSideDisconnect
  13688. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13691. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13692. // StopTransactionOnInvalidId
  13693. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13696. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13697. // StopTxnAlignedData
  13698. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13699. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13701. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13702. // StopTxnAlignedDataMaxLength
  13703. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13705. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13706. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13707. // StopTxnSampledData
  13708. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13710. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13712. else
  13713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13714. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13715. // StopTxnSampledDataMaxLength
  13716. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13718. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13719. {
  13720. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13721. }
  13722. else
  13723. {
  13724. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13725. }
  13726. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13727. // SupportedFeatureProfiles
  13728. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13731. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13732. // SupportedFeatureProfilesMaxLength
  13733. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13736. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13737. // TransactionMessageAttempts
  13738. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13741. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13742. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13743. // TransactionMessageRetryInterval
  13744. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13747. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13748. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13749. // UnlockConnectorOnEVSideDisconnect
  13750. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13753. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13754. // WebSocketPingInterval
  13755. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13758. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13759. // QueueOffLineMeterValues
  13760. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13762. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13763. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13764. // AuthorizationKey
  13765. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  13768. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13769. // SecurityProfile
  13770. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13772. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  13773. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13774. // DefaultPrice
  13775. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13776. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13778. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13779. // CustomDisplayCostAndPrice
  13780. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13783. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13784. // CustomIdleFeeAfterStop
  13785. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13788. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13789. // TimeOffset
  13790. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13791. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  13793. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13794. // NextTimeOffsetTransitionDateTime
  13795. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  13798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13799. // TimeOffsetNextTransition
  13800. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  13803. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13804. // SystemUptimeSec
  13805. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13808. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13809. // FreeVend
  13810. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13813. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13814. // FreeVendIdtag
  13815. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  13816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  13817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  13818. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  13819. // OcppServer
  13820. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13822. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13823. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13824. // MaintainServer
  13825. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13826. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13827. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13828. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13829. // StatusNotificationPeriodically
  13830. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13833. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13834. // StatusNotificationInterval
  13835. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13838. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13839. // Configuration Version
  13840. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13842. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13843. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13844. //* Local Auth List Management Profile*/
  13845. #if 0
  13846. //For OCTT Test Case
  13847. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13850. #endif
  13851. #if 1
  13852. //LocalAuthListEnabled
  13853. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13856. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13857. #endif
  13858. //LocalAuthListMaxLength
  13859. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  13862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13863. //SendLocalListMaxLength
  13864. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13867. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13868. //ReserveConnectorZeroSupported
  13869. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13872. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13873. //* Smart Charging Profile */
  13874. //ChargeProfileMaxStackLevel
  13875. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13878. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13879. // ChargingScheduleAllowedChargingRateUnit
  13880. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13883. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13884. // ChargingScheduleMaxPeriods
  13885. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13888. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13889. // ConnectorSwitch3to1PhaseSupported
  13890. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13894. // MaxChargingProfilesInstalled
  13895. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13896. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13898. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13899. fclose(outfile);
  13900. }
  13901. else
  13902. {
  13903. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  13904. char keystr[60]={0};
  13905. char readonlystr[10]={0};
  13906. char valuestr[256]={0};
  13907. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  13908. if(fp == NULL) {
  13909. DEBUG_INFO("Error opening file");
  13910. return FALSE;
  13911. }
  13912. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13913. {
  13914. //DEBUG_INFO("Get Configuration \n");
  13915. if(strlen(str) > 0)
  13916. {
  13917. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13918. //*************************key*********************************/
  13919. if(strstr(str, "key") != NULL)
  13920. {
  13921. loc = strstr(str, "key");
  13922. c = 0;
  13923. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13924. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13925. {
  13926. sstr[c] = loc[strlen("key")+3+c];
  13927. c++;
  13928. }
  13929. sstr[c] = '\0';
  13930. strcpy(keystr,sstr);
  13931. }
  13932. //*************************readonly*********************************/
  13933. if(strstr(str, "readonly") != NULL)
  13934. {
  13935. loc = strstr(str, "readonly");
  13936. c = 0;
  13937. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13938. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13939. {
  13940. sstr[c] = loc[strlen("readonly")+2+c];
  13941. c++;
  13942. }
  13943. sstr[c] = '\0';
  13944. strcpy(readonlystr,sstr);
  13945. }
  13946. //*************************value*********************************/
  13947. if(strstr(str, "value") != NULL)
  13948. {
  13949. loc = strstr(str, "value");
  13950. c = 0;
  13951. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13952. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13953. {
  13954. sstr[c] = loc[strlen("value")+3+c];
  13955. c++;
  13956. }
  13957. sstr[c] = '\0';
  13958. strcpy(valuestr,sstr);
  13959. }
  13960. // DEBUG_INFO("keystr=%s\n",keystr);
  13961. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13962. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13963. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13964. {
  13965. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13966. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13967. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13968. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13969. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13970. }
  13971. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13972. {
  13973. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13974. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13975. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13976. }
  13977. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13978. {
  13979. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13980. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13981. }
  13982. if(strcmp(keystr, "BlinkRepeat") == 0)
  13983. {
  13984. //Charger.BlinkRepeat = Integer.parseInt(value);
  13985. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13986. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13987. }
  13988. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13989. {
  13990. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13991. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13992. }
  13993. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13994. {
  13995. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13996. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13997. }
  13998. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13999. {
  14000. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14001. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14002. }
  14003. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14004. {
  14005. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14006. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14007. HeartBeatWaitTime = atoi(valuestr);
  14008. }
  14009. if(strcmp(keystr, "LightIntensity") == 0)
  14010. {
  14011. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14013. }
  14014. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14015. {
  14016. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14017. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14018. }
  14019. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14020. {
  14021. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14022. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14023. }
  14024. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14025. {
  14026. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14027. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14028. }
  14029. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14030. {
  14031. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14032. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14033. }
  14034. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14035. {
  14036. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14037. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14038. }
  14039. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14040. {
  14041. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14042. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14043. }
  14044. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14045. {
  14046. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14047. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14048. }
  14049. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14050. {
  14051. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14052. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14053. }
  14054. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14055. {
  14056. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14057. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14058. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14059. }
  14060. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14061. {
  14062. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14063. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14064. }
  14065. if(strcmp(keystr, "ResetRetries") == 0)
  14066. {
  14067. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14068. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14069. }
  14070. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14071. {
  14072. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14073. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14074. }
  14075. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14076. {
  14077. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14078. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14079. }
  14080. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14081. {
  14082. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14083. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14084. }
  14085. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14086. {
  14087. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14088. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14089. }
  14090. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14091. {
  14092. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14093. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14094. }
  14095. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14096. {
  14097. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14098. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14099. }
  14100. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14101. {
  14102. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14103. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14104. }
  14105. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14106. {
  14107. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14108. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14109. }
  14110. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14111. {
  14112. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14113. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14114. }
  14115. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14116. {
  14117. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14118. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14119. }
  14120. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14121. {
  14122. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14123. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14124. TransactionMessageAttemptsValue = atoi(valuestr);
  14125. }
  14126. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14127. {
  14128. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14129. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14130. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14131. }
  14132. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14133. {
  14134. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14135. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14136. }
  14137. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14138. {
  14139. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14140. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14141. }
  14142. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14143. {
  14144. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14145. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14146. }
  14147. if(strcmp(keystr, "AuthorizationKey") == 0)
  14148. {
  14149. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14150. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14151. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14152. }
  14153. if(strcmp(keystr, "SecurityProfile") == 0)
  14154. {
  14155. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14156. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14157. }
  14158. if(strcmp(keystr, "DefaultPrice") == 0)
  14159. {
  14160. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14161. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14162. }
  14163. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14164. {
  14165. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14166. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14167. }
  14168. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14169. {
  14170. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14171. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14172. }
  14173. if(strcmp(keystr, "TimeOffset") == 0)
  14174. {
  14175. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14176. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  14177. }
  14178. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  14179. {
  14180. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14181. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  14182. }
  14183. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  14184. {
  14185. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14186. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  14187. }
  14188. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14189. {
  14190. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14191. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  14192. }
  14193. if(strcmp(keystr, "FreeVend") == 0)
  14194. {
  14195. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14196. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14197. }
  14198. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14199. {
  14200. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14201. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14202. }
  14203. if(strcmp(keystr, "OcppServer") == 0)
  14204. {
  14205. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14206. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14207. }
  14208. if(strcmp(keystr, "MaintainServer") == 0)
  14209. {
  14210. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14211. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14212. }
  14213. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14214. {
  14215. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14216. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14217. }
  14218. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14219. {
  14220. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14221. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14222. }
  14223. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14224. {
  14225. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14226. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14227. }
  14228. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14229. {
  14230. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14231. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14232. }
  14233. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14234. {
  14235. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14236. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14237. }
  14238. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14239. {
  14240. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14241. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14242. }
  14243. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14244. {
  14245. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14246. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14247. }
  14248. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14249. {
  14250. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14251. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14252. }
  14253. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14254. {
  14255. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14257. }
  14258. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14259. {
  14260. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14261. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14262. }
  14263. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14264. {
  14265. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14266. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14267. }
  14268. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14269. {
  14270. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14271. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14272. }
  14273. }
  14274. }
  14275. fclose(fp);
  14276. }
  14277. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14278. {
  14279. return PASS;
  14280. }
  14281. else
  14282. {
  14283. return FAIL;
  14284. }
  14285. }
  14286. void StoreConfigurationTable(void)
  14287. {
  14288. FILE *outfile;
  14289. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14290. if(outfile == NULL)
  14291. {
  14292. DEBUG_INFO("Error opening file");
  14293. return ;
  14294. }
  14295. /*Core Profile*/
  14296. //AllowOfflineTxForUnknownId
  14297. /*
  14298. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14299. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14302. */
  14303. //DEBUG_INFO("data=%s\n",data);
  14304. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14305. //AuthorizationCacheEnabled
  14306. /*
  14307. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14308. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14310. */
  14311. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14312. //AuthorizeRemoteTxRequests
  14313. /*
  14314. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14317. */
  14318. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14319. //BlinkRepeat
  14320. /*
  14321. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14324. */
  14325. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14326. //ClockAlignedDataInterval
  14327. /*
  14328. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14331. */
  14332. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14333. //ConnectionTimeOut
  14334. /*
  14335. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14337. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14338. */
  14339. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14340. //GetConfigurationMaxKeys
  14341. /*
  14342. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14345. */
  14346. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14347. // HeartbeatInterval
  14348. /*
  14349. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14351. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14352. */
  14353. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14354. // LightIntensity
  14355. /*
  14356. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14359. */
  14360. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14361. // LocalAuthorizeOffline
  14362. /*
  14363. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14366. */
  14367. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14368. // LocalPreAuthorize
  14369. /*
  14370. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14373. */
  14374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14375. // MaxEnergyOnInvalidId
  14376. /*
  14377. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14380. */
  14381. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14382. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14383. // MeterValuesAlignedData
  14384. /*
  14385. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14388. */
  14389. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14390. // MeterValuesAlignedDataMaxLength
  14391. /*
  14392. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14395. */
  14396. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14397. // MeterValuesSampledData
  14398. /*
  14399. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14402. */
  14403. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14404. // MeterValuesSampledDataMaxLength
  14405. /*
  14406. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14409. */
  14410. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14411. // MeterValueSampleInterval
  14412. /*
  14413. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14416. */
  14417. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14418. // MinimumStatusDuration
  14419. /*
  14420. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14423. */
  14424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14425. // NumberOfConnectors
  14426. /*
  14427. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14428. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14429. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14430. {
  14431. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14432. }
  14433. else
  14434. {
  14435. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14436. }
  14437. */
  14438. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14439. // ResetRetries
  14440. /*
  14441. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14442. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14444. */
  14445. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14446. // ConnectorPhaseRotation
  14447. /*
  14448. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14450. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14451. */
  14452. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14453. // ConnectorPhaseRotationMaxLength
  14454. /*
  14455. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14456. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14457. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14458. */
  14459. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14460. // StopTransactionOnEVSideDisconnect
  14461. /*
  14462. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14463. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14464. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14465. */
  14466. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14467. // StopTransactionOnInvalidId
  14468. /*
  14469. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14470. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14471. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14472. */
  14473. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14474. // StopTxnAlignedData
  14475. /*
  14476. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14477. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14479. */
  14480. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14481. // StopTxnAlignedDataMaxLength
  14482. /*
  14483. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14484. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14485. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14486. */
  14487. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14488. // StopTxnSampledData
  14489. /*
  14490. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14491. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14492. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14493. */
  14494. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14495. // StopTxnSampledDataMaxLength
  14496. /*
  14497. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14498. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14499. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14500. */
  14501. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14502. // SupportedFeatureProfiles
  14503. /*
  14504. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14505. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14506. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14507. */
  14508. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14509. // SupportedFeatureProfilesMaxLength
  14510. /*
  14511. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14512. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14513. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14514. */
  14515. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14516. // TransactionMessageAttempts
  14517. /*
  14518. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14520. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14521. */
  14522. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14523. // TransactionMessageRetryInterval
  14524. /*
  14525. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14528. */
  14529. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14530. // UnlockConnectorOnEVSideDisconnect
  14531. /*
  14532. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14535. */
  14536. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14537. // WebSocketPingInterval
  14538. /*
  14539. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14542. */
  14543. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14544. // QueueOffLineMeterValues
  14545. /*
  14546. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14549. */
  14550. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14551. // AuthorizationKey
  14552. /*
  14553. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14556. */
  14557. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14558. // SecurityProfile
  14559. /*
  14560. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14563. */
  14564. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14565. // DefaultPrice
  14566. /*
  14567. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14570. */
  14571. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14572. // CustomDisplayCostAndPrice
  14573. /*
  14574. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14577. */
  14578. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14579. // CustomIdleFeeAfterStop
  14580. /*
  14581. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14584. */
  14585. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14586. // TimeOffset
  14587. /*
  14588. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  14591. */
  14592. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14593. // NextTimeOffsetTransitionDateTime
  14594. /*
  14595. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  14598. */
  14599. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14600. // TimeOffsetNextTransition
  14601. /*
  14602. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  14605. */
  14606. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14607. // SystemUptimeSec
  14608. /*
  14609. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14612. */
  14613. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14614. // FreeVend
  14615. /*
  14616. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14619. */
  14620. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14621. // FreeVendIdtag
  14622. /*
  14623. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14626. */
  14627. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14628. // OcppServer
  14629. /*
  14630. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14633. */
  14634. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14635. // MaintainServer
  14636. /*
  14637. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14640. */
  14641. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14642. // StatusNotificationPeriodically
  14643. /*
  14644. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14647. */
  14648. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14649. // StatusNotificationInterval
  14650. /*
  14651. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14654. */
  14655. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14656. // ConfigurationVersion
  14657. /*
  14658. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14661. */
  14662. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14663. //* Local Auth List Management Profile*/
  14664. //LocalAuthListEnabled
  14665. /*
  14666. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14669. */
  14670. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14671. //LocalAuthListMaxLength
  14672. /*
  14673. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14676. */
  14677. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14678. //SendLocalListMaxLength
  14679. /*
  14680. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14683. */
  14684. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14685. //ReserveConnectorZeroSupported
  14686. /*
  14687. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14690. */
  14691. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14692. //* Smart Charging Profile */
  14693. //ChargeProfileMaxStackLevel
  14694. /*
  14695. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14698. */
  14699. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14700. // ChargingScheduleAllowedChargingRateUnit
  14701. /*
  14702. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14705. */
  14706. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14707. // ChargingScheduleMaxPeriods
  14708. /*
  14709. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14712. */
  14713. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14714. // ConnectorSwitch3to1PhaseSupported
  14715. /*
  14716. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14719. */
  14720. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14721. // MaxChargingProfilesInstalled
  14722. /*
  14723. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14726. */
  14727. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14728. fclose(outfile);
  14729. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14730. }
  14731. void getKeyValue(char *keyReq)
  14732. {
  14733. int isEmpty = FALSE;
  14734. int isKnowKey = FALSE;
  14735. DEBUG_INFO("keyReq = %s\n", keyReq);
  14736. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14737. isEmpty = TRUE;
  14738. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14739. {
  14740. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14742. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14743. {
  14744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14745. }
  14746. else
  14747. {
  14748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14749. }
  14750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14751. isKnowKey = TRUE;
  14752. }
  14753. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14754. {
  14755. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14757. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14758. {
  14759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14760. }
  14761. else
  14762. {
  14763. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14764. }
  14765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14766. isKnowKey = TRUE;
  14767. }
  14768. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14769. {
  14770. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14772. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14773. {
  14774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14775. }
  14776. else
  14777. {
  14778. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14779. }
  14780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14781. isKnowKey = TRUE;
  14782. }
  14783. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14784. {
  14785. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14787. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14788. {
  14789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14790. }
  14791. else
  14792. {
  14793. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14794. }
  14795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14796. isKnowKey = TRUE;
  14797. }
  14798. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14799. {
  14800. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14802. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14803. {
  14804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14805. }
  14806. else
  14807. {
  14808. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14809. }
  14810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14811. isKnowKey = TRUE;
  14812. }
  14813. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14814. {
  14815. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14817. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14818. {
  14819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14820. }
  14821. else
  14822. {
  14823. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14824. }
  14825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14826. isKnowKey = TRUE;
  14827. }
  14828. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14829. {
  14830. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14832. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14833. {
  14834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14835. }
  14836. else
  14837. {
  14838. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14839. }
  14840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14841. isKnowKey = TRUE;
  14842. }
  14843. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14844. {
  14845. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14847. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14848. {
  14849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14850. }
  14851. else
  14852. {
  14853. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14854. }
  14855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14856. isKnowKey = TRUE;
  14857. }
  14858. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14859. {
  14860. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14861. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14862. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14863. {
  14864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14865. }
  14866. else
  14867. {
  14868. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14869. }
  14870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14871. isKnowKey = TRUE;
  14872. }
  14873. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14874. {
  14875. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14876. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14877. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14878. {
  14879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14880. }
  14881. else
  14882. {
  14883. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14884. }
  14885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14886. isKnowKey = TRUE;
  14887. }
  14888. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14889. {
  14890. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14891. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14892. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14893. {
  14894. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14895. }
  14896. else
  14897. {
  14898. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14899. }
  14900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14901. isKnowKey = TRUE;
  14902. }
  14903. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14904. {
  14905. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14907. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14908. {
  14909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14910. }
  14911. else
  14912. {
  14913. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14914. }
  14915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14916. isKnowKey = TRUE;
  14917. }
  14918. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14919. {
  14920. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14922. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14923. {
  14924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14925. }
  14926. else
  14927. {
  14928. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14929. }
  14930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14931. isKnowKey = TRUE;
  14932. }
  14933. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14934. {
  14935. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14937. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14938. {
  14939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14940. }
  14941. else
  14942. {
  14943. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14944. }
  14945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14946. isKnowKey = TRUE;
  14947. }
  14948. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14949. {
  14950. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14952. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14953. {
  14954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14955. }
  14956. else
  14957. {
  14958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14959. }
  14960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14961. isKnowKey = TRUE;
  14962. }
  14963. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14964. {
  14965. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14967. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14968. {
  14969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14970. }
  14971. else
  14972. {
  14973. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14974. }
  14975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14976. isKnowKey = TRUE;
  14977. }
  14978. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14979. {
  14980. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14982. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14983. {
  14984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14985. }
  14986. else
  14987. {
  14988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14989. }
  14990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14991. isKnowKey = TRUE;
  14992. }
  14993. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14994. {
  14995. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14997. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14998. {
  14999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15000. }
  15001. else
  15002. {
  15003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15004. }
  15005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  15006. isKnowKey = TRUE;
  15007. }
  15008. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15009. {
  15010. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15012. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15013. {
  15014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15015. }
  15016. else
  15017. {
  15018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15019. }
  15020. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15022. isKnowKey = TRUE;
  15023. }
  15024. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15025. {
  15026. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15028. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15029. {
  15030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15031. }
  15032. else
  15033. {
  15034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15035. }
  15036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15037. isKnowKey = TRUE;
  15038. }
  15039. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15040. {
  15041. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15043. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15044. {
  15045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15046. }
  15047. else
  15048. {
  15049. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15050. }
  15051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15052. isKnowKey = TRUE;
  15053. }
  15054. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15055. {
  15056. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15058. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15059. {
  15060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15061. }
  15062. else
  15063. {
  15064. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15065. }
  15066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15067. isKnowKey = TRUE;
  15068. }
  15069. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15070. {
  15071. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15073. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15074. {
  15075. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15076. }
  15077. else
  15078. {
  15079. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15080. }
  15081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15082. isKnowKey = TRUE;
  15083. }
  15084. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15085. {
  15086. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15088. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15089. {
  15090. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15091. }
  15092. else
  15093. {
  15094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15095. }
  15096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15097. isKnowKey = TRUE;
  15098. }
  15099. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15100. {
  15101. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15103. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15104. {
  15105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15106. }
  15107. else
  15108. {
  15109. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15110. }
  15111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15112. isKnowKey = TRUE;
  15113. }
  15114. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15115. {
  15116. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15118. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15119. {
  15120. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15121. }
  15122. else
  15123. {
  15124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15125. }
  15126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15127. isKnowKey = TRUE;
  15128. }
  15129. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15130. {
  15131. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15133. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15134. {
  15135. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15136. }
  15137. else
  15138. {
  15139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15140. }
  15141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15142. isKnowKey = TRUE;
  15143. }
  15144. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15145. {
  15146. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15148. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15149. {
  15150. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15151. }
  15152. else
  15153. {
  15154. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15155. }
  15156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15157. isKnowKey = TRUE;
  15158. }
  15159. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15160. {
  15161. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15163. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15164. {
  15165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15166. }
  15167. else
  15168. {
  15169. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15170. }
  15171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15172. isKnowKey = TRUE;
  15173. }
  15174. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15175. {
  15176. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15178. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15179. {
  15180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15181. }
  15182. else
  15183. {
  15184. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15185. }
  15186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15187. isKnowKey = TRUE;
  15188. }
  15189. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15190. {
  15191. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15193. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15194. {
  15195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15196. }
  15197. else
  15198. {
  15199. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15200. }
  15201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15202. isKnowKey = TRUE;
  15203. }
  15204. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15205. {
  15206. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15208. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15209. {
  15210. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15211. }
  15212. else
  15213. {
  15214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15215. }
  15216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15217. isKnowKey = TRUE;
  15218. }
  15219. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15220. {
  15221. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15223. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15224. {
  15225. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15226. }
  15227. else
  15228. {
  15229. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15230. }
  15231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15232. isKnowKey = TRUE;
  15233. }
  15234. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15235. {
  15236. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15238. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15239. {
  15240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15241. }
  15242. else
  15243. {
  15244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15245. }
  15246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15247. isKnowKey = TRUE;
  15248. }
  15249. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15250. {
  15251. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15253. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15254. {
  15255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15256. }
  15257. else
  15258. {
  15259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15260. }
  15261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15262. isKnowKey = TRUE;
  15263. }
  15264. /*
  15265. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15266. {
  15267. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15269. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15270. {
  15271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15272. }
  15273. else
  15274. {
  15275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15276. }
  15277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15278. isKnowKey = TRUE;
  15279. }*/
  15280. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15281. {
  15282. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15284. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15285. {
  15286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15287. }
  15288. else
  15289. {
  15290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15291. }
  15292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15293. isKnowKey = TRUE;
  15294. }
  15295. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15296. {
  15297. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15299. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15300. {
  15301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15302. }
  15303. else
  15304. {
  15305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15306. }
  15307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15308. isKnowKey = TRUE;
  15309. }
  15310. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15311. {
  15312. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15314. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15315. {
  15316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15317. }
  15318. else
  15319. {
  15320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15321. }
  15322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15323. isKnowKey = TRUE;
  15324. }
  15325. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15326. {
  15327. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15329. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15330. {
  15331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15332. }
  15333. else
  15334. {
  15335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15336. }
  15337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15338. isKnowKey = TRUE;
  15339. }
  15340. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  15341. {
  15342. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  15343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  15344. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15345. {
  15346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  15347. }
  15348. else
  15349. {
  15350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  15351. }
  15352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  15353. isKnowKey = TRUE;
  15354. }
  15355. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  15356. {
  15357. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  15358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  15359. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15360. {
  15361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  15362. }
  15363. else
  15364. {
  15365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  15366. }
  15367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  15368. isKnowKey = TRUE;
  15369. }
  15370. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  15371. {
  15372. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  15373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  15374. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15375. {
  15376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  15377. }
  15378. else
  15379. {
  15380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  15381. }
  15382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  15383. isKnowKey = TRUE;
  15384. }
  15385. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15386. {
  15387. struct sysinfo s_info;
  15388. int error = sysinfo(&s_info);
  15389. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15391. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15392. {
  15393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15394. }
  15395. else
  15396. {
  15397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15398. }
  15399. if(error != 0)
  15400. {
  15401. DEBUG_WARN("System uptime get error: %d\n", error);
  15402. }
  15403. else
  15404. {
  15405. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15406. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15407. }
  15408. isKnowKey = TRUE;
  15409. }
  15410. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15411. {
  15412. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15414. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15415. {
  15416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15417. }
  15418. else
  15419. {
  15420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15421. }
  15422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  15423. isKnowKey = TRUE;
  15424. }
  15425. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15426. {
  15427. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15429. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15430. {
  15431. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15432. }
  15433. else
  15434. {
  15435. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15436. }
  15437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15438. isKnowKey = TRUE;
  15439. }
  15440. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15441. {
  15442. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15444. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15445. {
  15446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15447. }
  15448. else
  15449. {
  15450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15451. }
  15452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15453. isKnowKey = TRUE;
  15454. }
  15455. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15456. {
  15457. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15459. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15460. {
  15461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15462. }
  15463. else
  15464. {
  15465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15466. }
  15467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15468. isKnowKey = TRUE;
  15469. }
  15470. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15471. {
  15472. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15474. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15475. {
  15476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15477. }
  15478. else
  15479. {
  15480. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15481. }
  15482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15483. isKnowKey = TRUE;
  15484. }
  15485. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15486. {
  15487. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15489. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15490. {
  15491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15492. }
  15493. else
  15494. {
  15495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15496. }
  15497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15498. isKnowKey = TRUE;
  15499. }
  15500. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15501. {
  15502. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15504. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15505. {
  15506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15507. }
  15508. else
  15509. {
  15510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15511. }
  15512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15513. isKnowKey = TRUE;
  15514. }
  15515. #if 1
  15516. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15517. {
  15518. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15520. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15521. {
  15522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15523. }
  15524. else
  15525. {
  15526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15527. }
  15528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15529. isKnowKey = TRUE;
  15530. }
  15531. #endif
  15532. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15533. {
  15534. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15536. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15537. {
  15538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15539. }
  15540. else
  15541. {
  15542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15543. }
  15544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15545. isKnowKey = TRUE;
  15546. }
  15547. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15548. {
  15549. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15551. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15552. {
  15553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15554. }
  15555. else
  15556. {
  15557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15558. }
  15559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15560. isKnowKey = TRUE;
  15561. }
  15562. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15563. {
  15564. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15566. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15567. {
  15568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15569. }
  15570. else
  15571. {
  15572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15573. }
  15574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15575. isKnowKey = TRUE;
  15576. }
  15577. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15578. {
  15579. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15581. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15582. {
  15583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15584. }
  15585. else
  15586. {
  15587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15588. }
  15589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15590. isKnowKey = TRUE;
  15591. }
  15592. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15593. {
  15594. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15596. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15597. {
  15598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15599. }
  15600. else
  15601. {
  15602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15603. }
  15604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15605. isKnowKey = TRUE;
  15606. }
  15607. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15608. {
  15609. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15611. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15612. {
  15613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15614. }
  15615. else
  15616. {
  15617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15618. }
  15619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15620. isKnowKey = TRUE;
  15621. }
  15622. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15623. {
  15624. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15626. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15627. {
  15628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15629. }
  15630. else
  15631. {
  15632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15633. }
  15634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15635. isKnowKey = TRUE;
  15636. }
  15637. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15638. {
  15639. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15641. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15642. {
  15643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15644. }
  15645. else
  15646. {
  15647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15648. }
  15649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15650. isKnowKey = TRUE;
  15651. }
  15652. //=========================================================
  15653. if(!isEmpty && !isKnowKey)
  15654. {
  15655. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15656. strcpy(unknownkey[UnknownKeynum], keyReq);
  15657. UnknownKeynum = UnknownKeynum + 1;
  15658. }
  15659. }
  15660. void processUnkownKey(void)
  15661. {
  15662. DEBUG_INFO("processUnkownKey...\n");
  15663. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15664. for(int index=0; index < UnknownKeynum; index++)
  15665. {
  15666. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15667. {
  15668. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15669. }
  15670. }
  15671. }
  15672. int setKeyValue(char *key, char *value)
  15673. {
  15674. int isSuccess = NotSupported;
  15675. int check_ascii=0;
  15676. char str[501]={0};
  15677. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15678. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15679. {
  15680. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15681. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15682. {
  15683. strcpy(str, (const char*)value);
  15684. for(int i = 0; str[i]; i++){
  15685. str[i] = tolower(str[i]);
  15686. }
  15687. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15688. isSuccess = ConfigurationStatus_Accepted;
  15689. }
  15690. else
  15691. {
  15692. isSuccess = ConfigurationStatus_Rejected;
  15693. }
  15694. }
  15695. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15696. {
  15697. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15698. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15699. {
  15700. strcpy(str, (const char*)value);
  15701. for(int i = 0; str[i]; i++){
  15702. str[i] = tolower(str[i]);
  15703. }
  15704. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15705. isSuccess = ConfigurationStatus_Accepted;
  15706. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  15707. }
  15708. else
  15709. {
  15710. isSuccess = ConfigurationStatus_Rejected;
  15711. }
  15712. }
  15713. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15714. {
  15715. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15716. {
  15717. strcpy(str, (const char*)value);
  15718. for(int i = 0; str[i]; i++)
  15719. {
  15720. str[i] = tolower(str[i]);
  15721. }
  15722. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15723. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15724. isSuccess = ConfigurationStatus_Accepted;
  15725. }
  15726. else
  15727. {
  15728. isSuccess = ConfigurationStatus_Rejected;
  15729. }
  15730. }
  15731. if(strcmp(key, "BlinkRepeat") == 0)
  15732. {
  15733. //Charger.BlinkRepeat = Integer.parseInt(value);
  15734. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15735. {
  15736. check_ascii = value[0];
  15737. if( (check_ascii < 48) || (check_ascii > 57) )
  15738. {
  15739. isSuccess = ConfigurationStatus_Rejected;
  15740. }
  15741. else
  15742. {
  15743. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15744. isSuccess = ConfigurationStatus_Accepted;
  15745. }
  15746. }
  15747. else
  15748. {
  15749. isSuccess = ConfigurationStatus_Rejected;
  15750. }
  15751. }
  15752. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15753. {
  15754. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15755. {
  15756. check_ascii = value[0];
  15757. if( (check_ascii < 48) || (check_ascii > 57) )
  15758. {
  15759. isSuccess = ConfigurationStatus_Rejected;
  15760. }
  15761. else
  15762. {
  15763. if((atoi(value) == 0) || (atoi(value) >= 5))
  15764. {
  15765. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15766. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15767. isSuccess = ConfigurationStatus_Accepted;
  15768. }
  15769. else
  15770. isSuccess = ConfigurationStatus_Rejected;
  15771. }
  15772. }
  15773. else
  15774. {
  15775. isSuccess = ConfigurationStatus_Rejected;
  15776. }
  15777. }
  15778. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15779. {
  15780. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15781. {
  15782. check_ascii = value[0];
  15783. if( (check_ascii < 48) || (check_ascii > 57) )
  15784. {
  15785. isSuccess = ConfigurationStatus_Rejected;
  15786. }
  15787. else
  15788. {
  15789. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15790. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15791. isSuccess = ConfigurationStatus_Accepted;
  15792. }
  15793. }
  15794. else
  15795. {
  15796. isSuccess = ConfigurationStatus_Rejected;
  15797. }
  15798. }
  15799. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15800. {
  15801. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15802. {
  15803. check_ascii = value[0];
  15804. if( (check_ascii < 48) || (check_ascii > 57) )
  15805. {
  15806. isSuccess = ConfigurationStatus_Rejected;
  15807. }
  15808. else
  15809. {
  15810. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15811. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15812. isSuccess = ConfigurationStatus_Accepted;
  15813. }
  15814. }
  15815. else
  15816. {
  15817. isSuccess = ConfigurationStatus_Rejected;
  15818. }
  15819. }
  15820. if(strcmp(key, "HeartbeatInterval") == 0)
  15821. {
  15822. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15823. {
  15824. check_ascii = value[0];
  15825. if( (check_ascii < 48) || (check_ascii > 57) )
  15826. {
  15827. isSuccess = ConfigurationStatus_Rejected;
  15828. }
  15829. else
  15830. {
  15831. if((atoi(value) == 0) || (atoi(value) >= 10))
  15832. {
  15833. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15834. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15835. HeartBeatWaitTime = atoi(value);
  15836. isSuccess = ConfigurationStatus_Accepted;
  15837. }
  15838. else
  15839. {
  15840. isSuccess = ConfigurationStatus_Rejected;
  15841. }
  15842. }
  15843. }
  15844. else
  15845. {
  15846. isSuccess = ConfigurationStatus_Rejected;
  15847. }
  15848. }
  15849. if(strcmp(key, "LightIntensity") == 0)
  15850. {
  15851. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15852. {
  15853. check_ascii = value[0];
  15854. if( (check_ascii < 48) || (check_ascii > 57) )
  15855. {
  15856. isSuccess = ConfigurationStatus_Rejected;
  15857. }
  15858. else
  15859. {
  15860. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15861. isSuccess = ConfigurationStatus_Accepted;
  15862. }
  15863. }
  15864. else
  15865. {
  15866. isSuccess = ConfigurationStatus_Rejected;
  15867. }
  15868. }
  15869. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15870. {
  15871. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15872. {
  15873. strcpy(str, (const char*)value);
  15874. for(int i = 0; str[i]; i++)
  15875. {
  15876. str[i] = tolower(str[i]);
  15877. }
  15878. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15879. isSuccess = ConfigurationStatus_Accepted;
  15880. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15881. }
  15882. else
  15883. {
  15884. isSuccess = ConfigurationStatus_Rejected;
  15885. }
  15886. }
  15887. if(strcmp(key, "LocalPreAuthorize") == 0)
  15888. {
  15889. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15890. {
  15891. strcpy(str, (const char*)value);
  15892. for(int i = 0; str[i]; i++)
  15893. {
  15894. str[i] = tolower(str[i]);
  15895. }
  15896. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15897. isSuccess = ConfigurationStatus_Accepted;
  15898. }
  15899. else
  15900. {
  15901. isSuccess = ConfigurationStatus_Rejected;
  15902. }
  15903. }
  15904. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15905. {
  15906. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15907. {
  15908. check_ascii = value[0];
  15909. if( (check_ascii < 48) || (check_ascii > 57) )
  15910. {
  15911. isSuccess = ConfigurationStatus_Rejected;
  15912. }
  15913. else
  15914. {
  15915. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15916. isSuccess = ConfigurationStatus_Accepted;
  15917. }
  15918. }
  15919. else
  15920. {
  15921. isSuccess = ConfigurationStatus_Rejected;
  15922. }
  15923. }
  15924. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15925. {
  15926. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15927. {
  15928. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15929. isSuccess = ConfigurationStatus_Accepted;
  15930. }
  15931. else
  15932. {
  15933. isSuccess = ConfigurationStatus_Rejected;
  15934. }
  15935. }
  15936. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15937. {
  15938. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15939. {
  15940. check_ascii = value[0];
  15941. if( (check_ascii < 48) || (check_ascii > 57) )
  15942. {
  15943. isSuccess = ConfigurationStatus_Rejected;
  15944. }
  15945. else
  15946. {
  15947. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15948. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15949. isSuccess = ConfigurationStatus_Accepted;
  15950. }
  15951. }
  15952. else
  15953. {
  15954. isSuccess = ConfigurationStatus_Rejected;
  15955. }
  15956. }
  15957. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15958. {
  15959. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15960. {
  15961. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15962. isSuccess = ConfigurationStatus_Accepted;
  15963. }
  15964. else
  15965. {
  15966. isSuccess = ConfigurationStatus_Rejected;
  15967. }
  15968. }
  15969. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15970. {
  15971. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15972. {
  15973. check_ascii = value[0];
  15974. if( (check_ascii < 48) || (check_ascii > 57) )
  15975. {
  15976. isSuccess = ConfigurationStatus_Rejected;
  15977. }
  15978. else
  15979. {
  15980. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15981. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15982. isSuccess = ConfigurationStatus_Accepted;
  15983. }
  15984. }
  15985. else
  15986. {
  15987. isSuccess = ConfigurationStatus_Rejected;
  15988. }
  15989. }
  15990. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15991. {
  15992. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15993. {
  15994. check_ascii = value[0];
  15995. if( (check_ascii < 48) || (check_ascii > 57) )
  15996. {
  15997. isSuccess = ConfigurationStatus_Rejected;
  15998. }
  15999. else
  16000. {
  16001. if((atoi(value) == 0) || (atoi(value) >= 3))
  16002. {
  16003. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16004. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16005. isSuccess = ConfigurationStatus_Accepted;
  16006. }
  16007. else
  16008. {
  16009. isSuccess = ConfigurationStatus_Rejected;
  16010. }
  16011. }
  16012. }
  16013. else
  16014. {
  16015. isSuccess = ConfigurationStatus_Rejected;
  16016. }
  16017. }
  16018. if(strcmp(key, "MinimumStatusDuration") == 0)
  16019. {
  16020. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16021. {
  16022. check_ascii = value[0];
  16023. if( (check_ascii < 48) || (check_ascii > 57) )
  16024. {
  16025. isSuccess = ConfigurationStatus_Rejected;
  16026. }
  16027. else
  16028. {
  16029. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16030. {
  16031. isSuccess = ConfigurationStatus_Rejected;
  16032. }
  16033. else
  16034. {
  16035. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16036. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16037. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16038. isSuccess = ConfigurationStatus_Accepted;
  16039. }
  16040. }
  16041. }
  16042. else
  16043. {
  16044. isSuccess = ConfigurationStatus_Rejected;
  16045. }
  16046. }
  16047. if(strcmp(key, "NumberOfConnectors") == 0)
  16048. {
  16049. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16050. {
  16051. check_ascii = value[0];
  16052. if( (check_ascii < 48) || (check_ascii > 57) )
  16053. {
  16054. isSuccess = ConfigurationStatus_Rejected;
  16055. }
  16056. else
  16057. {
  16058. //Charger.ResetRetries = Integer.parseInt(value);
  16059. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16060. isSuccess = ConfigurationStatus_Accepted;
  16061. }
  16062. }
  16063. else
  16064. {
  16065. isSuccess = ConfigurationStatus_Rejected;
  16066. }
  16067. }
  16068. if(strcmp(key, "ResetRetries") == 0)
  16069. {
  16070. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16071. {
  16072. check_ascii = value[0];
  16073. if( (check_ascii < 48) || (check_ascii > 57) )
  16074. {
  16075. isSuccess = ConfigurationStatus_Rejected;
  16076. }
  16077. else
  16078. {
  16079. //Charger.ResetRetries = Integer.parseInt(value);
  16080. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16081. isSuccess = ConfigurationStatus_Accepted;
  16082. }
  16083. }
  16084. else
  16085. {
  16086. isSuccess = ConfigurationStatus_Rejected;
  16087. }
  16088. }
  16089. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16090. {
  16091. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16092. {
  16093. strcpy(str, (const char*)value);
  16094. for(int i = 0; str[i]; i++)
  16095. {
  16096. str[i] = tolower(str[i]);
  16097. }
  16098. if(strcmp(str, "notapplicable")== 0)
  16099. {
  16100. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16101. isSuccess = ConfigurationStatus_Accepted;
  16102. }
  16103. else if(strcmp(str, "unknown")== 0)
  16104. {
  16105. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16106. isSuccess = ConfigurationStatus_Accepted;
  16107. }
  16108. else if(strcmp(str, "rst")== 0)
  16109. {
  16110. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16111. isSuccess = ConfigurationStatus_Accepted;
  16112. }
  16113. else if(strcmp(str, "rts")== 0)
  16114. {
  16115. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16116. isSuccess = ConfigurationStatus_Accepted;
  16117. }
  16118. else if(strcmp(str, "srt")== 0)
  16119. {
  16120. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16121. isSuccess = ConfigurationStatus_Accepted;
  16122. }
  16123. else if(strcmp(str, "str")== 0)
  16124. {
  16125. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16126. isSuccess = ConfigurationStatus_Accepted;
  16127. }
  16128. else if(strcmp(str, "trs")== 0)
  16129. {
  16130. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16131. isSuccess = ConfigurationStatus_Accepted;
  16132. }
  16133. else if(strcmp(str, "tsr")== 0)
  16134. {
  16135. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16136. isSuccess = ConfigurationStatus_Accepted;
  16137. }
  16138. else
  16139. {
  16140. isSuccess = ConfigurationStatus_Rejected;
  16141. }
  16142. }
  16143. else
  16144. {
  16145. isSuccess = ConfigurationStatus_Rejected;
  16146. }
  16147. }
  16148. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16149. {
  16150. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16151. {
  16152. check_ascii = value[0];
  16153. if( (check_ascii < 48) || (check_ascii > 57) )
  16154. {
  16155. isSuccess = ConfigurationStatus_Rejected;
  16156. }
  16157. else
  16158. {
  16159. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16160. isSuccess = ConfigurationStatus_Accepted;
  16161. }
  16162. }
  16163. else
  16164. {
  16165. isSuccess = ConfigurationStatus_Rejected;
  16166. }
  16167. }
  16168. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16169. {
  16170. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16171. {
  16172. strcpy(str, (const char*)value);
  16173. for(int i = 0; str[i]; i++)
  16174. {
  16175. str[i] = tolower(str[i]);
  16176. }
  16177. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16178. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16179. isSuccess = ConfigurationStatus_Accepted;
  16180. }
  16181. else
  16182. {
  16183. isSuccess = ConfigurationStatus_Rejected;
  16184. }
  16185. }
  16186. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16187. {
  16188. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16189. {
  16190. strcpy(str, (const char*)value);
  16191. for(int i = 0; str[i]; i++)
  16192. {
  16193. str[i] = tolower(str[i]);
  16194. }
  16195. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16196. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16197. isSuccess = ConfigurationStatus_Accepted;
  16198. }
  16199. else
  16200. {
  16201. isSuccess = ConfigurationStatus_Rejected;
  16202. }
  16203. }
  16204. if(strcmp(key, "StopTxnAlignedData") == 0)
  16205. {
  16206. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16207. {
  16208. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16209. isSuccess = ConfigurationStatus_Accepted;
  16210. }
  16211. else
  16212. {
  16213. isSuccess = ConfigurationStatus_Rejected;
  16214. }
  16215. }
  16216. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16217. {
  16218. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16219. {
  16220. check_ascii = value[0];
  16221. if( (check_ascii < 48) || (check_ascii > 57) )
  16222. {
  16223. isSuccess = ConfigurationStatus_Rejected;
  16224. }
  16225. else
  16226. {
  16227. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16228. isSuccess = ConfigurationStatus_Accepted;
  16229. }
  16230. }
  16231. else
  16232. {
  16233. isSuccess = ConfigurationStatus_Rejected;
  16234. }
  16235. }
  16236. if(strcmp(key, "StopTxnSampledData") == 0)
  16237. {
  16238. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16239. {
  16240. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16241. isSuccess = ConfigurationStatus_Accepted;
  16242. }
  16243. else
  16244. {
  16245. isSuccess = ConfigurationStatus_Rejected;
  16246. }
  16247. }
  16248. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16249. {
  16250. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16251. {
  16252. check_ascii = value[0];
  16253. if( (check_ascii < 48) || (check_ascii > 57) )
  16254. {
  16255. isSuccess = ConfigurationStatus_Rejected;
  16256. }
  16257. else
  16258. {
  16259. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16260. isSuccess = ConfigurationStatus_Accepted;
  16261. }
  16262. }
  16263. else
  16264. {
  16265. isSuccess = ConfigurationStatus_Rejected;
  16266. }
  16267. }
  16268. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16269. {
  16270. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16271. {
  16272. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16273. isSuccess = ConfigurationStatus_Accepted;
  16274. }
  16275. else
  16276. {
  16277. isSuccess = ConfigurationStatus_Rejected;
  16278. }
  16279. }
  16280. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16281. {
  16282. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16283. {
  16284. check_ascii = value[0];
  16285. if( (check_ascii < 48) || (check_ascii > 57) )
  16286. {
  16287. isSuccess = ConfigurationStatus_Rejected;
  16288. }
  16289. else
  16290. {
  16291. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16292. isSuccess = ConfigurationStatus_Accepted;
  16293. }
  16294. }
  16295. else
  16296. {
  16297. isSuccess = ConfigurationStatus_Rejected;
  16298. }
  16299. }
  16300. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16301. {
  16302. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16303. {
  16304. check_ascii = value[0];
  16305. if( (check_ascii < 48) || (check_ascii > 57) )
  16306. {
  16307. isSuccess = ConfigurationStatus_Rejected;
  16308. }
  16309. else
  16310. {
  16311. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16312. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16313. TransactionMessageAttemptsValue = atoi(value);
  16314. isSuccess = ConfigurationStatus_Accepted;
  16315. }
  16316. }
  16317. else
  16318. {
  16319. isSuccess = ConfigurationStatus_Rejected;
  16320. }
  16321. }
  16322. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16323. {
  16324. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16325. {
  16326. check_ascii = value[0];
  16327. if( (check_ascii < 48) || (check_ascii > 57) )
  16328. {
  16329. isSuccess = ConfigurationStatus_Rejected;
  16330. }
  16331. else
  16332. {
  16333. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16334. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16335. TransactionMessageRetryIntervalValue = atoi(value);
  16336. isSuccess = ConfigurationStatus_Accepted;
  16337. }
  16338. }
  16339. else
  16340. {
  16341. isSuccess = ConfigurationStatus_Rejected;
  16342. }
  16343. }
  16344. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16345. {
  16346. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16347. {
  16348. strcpy(str, (const char*)value);
  16349. for(int i = 0; str[i]; i++)
  16350. {
  16351. str[i] = tolower(str[i]);
  16352. }
  16353. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16354. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16355. isSuccess = ConfigurationStatus_Accepted;
  16356. }
  16357. else
  16358. {
  16359. isSuccess = ConfigurationStatus_Rejected;
  16360. }
  16361. }
  16362. if(strcmp(key, "WebSocketPingInterval") == 0)
  16363. {
  16364. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16365. {
  16366. check_ascii = value[0];
  16367. if( (check_ascii < 48) || (check_ascii > 57) )
  16368. {
  16369. isSuccess = ConfigurationStatus_Rejected;
  16370. }
  16371. else
  16372. {
  16373. if((atoi(value) == 0) || (atoi(value) >= 10))
  16374. {
  16375. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16376. isSuccess = ConfigurationStatus_Accepted;
  16377. }
  16378. else
  16379. isSuccess = ConfigurationStatus_Rejected;
  16380. }
  16381. }
  16382. else
  16383. {
  16384. isSuccess = ConfigurationStatus_Rejected;
  16385. }
  16386. }
  16387. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16388. {
  16389. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16390. {
  16391. strcpy(str, (const char*)value);
  16392. for(int i = 0; str[i]; i++)
  16393. {
  16394. str[i] = tolower(str[i]);
  16395. }
  16396. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16397. isSuccess = ConfigurationStatus_Accepted;
  16398. }
  16399. else
  16400. {
  16401. isSuccess = ConfigurationStatus_Rejected;
  16402. }
  16403. }
  16404. if(strcmp(key, "AuthorizationKey") == 0)
  16405. {
  16406. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16407. {
  16408. strcpy(str, (const char*)value);
  16409. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16410. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16411. isSuccess = ConfigurationStatus_Accepted;
  16412. }
  16413. else
  16414. {
  16415. isSuccess = ConfigurationStatus_Rejected;
  16416. }
  16417. }
  16418. if(strcmp(key, "SecurityProfile") == 0)
  16419. {
  16420. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16421. {
  16422. check_ascii = value[0];
  16423. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16424. {
  16425. isSuccess = ConfigurationStatus_Rejected;
  16426. }
  16427. else if(check_ascii == 0x33)
  16428. {
  16429. isSuccess = NotSupported;
  16430. }
  16431. else
  16432. {
  16433. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16434. {
  16435. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16436. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  16437. isSuccess = ConfigurationStatus_Accepted;
  16438. }
  16439. else
  16440. isSuccess = ConfigurationStatus_Rejected;
  16441. }
  16442. }
  16443. else
  16444. {
  16445. isSuccess = ConfigurationStatus_Rejected;
  16446. }
  16447. }
  16448. if(strcmp(key, "DefaultPrice") == 0)
  16449. {
  16450. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16451. {
  16452. strcpy(str, (const char*)value);
  16453. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16454. isSuccess = ConfigurationStatus_Accepted;
  16455. }
  16456. else
  16457. {
  16458. isSuccess = ConfigurationStatus_Rejected;
  16459. }
  16460. }
  16461. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16462. {
  16463. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16464. {
  16465. strcpy(str, (const char*)value);
  16466. for(int i = 0; str[i]; i++)
  16467. {
  16468. str[i] = tolower(str[i]);
  16469. }
  16470. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16471. isSuccess = ConfigurationStatus_Accepted;
  16472. }
  16473. else
  16474. {
  16475. isSuccess = ConfigurationStatus_Rejected;
  16476. }
  16477. }
  16478. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16479. {
  16480. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16481. {
  16482. strcpy(str, (const char*)value);
  16483. for(int i = 0; str[i]; i++)
  16484. {
  16485. str[i] = tolower(str[i]);
  16486. }
  16487. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16488. isSuccess = ConfigurationStatus_Accepted;
  16489. }
  16490. else
  16491. {
  16492. isSuccess = ConfigurationStatus_Rejected;
  16493. }
  16494. }
  16495. if(strcmp(key, "TimeOffset") == 0)
  16496. {
  16497. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16498. {
  16499. strcpy(str, (const char*)value);
  16500. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  16501. isSuccess = ConfigurationStatus_Accepted;
  16502. }
  16503. else
  16504. {
  16505. isSuccess = ConfigurationStatus_Rejected;
  16506. }
  16507. }
  16508. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  16509. {
  16510. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  16511. {
  16512. strcpy(str, (const char*)value);
  16513. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  16514. isSuccess = ConfigurationStatus_Accepted;
  16515. }
  16516. else
  16517. {
  16518. isSuccess = ConfigurationStatus_Rejected;
  16519. }
  16520. }
  16521. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  16522. {
  16523. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  16524. {
  16525. strcpy(str, (const char*)value);
  16526. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  16527. isSuccess = ConfigurationStatus_Accepted;
  16528. }
  16529. else
  16530. {
  16531. isSuccess = ConfigurationStatus_Rejected;
  16532. }
  16533. }
  16534. if(strcmp(key, "SystemUptimeSec") == 0)
  16535. {
  16536. isSuccess = NotSupported;
  16537. }
  16538. if(strcmp(key, "FreeVend") == 0)
  16539. {
  16540. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16541. {
  16542. strcpy(str, (const char*)value);
  16543. for(int i = 0; str[i]; i++)
  16544. {
  16545. str[i] = tolower(str[i]);
  16546. }
  16547. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16548. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16549. isSuccess = ConfigurationStatus_Accepted;
  16550. }
  16551. else
  16552. {
  16553. isSuccess = ConfigurationStatus_Rejected;
  16554. }
  16555. }
  16556. if(strcmp(key, "FreeVendIdtag") == 0)
  16557. {
  16558. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16559. {
  16560. strcpy(str, (const char*)value);
  16561. if(strlen(str) <= 20)
  16562. {
  16563. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  16564. isSuccess = ConfigurationStatus_Accepted;
  16565. }
  16566. else
  16567. {
  16568. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  16569. isSuccess = ConfigurationStatus_Rejected;
  16570. }
  16571. }
  16572. else
  16573. {
  16574. isSuccess = ConfigurationStatus_Rejected;
  16575. }
  16576. }
  16577. if(strcmp(key, "OcppServer") == 0)
  16578. {
  16579. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16580. {
  16581. strcpy(str, (const char*)value);
  16582. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16583. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16584. isSuccess = ConfigurationStatus_Accepted;
  16585. }
  16586. else
  16587. {
  16588. isSuccess = ConfigurationStatus_Rejected;
  16589. }
  16590. }
  16591. if(strcmp(key, "MaintainServer") == 0)
  16592. {
  16593. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16594. {
  16595. strcpy(str, (const char*)value);
  16596. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16597. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16598. isSuccess = ConfigurationStatus_Accepted;
  16599. }
  16600. else
  16601. {
  16602. isSuccess = ConfigurationStatus_Rejected;
  16603. }
  16604. }
  16605. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16606. {
  16607. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16608. {
  16609. strcpy(str, (const char*)value);
  16610. for(int i = 0; str[i]; i++)
  16611. {
  16612. str[i] = tolower(str[i]);
  16613. }
  16614. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16615. isSuccess = ConfigurationStatus_Accepted;
  16616. }
  16617. else
  16618. {
  16619. isSuccess = ConfigurationStatus_Rejected;
  16620. }
  16621. }
  16622. if(strcmp(key, "StatusNotificationInterval") == 0)
  16623. {
  16624. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16625. {
  16626. check_ascii = value[0];
  16627. if( (check_ascii < 48) || (check_ascii > 57) )
  16628. {
  16629. isSuccess = ConfigurationStatus_Rejected;
  16630. }
  16631. else
  16632. {
  16633. if((atoi(value) == 0) || (atoi(value) >= 10))
  16634. {
  16635. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16636. isSuccess = ConfigurationStatus_Accepted;
  16637. }
  16638. else
  16639. isSuccess = ConfigurationStatus_Rejected;
  16640. }
  16641. }
  16642. else
  16643. {
  16644. isSuccess = ConfigurationStatus_Rejected;
  16645. }
  16646. }
  16647. #if 0
  16648. //For OCPP Test Case
  16649. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16650. {
  16651. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16652. {
  16653. strcpy(str, (const char*)value);
  16654. for(int i = 0; str[i]; i++)
  16655. {
  16656. str[i] = tolower(str[i]);
  16657. }
  16658. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16659. isSuccess = ConfigurationStatus_Accepted;
  16660. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16661. }
  16662. else
  16663. {
  16664. isSuccess = ConfigurationStatus_Rejected;
  16665. }
  16666. }
  16667. #endif
  16668. #if 1
  16669. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16670. {
  16671. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16672. {
  16673. strcpy(str, (const char*)value);
  16674. for(int i = 0; str[i]; i++)
  16675. {
  16676. str[i] = tolower(str[i]);
  16677. }
  16678. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16679. isSuccess = ConfigurationStatus_Accepted;
  16680. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16681. }
  16682. else
  16683. {
  16684. isSuccess = ConfigurationStatus_Rejected;
  16685. }
  16686. }
  16687. #endif
  16688. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16689. {
  16690. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16691. {
  16692. check_ascii = value[0];
  16693. if( (check_ascii < 48) || (check_ascii > 57) )
  16694. {
  16695. isSuccess = ConfigurationStatus_Rejected;
  16696. }
  16697. else
  16698. {
  16699. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16700. isSuccess = ConfigurationStatus_Accepted;
  16701. }
  16702. }
  16703. else
  16704. {
  16705. isSuccess = ConfigurationStatus_Rejected;
  16706. }
  16707. }
  16708. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16709. {
  16710. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16711. {
  16712. check_ascii = value[0];
  16713. if( (check_ascii < 48) || (check_ascii > 57) )
  16714. {
  16715. isSuccess = ConfigurationStatus_Rejected;
  16716. }
  16717. else
  16718. {
  16719. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16720. isSuccess = ConfigurationStatus_Accepted;
  16721. }
  16722. }
  16723. else
  16724. {
  16725. isSuccess = ConfigurationStatus_Rejected;
  16726. }
  16727. }
  16728. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16729. {
  16730. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16731. {
  16732. strcpy(str, (const char*)value);
  16733. for(int i = 0; str[i]; i++)
  16734. {
  16735. str[i] = tolower(str[i]);
  16736. }
  16737. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16738. isSuccess = ConfigurationStatus_Accepted;
  16739. }
  16740. else
  16741. {
  16742. isSuccess = ConfigurationStatus_Rejected;
  16743. }
  16744. }
  16745. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16746. {
  16747. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16748. {
  16749. check_ascii = value[0];
  16750. if( (check_ascii < 48) || (check_ascii > 57) )
  16751. {
  16752. isSuccess = ConfigurationStatus_Rejected;
  16753. }
  16754. else
  16755. {
  16756. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16757. isSuccess = ConfigurationStatus_Accepted;
  16758. }
  16759. }
  16760. else
  16761. {
  16762. isSuccess = ConfigurationStatus_Rejected;
  16763. }
  16764. }
  16765. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16766. {
  16767. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16768. {
  16769. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16770. isSuccess = ConfigurationStatus_Accepted;
  16771. }
  16772. else
  16773. {
  16774. isSuccess = ConfigurationStatus_Rejected;
  16775. }
  16776. }
  16777. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16778. {
  16779. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16780. {
  16781. check_ascii = value[0];
  16782. if( (check_ascii < 48) || (check_ascii > 57) )
  16783. {
  16784. isSuccess = ConfigurationStatus_Rejected;
  16785. }
  16786. else
  16787. {
  16788. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16789. isSuccess = ConfigurationStatus_Accepted;
  16790. }
  16791. }
  16792. else
  16793. {
  16794. isSuccess = ConfigurationStatus_Rejected;
  16795. }
  16796. }
  16797. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16798. {
  16799. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16800. {
  16801. strcpy(str, (const char*)value);
  16802. for(int i = 0; str[i]; i++)
  16803. {
  16804. str[i] = tolower(str[i]);
  16805. }
  16806. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16807. isSuccess = ConfigurationStatus_Accepted;
  16808. }
  16809. else
  16810. {
  16811. isSuccess = ConfigurationStatus_Rejected;
  16812. }
  16813. }
  16814. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16815. {
  16816. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16817. {
  16818. check_ascii = value[0];
  16819. if( (check_ascii < 48) || (check_ascii > 57) )
  16820. {
  16821. isSuccess = ConfigurationStatus_Rejected;
  16822. }
  16823. else
  16824. {
  16825. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16826. isSuccess = ConfigurationStatus_Accepted;
  16827. }
  16828. }
  16829. else
  16830. {
  16831. isSuccess = ConfigurationStatus_Rejected;
  16832. }
  16833. }
  16834. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16835. return isSuccess;
  16836. }
  16837. int TransactionMessageAttemptsGet(void)
  16838. {
  16839. return TransactionMessageAttemptsValue;
  16840. }
  16841. int FirstHeartBeatResponse(void)
  16842. {
  16843. return FirstHeartBeat;
  16844. }
  16845. int TransactionMessageRetryIntervalGet(void)
  16846. {
  16847. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16848. }
  16849. int ReadHttpStatus(int sock)
  16850. {
  16851. //char c;
  16852. char buff[1024]="",*ptr=buff+1;
  16853. int bytes_received, status;
  16854. DEBUG_INFO("Begin Response ..\n");
  16855. while((bytes_received = recv(sock, ptr, 1, 0))){
  16856. if(bytes_received==-1){
  16857. perror("ReadHttpStatus");
  16858. exit(1);
  16859. }
  16860. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16861. ptr++;
  16862. }
  16863. *ptr=0;
  16864. ptr=buff+1;
  16865. sscanf(ptr,"%*s %d ", &status);
  16866. DEBUG_INFO("%s\n",ptr);
  16867. DEBUG_INFO("status=%d\n",status);
  16868. DEBUG_INFO("End Response ..\n");
  16869. return (bytes_received>0)?status:0;
  16870. }
  16871. //the only filed that it parsed is 'Content-Length'
  16872. int ParseHeader(int sock)
  16873. {
  16874. //char c;
  16875. char buff[1024]="",*ptr=buff+4;
  16876. int bytes_received;
  16877. DEBUG_INFO("Begin HEADER ..\n");
  16878. while((bytes_received = recv(sock, ptr, 1, 0))){
  16879. if(bytes_received==-1){
  16880. perror("Parse Header");
  16881. exit(1);
  16882. }
  16883. if(
  16884. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16885. (ptr[-1]=='\r') && (*ptr=='\n' )
  16886. ) break;
  16887. ptr++;
  16888. }
  16889. *ptr=0;
  16890. ptr=buff+4;
  16891. //printf("%s",ptr);
  16892. if(bytes_received){
  16893. ptr=strstr(ptr,"Content-Length:");
  16894. if(ptr){
  16895. sscanf(ptr,"%*s %d",&bytes_received);
  16896. }else
  16897. bytes_received=-1; //unknown size
  16898. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16899. }
  16900. DEBUG_INFO("End HEADER ..\n");
  16901. return bytes_received ;
  16902. }
  16903. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16904. {
  16905. int result = TRUE;
  16906. char rmFileCmd[100]={0};
  16907. char FilePath[100]={0};
  16908. char ftpbuf[200];
  16909. int systemresult;
  16910. sprintf(FilePath,"/mnt/%s",filename);
  16911. system("ping 8.8.8.8 &");
  16912. if((access(FilePath,F_OK))!=-1)
  16913. {
  16914. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16915. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16916. system(rmFileCmd);
  16917. }
  16918. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16919. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16920. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16921. systemresult = system(ftpbuf);
  16922. if(systemresult != 0)
  16923. {
  16924. DEBUG_INFO("http DownLoad error!\n");
  16925. result = FALSE;
  16926. }
  16927. system("pkill ping");
  16928. return result;
  16929. }
  16930. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16931. {
  16932. int result = TRUE;
  16933. char rmFileCmd[100]={0};
  16934. char FilePath[100]={0};
  16935. char ftpbuf[200];
  16936. int systemresult;
  16937. sprintf(FilePath,"/mnt/%s",filename);
  16938. system("ping 8.8.8.8 &");
  16939. if((access(FilePath,F_OK))!=-1)
  16940. {
  16941. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16942. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16943. system(rmFileCmd);
  16944. }
  16945. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16946. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16947. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16948. systemresult = system(ftpbuf);
  16949. if(systemresult != 0)
  16950. {
  16951. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16952. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16953. systemresult = system(ftpbuf);
  16954. if(systemresult != 0)
  16955. {
  16956. DEBUG_WARN("wget error!\n");
  16957. result = FALSE;
  16958. }
  16959. }
  16960. system("pkill ping");
  16961. return result;
  16962. }
  16963. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16964. {
  16965. char rmFileCmd[100]={0};
  16966. char FilePath[100]={0};
  16967. char buf[512];
  16968. int systemresult = 0;
  16969. //DEBUG_INFO("filename=%s\n",filename);
  16970. //DEBUG_INFO("url=%s\n",url);
  16971. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16972. if((access(FilePath,F_OK))!=-1)
  16973. {
  16974. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16975. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16976. system(rmFileCmd);
  16977. }
  16978. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16979. if(fp == NULL)
  16980. {
  16981. DEBUG_INFO("log is NULL\n");
  16982. return FALSE;
  16983. }
  16984. else
  16985. {
  16986. fprintf(fp, "%s\n", url);
  16987. fprintf(fp, "%s\n", filename);
  16988. fclose(fp);
  16989. }
  16990. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16991. if(phpFP == NULL)
  16992. {
  16993. DEBUG_INFO("PHP upload fail.\n");
  16994. return FALSE;
  16995. }
  16996. else
  16997. {
  16998. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16999. {
  17000. if(strstr(buf, "result") != NULL)
  17001. {
  17002. sscanf(buf, "result: %d", &systemresult);
  17003. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17004. }
  17005. }
  17006. pclose(phpFP);
  17007. }
  17008. if(systemresult != 1)
  17009. {
  17010. DEBUG_INFO("HTTP upload error!\n");
  17011. return FALSE;
  17012. }
  17013. return TRUE;
  17014. }
  17015. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17016. {
  17017. int result = FALSE;
  17018. char ftpbuf[200];
  17019. int systemresult;
  17020. /*
  17021. // Domaind name transfer to IP address
  17022. struct hostent* server;
  17023. char *IPbuffer;
  17024. server = gethostbyname(location);
  17025. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17026. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17027. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17028. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17029. systemresult = system(ftpbuf);
  17030. if(systemresult != 0)
  17031. {
  17032. DEBUG_INFO("ftpput error!\n");
  17033. }
  17034. else
  17035. {
  17036. result = TRUE;
  17037. DEBUG_INFO("ftpput OK!\n");
  17038. }
  17039. return result;
  17040. }
  17041. int GetOcppServerURL()
  17042. {
  17043. int result = FALSE;
  17044. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17045. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17046. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17047. struct yuarel url;
  17048. char urlStr[512];
  17049. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  17050. {
  17051. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  17052. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17053. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17054. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  17055. if(yuarel_parse(&url, urlStr) != -1)
  17056. {
  17057. sprintf(OcppProtocol, "%s", url.scheme);
  17058. sprintf(OcppHost, "%s", url.host);
  17059. if(url.path == NULL)
  17060. OcppTempPath[0] = '\0';
  17061. else
  17062. {
  17063. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  17064. {
  17065. sprintf(OcppTempPath, "%s/", url.path);
  17066. }
  17067. else
  17068. {
  17069. sprintf(OcppTempPath, "%s", url.path);
  17070. }
  17071. }
  17072. if(url.port == 0)
  17073. {
  17074. if(strcmp(OcppProtocol, "wss") == 0)
  17075. OcppPort = 443;
  17076. else
  17077. OcppPort = 80;
  17078. }
  17079. else
  17080. OcppPort = url.port;
  17081. result = TRUE;
  17082. }
  17083. }
  17084. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  17085. {
  17086. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  17087. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17088. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17089. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  17090. if(yuarel_parse(&url, urlStr) != -1)
  17091. {
  17092. sprintf(OcppProtocol, "%s", url.scheme);
  17093. sprintf(OcppHost, "%s", url.host);
  17094. if(url.path == NULL)
  17095. OcppTempPath[0] = '\0';
  17096. else
  17097. sprintf(OcppTempPath, "%s", url.path);
  17098. if(url.port == 0)
  17099. {
  17100. if(strcmp(OcppProtocol, "wss") == 0)
  17101. OcppPort = 443;
  17102. else
  17103. OcppPort = 80;
  17104. }
  17105. else
  17106. OcppPort = url.port;
  17107. result = TRUE;
  17108. }
  17109. }
  17110. else
  17111. {
  17112. strcpy(OcppHost,"");
  17113. }
  17114. return result;
  17115. }
  17116. int GetOcppPath()
  17117. {
  17118. int result = FALSE;
  17119. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  17120. {
  17121. if(OcppTempPath == NULL)
  17122. {
  17123. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17124. }
  17125. else
  17126. {
  17127. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17128. }
  17129. result = TRUE;
  17130. goto End;
  17131. }
  17132. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  17133. {
  17134. if(OcppTempPath == NULL)
  17135. {
  17136. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  17137. }
  17138. else
  17139. {
  17140. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  17141. }
  17142. result = TRUE;
  17143. goto End;
  17144. }
  17145. else
  17146. {
  17147. strcpy(OcppPath,"");
  17148. }
  17149. End:
  17150. return result;
  17151. }
  17152. int GetOcppPort()
  17153. {
  17154. return OcppPort;
  17155. }
  17156. int GetOcppConnStatus(void)
  17157. {
  17158. return ShmOCPP16Data->OcppConnStatus;
  17159. }
  17160. void SetOcppConnStatus(uint8_t status)
  17161. {
  17162. ShmOCPP16Data->OcppConnStatus = status;
  17163. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  17164. }
  17165. int GetHeartBeatWithNOResponse(void)
  17166. {
  17167. return HeartBeatWithNOResponse;
  17168. }
  17169. void SetHeartBeatWithNOResponse(void)
  17170. {
  17171. HeartBeatWithNOResponse = 0;
  17172. }
  17173. void GetStartTransactionIdTag(int gun_index)
  17174. {
  17175. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17176. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17177. }
  17178. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17179. {
  17180. char ch;
  17181. FILE *fptr1;
  17182. int temptransactionId;
  17183. char str[100]={0};
  17184. temptransactionId = 0;
  17185. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17186. {
  17187. DEBUG_INFO("IdTag is empty.\n");
  17188. return temptransactionId;
  17189. }
  17190. /*------ Read the file ----------------*/
  17191. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  17192. if (!fptr1)
  17193. {
  17194. DEBUG_INFO("QueueTransactionId file open error.\n");
  17195. //printf(" File not found or unable to open the input file!!\n");
  17196. return temptransactionId;
  17197. }
  17198. ch=fgetc(fptr1);
  17199. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  17200. rewind(fptr1);
  17201. if(ch!=EOF)
  17202. {
  17203. // printf("%c",ch);
  17204. while (fgets(str, 100, fptr1) != NULL)
  17205. {
  17206. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17207. if(str[0]=='\0')
  17208. {
  17209. break;
  17210. }
  17211. char *revbuf[8] = {0}; // Variable store string split
  17212. int num = 0;// Quantity after string split
  17213. DEBUG_INFO("Transaction queue data= %s\n", str);
  17214. splitstring(str,",",revbuf,&num); // String split
  17215. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17216. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17217. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17218. DEBUG_INFO("------------------------------\n");
  17219. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17220. {
  17221. if(isStopTransaction)
  17222. {
  17223. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17224. {
  17225. temptransactionId = atoi(revbuf[2]);
  17226. //break;
  17227. }
  17228. }
  17229. else
  17230. {
  17231. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17232. {
  17233. temptransactionId = atoi(revbuf[2]);
  17234. //break;
  17235. }
  17236. }
  17237. }
  17238. }
  17239. }
  17240. else
  17241. DEBUG_INFO("EOF\n");
  17242. fclose(fptr1);
  17243. /*------- End of reading ---------------*/
  17244. return temptransactionId;
  17245. }
  17246. void SetTransactionIdZero(int transactionId)
  17247. {
  17248. char ch;
  17249. FILE *fptr1, *fptr2;
  17250. int temptransactionId = 0;
  17251. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  17252. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  17253. if (!fptr1)
  17254. {
  17255. //printf(" File not found or unable to open the input file!!\n");
  17256. return ;
  17257. }
  17258. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17259. if (!fptr2)
  17260. {
  17261. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17262. fclose(fptr1);
  17263. return ;
  17264. }
  17265. ch=fgetc(fptr1);
  17266. rewind(fptr1);
  17267. if(ch!=EOF)
  17268. {
  17269. // copy all contents to the temporary file except the specific line
  17270. while (fgets(str, 100, fptr1) != NULL)
  17271. {
  17272. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17273. if(str[0]=='\0')
  17274. {
  17275. break;
  17276. }
  17277. char *revbuf[8] = {0};
  17278. int num = 0;
  17279. strcpy(strtemp, str);
  17280. splitstring(str,",",revbuf,&num);
  17281. if(revbuf[2][0] != '\0')
  17282. {
  17283. temptransactionId = atoi(revbuf[2]);
  17284. if(transactionId != temptransactionId)
  17285. {
  17286. fprintf(fptr2, "%s\n", strtemp);
  17287. }
  17288. }
  17289. }
  17290. }
  17291. fclose(fptr1);
  17292. fclose(fptr2);
  17293. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  17294. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  17295. /*------ Read the file ----------------*/
  17296. }
  17297. int InternetDisconnect(void)
  17298. {
  17299. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17300. }
  17301. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17302. void storeTempStopTransaction(int gun_index)
  17303. {
  17304. char guid[37]={0};
  17305. int tempIndex = 0;
  17306. char TempStopTransaction[256];
  17307. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  17308. DEBUG_INFO("storeTempStopTransaction...\n");
  17309. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17310. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  17311. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17312. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17313. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17314. {
  17315. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17316. {
  17317. tempIndex = ((gun_index==2) ? 1: 0);
  17318. }
  17319. else
  17320. {
  17321. tempIndex = gun_index;
  17322. }
  17323. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17324. {
  17325. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17326. {
  17327. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17328. }
  17329. }// END OF CHAdeMO_QUANTITY
  17330. }
  17331. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17332. {
  17333. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17334. {
  17335. tempIndex = ((gun_index==2) ? 1: 0);
  17336. }
  17337. else
  17338. {
  17339. tempIndex = gun_index;
  17340. }
  17341. for (int index = 0; index < CCS_QUANTITY; index++)
  17342. {
  17343. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17344. {
  17345. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17346. }
  17347. }// END OF CCS_QUANTITY
  17348. }
  17349. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17350. {
  17351. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17352. {
  17353. tempIndex = ((gun_index==2) ? 1: 0);
  17354. }
  17355. else
  17356. {
  17357. tempIndex = gun_index;
  17358. }
  17359. for (int index = 0; index < GB_QUANTITY; index++)
  17360. {
  17361. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17362. {
  17363. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17364. }
  17365. }// END OF GB_QUANTITY
  17366. }
  17367. else if(gunType[gun_index] == GUN_TYPE_DO)
  17368. {
  17369. tempIndex = gun_index;
  17370. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17371. {
  17372. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17373. {
  17374. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17375. }
  17376. }
  17377. }
  17378. else
  17379. {
  17380. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17381. {
  17382. tempIndex = 2;
  17383. }
  17384. else
  17385. {
  17386. tempIndex = gun_index;
  17387. }
  17388. for (int index = 0; index < AC_QUANTITY; index++)
  17389. {
  17390. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17391. {
  17392. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17393. }
  17394. }// END OF AC_QUANTITY
  17395. }
  17396. //Stop Transaction Time
  17397. struct timeval tmnow;
  17398. struct tm *tm;
  17399. char buf[28];//, usec_buf[6];
  17400. gettimeofday(&tmnow, NULL);
  17401. time_t t;
  17402. t = time(NULL);
  17403. /*UTC time and date*/
  17404. tm = gmtime(&t);
  17405. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17406. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  17407. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  17408. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17409. random_uuid(guid);
  17410. /***********************************transactionData******************************************************/
  17411. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17412. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17413. //=================================
  17414. //1. Transaction_Begin
  17415. //=================================
  17416. //============================== Energy.Active.Import.Interval ===========================================
  17417. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17418. {
  17419. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  17420. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17421. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  17422. 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*/]);
  17423. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17424. 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))
  17425. {
  17426. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  17427. }
  17428. else
  17429. {
  17430. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  17431. }
  17432. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  17433. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17434. }
  17435. //=================================
  17436. //2. Transaction_End
  17437. //=================================
  17438. //2.1====================================== Current.Import L1 ==============================================
  17439. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17440. {
  17441. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17442. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17443. {
  17444. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17445. {
  17446. tempIndex = ((gun_index==2) ? 1: 0);
  17447. }
  17448. else
  17449. {
  17450. tempIndex = gun_index;
  17451. }
  17452. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17453. {
  17454. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17455. {
  17456. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17457. }
  17458. }// End of for CHAdeMO_QUANTITY
  17459. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17460. }
  17461. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17462. {
  17463. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17464. {
  17465. tempIndex = ((gun_index==2) ? 1: 0);
  17466. }
  17467. else
  17468. {
  17469. tempIndex = gun_index;
  17470. }
  17471. for (int index = 0; index < CCS_QUANTITY; index++)
  17472. {
  17473. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17474. {
  17475. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17476. }
  17477. }// End of for CCS_QUANTITY
  17478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17479. }
  17480. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17481. {
  17482. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17483. {
  17484. tempIndex = ((gun_index==2) ? 1: 0);
  17485. }
  17486. else
  17487. {
  17488. tempIndex = gun_index;
  17489. }
  17490. for (int index = 0; index < GB_QUANTITY; index++)
  17491. {
  17492. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17493. {
  17494. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17495. }
  17496. }// End of for GB_QUANTITY
  17497. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17498. }
  17499. else if(gunType[gun_index] == GUN_TYPE_DO)
  17500. {
  17501. tempIndex = gun_index;
  17502. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17503. {
  17504. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17505. {
  17506. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17507. }
  17508. }
  17509. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17510. }
  17511. else
  17512. {
  17513. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17514. {
  17515. tempIndex = 2;
  17516. }
  17517. else
  17518. {
  17519. tempIndex = gun_index;
  17520. }
  17521. for (int index = 0; index < AC_QUANTITY; index++)
  17522. {
  17523. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17524. {
  17525. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17526. }
  17527. }// End of for AC_QUANTITY
  17528. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17529. }
  17530. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17531. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17532. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17533. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17534. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17535. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17536. }
  17537. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17538. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17539. {
  17540. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17541. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17542. {
  17543. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17544. {
  17545. tempIndex = ((gun_index==2) ? 1: 0);
  17546. }
  17547. else
  17548. {
  17549. tempIndex = gun_index;
  17550. }
  17551. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17552. {
  17553. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17554. {
  17555. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17556. }
  17557. }// END OF CHAdeMO_QUANTITY
  17558. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17559. }
  17560. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17561. {
  17562. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17563. {
  17564. tempIndex = ((gun_index==2) ? 1: 0);
  17565. }
  17566. else
  17567. {
  17568. tempIndex = gun_index;
  17569. }
  17570. for (int index = 0; index < CCS_QUANTITY; index++)
  17571. {
  17572. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17573. {
  17574. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17575. }
  17576. }// END OF CCS_QUANTITY
  17577. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17578. }
  17579. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17580. {
  17581. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17582. {
  17583. tempIndex = ((gun_index==2) ? 1: 0);
  17584. }
  17585. else
  17586. {
  17587. tempIndex = gun_index;
  17588. }
  17589. for (int index = 0; index < GB_QUANTITY; index++)
  17590. {
  17591. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17592. {
  17593. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17594. }
  17595. }// END OF GB_QUANTITY
  17596. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17597. }
  17598. else if(gunType[gun_index] == GUN_TYPE_DO)
  17599. {
  17600. tempIndex = gun_index;
  17601. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17602. {
  17603. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17604. {
  17605. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17606. }
  17607. }
  17608. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17609. }
  17610. else
  17611. {
  17612. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17613. {
  17614. tempIndex = 2;
  17615. }
  17616. else
  17617. {
  17618. tempIndex = gun_index;
  17619. }
  17620. for (int index = 0; index < AC_QUANTITY; index++)
  17621. {
  17622. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17623. {
  17624. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17625. }
  17626. }// END OF AC_QUANTITY
  17627. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17628. }
  17629. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17630. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17631. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17632. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17633. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17634. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17635. }
  17636. //2.3====================================== Power.Active.Import =========================================
  17637. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17638. {
  17639. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17640. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17641. {
  17642. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17643. {
  17644. tempIndex = ((gun_index==2) ? 1: 0);
  17645. }
  17646. else
  17647. {
  17648. tempIndex = gun_index;
  17649. }
  17650. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17651. {
  17652. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17653. {
  17654. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17655. }
  17656. } // End for CHAdeMO_QUANTITY
  17657. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17658. }
  17659. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17660. {
  17661. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17662. {
  17663. tempIndex = ((gun_index==2) ? 1: 0);
  17664. }
  17665. else
  17666. {
  17667. tempIndex = gun_index;
  17668. }
  17669. for (int index = 0; index < CCS_QUANTITY; index++)
  17670. {
  17671. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17672. {
  17673. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17674. }
  17675. } // END for CCS_QUANTITY
  17676. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17677. }
  17678. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17679. {
  17680. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17681. {
  17682. tempIndex = ((gun_index==2) ? 1: 0);
  17683. }
  17684. else
  17685. {
  17686. tempIndex = gun_index;
  17687. }
  17688. for (int index = 0; index < GB_QUANTITY; index++)
  17689. {
  17690. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17691. {
  17692. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17693. }
  17694. }// END for GB_QUANTITY
  17695. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17696. }
  17697. else if(gunType[gun_index] == GUN_TYPE_DO)
  17698. {
  17699. tempIndex = gun_index;
  17700. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17701. {
  17702. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17703. {
  17704. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17705. }
  17706. }
  17707. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17708. }
  17709. else
  17710. {
  17711. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17712. {
  17713. tempIndex = 2;
  17714. }
  17715. else
  17716. {
  17717. tempIndex = gun_index;
  17718. }
  17719. for (int index = 0; index < AC_QUANTITY; index++)
  17720. {
  17721. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17722. {
  17723. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17724. }
  17725. } // END for AC_QUANTITY
  17726. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17727. }
  17728. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17729. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17730. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17731. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17732. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17733. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17734. }
  17735. //2.4====================================== Voltage L1 ====================================================
  17736. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17737. {
  17738. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17739. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17740. {
  17741. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17742. {
  17743. tempIndex = ((gun_index==2) ? 1: 0);
  17744. }
  17745. else
  17746. {
  17747. tempIndex = gun_index;
  17748. }
  17749. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17750. {
  17751. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17752. {
  17753. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17754. }
  17755. } // END OF FOR CHAdeMO_QUANTITY
  17756. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17757. }
  17758. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17759. {
  17760. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17761. {
  17762. tempIndex = ((gun_index==2) ? 1: 0);
  17763. }
  17764. else
  17765. {
  17766. tempIndex = gun_index;
  17767. }
  17768. for (int index = 0; index < CCS_QUANTITY; index++)
  17769. {
  17770. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17771. {
  17772. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17773. }
  17774. } // END OF FOR CCS_QUANTITY
  17775. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17776. }
  17777. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17778. {
  17779. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17780. {
  17781. tempIndex = ((gun_index==2) ? 1: 0);
  17782. }
  17783. else
  17784. {
  17785. tempIndex = gun_index;
  17786. }
  17787. for (int index = 0; index < GB_QUANTITY; index++)
  17788. {
  17789. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17790. {
  17791. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17792. }
  17793. } // END OF FOR GB_QUANTITY
  17794. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17795. }
  17796. else if(gunType[gun_index] == GUN_TYPE_DO)
  17797. {
  17798. tempIndex = gun_index;
  17799. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17800. {
  17801. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17802. {
  17803. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17804. }
  17805. }
  17806. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17807. }
  17808. else
  17809. {
  17810. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17811. {
  17812. tempIndex = 2;
  17813. }
  17814. else
  17815. {
  17816. tempIndex = gun_index;
  17817. }
  17818. for (int index = 0; index < AC_QUANTITY; index++)
  17819. {
  17820. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17821. {
  17822. 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
  17823. }
  17824. } // END OF FOR AC_QUANTITY
  17825. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17826. }
  17827. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17828. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17829. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17830. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17831. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17832. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17833. }
  17834. //2.5============================================== End SoC =========================================================
  17835. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17836. {
  17837. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17838. 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))
  17839. {
  17840. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17841. {
  17842. tempIndex = ((gun_index==2) ? 1: 0);
  17843. }
  17844. else
  17845. {
  17846. tempIndex = gun_index;
  17847. }
  17848. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17849. {
  17850. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17851. {
  17852. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17853. {
  17854. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17855. }
  17856. }
  17857. }
  17858. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17859. {
  17860. for (int index = 0; index < CCS_QUANTITY; index++)
  17861. {
  17862. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17863. {
  17864. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17865. }
  17866. }
  17867. }
  17868. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17869. {
  17870. for (int index = 0; index < GB_QUANTITY; index++)
  17871. {
  17872. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17873. {
  17874. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17875. }
  17876. }
  17877. }
  17878. else if(gunType[gun_index] == GUN_TYPE_DO)
  17879. {
  17880. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17881. {
  17882. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17883. {
  17884. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17885. }
  17886. }
  17887. }
  17888. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17889. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17890. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17891. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17892. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17893. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17894. } // END FOR DC CASE
  17895. }
  17896. //2.6====================================== Current.Import L2 ==============================================
  17897. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17898. {
  17899. // AC 3 phase L2 current
  17900. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17901. {
  17902. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17903. {
  17904. tempIndex = 2;
  17905. }
  17906. else
  17907. {
  17908. tempIndex = gun_index;
  17909. }
  17910. for (int index = 0; index < AC_QUANTITY; index++)
  17911. {
  17912. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17913. {
  17914. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17915. }
  17916. }// End of for AC_QUANTITY
  17917. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17918. }
  17919. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17920. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17921. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17922. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17923. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17924. }
  17925. //2.7====================================== Current.Import L3 ==============================================
  17926. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17927. {
  17928. // AC 3 phase L3 current
  17929. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17930. {
  17931. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17932. {
  17933. tempIndex = 2;
  17934. }
  17935. else
  17936. {
  17937. tempIndex = gun_index;
  17938. }
  17939. for (int index = 0; index < AC_QUANTITY; index++)
  17940. {
  17941. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17942. {
  17943. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17944. }
  17945. }// End of for AC_QUANTITY
  17946. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17947. }
  17948. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17949. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17950. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17951. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17952. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17953. }
  17954. //2.9====================================== Voltage L2 ====================================================
  17955. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17956. {
  17957. // AC 3 phase L2 volatge
  17958. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17959. {
  17960. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17961. {
  17962. tempIndex = 2;
  17963. }
  17964. else
  17965. {
  17966. tempIndex = gun_index;
  17967. }
  17968. for (int index = 0; index < AC_QUANTITY; index++)
  17969. {
  17970. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17971. {
  17972. 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
  17973. }
  17974. } // END OF FOR AC_QUANTITY
  17975. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  17976. }
  17977. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17978. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17979. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17980. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17981. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17982. }
  17983. //2.10====================================== Voltage L3 ====================================================
  17984. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17985. {
  17986. // AC 3 phase L3 volatge
  17987. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17988. {
  17989. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17990. {
  17991. tempIndex = 2;
  17992. }
  17993. else
  17994. {
  17995. tempIndex = gun_index;
  17996. }
  17997. for (int index = 0; index < AC_QUANTITY; index++)
  17998. {
  17999. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18000. {
  18001. 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
  18002. }
  18003. } // END OF FOR AC_QUANTITY
  18004. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18005. }
  18006. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18007. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18008. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18009. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18010. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18011. }
  18012. //====================== Start SoC ================================
  18013. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18014. {
  18015. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18016. 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))
  18017. {
  18018. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18019. {
  18020. tempIndex = ((gun_index==2) ? 1: 0);
  18021. }
  18022. else
  18023. {
  18024. tempIndex = gun_index;
  18025. }
  18026. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18027. {
  18028. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18029. {
  18030. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18031. {
  18032. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18033. }
  18034. }
  18035. }
  18036. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18037. {
  18038. for (int index = 0; index < CCS_QUANTITY; index++)
  18039. {
  18040. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18041. {
  18042. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18043. }
  18044. }
  18045. }
  18046. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18047. {
  18048. for (int index = 0; index < GB_QUANTITY; index++)
  18049. {
  18050. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18051. {
  18052. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18053. }
  18054. }
  18055. }
  18056. else if(gunType[gun_index] == GUN_TYPE_DO)
  18057. {
  18058. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18059. {
  18060. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18061. {
  18062. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18063. }
  18064. }
  18065. }
  18066. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18067. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18068. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18070. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18071. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18072. } // END FOR DC CASE
  18073. }
  18074. //======================================== Message create ==============================================
  18075. json_object *StopTransaction = json_object_new_object();
  18076. json_object *transactionDatas = json_object_new_array();
  18077. json_object *sampledValues = json_object_new_array();
  18078. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  18079. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  18080. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  18081. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  18082. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  18083. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18084. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  18085. {
  18086. json_object *transactionData = json_object_new_object();
  18087. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18088. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18089. {
  18090. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18091. {
  18092. json_object *sampledValue = json_object_new_object();
  18093. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18094. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18095. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18096. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18097. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18098. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18099. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18100. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18101. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18102. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18103. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18104. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18105. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18106. json_object_array_add(sampledValues, sampledValue);
  18107. }
  18108. }
  18109. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18110. json_object_array_add(transactionDatas, transactionData);
  18111. }
  18112. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18113. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18114. ,MESSAGE_TYPE_CALL
  18115. ,guid
  18116. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18117. json_object_put(StopTransaction);
  18118. // Check File "TempStopTransaction" Exist
  18119. if((access(TempStopTransaction,F_OK))!=-1)
  18120. {
  18121. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18122. fclose(fopen(TempStopTransaction, "w"));
  18123. }
  18124. else
  18125. {
  18126. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18127. FILE *log = fopen(TempStopTransaction, "w+");
  18128. if(log == NULL)
  18129. {
  18130. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18131. return ;
  18132. }
  18133. else
  18134. {
  18135. fclose(log);
  18136. }
  18137. }
  18138. //Add TempStopTransaction | Update TempStopTransaction
  18139. // open file for writing
  18140. FILE *outfile;
  18141. outfile = fopen (TempStopTransaction, "a");
  18142. //DEBUG_INFO("data = %s\n", queuedata);
  18143. fputs(queuedata, outfile);
  18144. fputs("\n", outfile);
  18145. fclose (outfile);
  18146. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18147. OCPP_updatePeriodEnergy(gun_index);
  18148. }
  18149. void checkTempStopTransaction(int gun_index)
  18150. {
  18151. FILE *fptr1;
  18152. char ch;
  18153. char str[QUEUE_MESSAGE_LENGTH]={0};
  18154. char guid[37]={0};
  18155. char tempdata[65]={0};
  18156. char connectorStr[2]={0};
  18157. char TempStopTransaction[256];
  18158. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18159. fptr1 = fopen(TempStopTransaction, "r");
  18160. //TempStopTransaction格式: 槍號,StopTransaction封包
  18161. if (!fptr1)
  18162. {
  18163. //printf(" File not found or unable to open the input file!!\n");
  18164. return ;
  18165. }
  18166. ch=fgetc(fptr1);
  18167. //printf(" Now the content of the file %s is : \n",fname);
  18168. rewind(fptr1);
  18169. if(ch!=EOF)
  18170. {
  18171. // copy all contents to the temporary file except the specific line
  18172. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18173. {
  18174. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18175. if(str[0]=='\0')
  18176. {
  18177. break;
  18178. }
  18179. //TempStopTransaction格式: 槍號,StopTransaction封包
  18180. strncpy(connectorStr, str, 1);
  18181. if(atoi(connectorStr) != (gun_index+1))
  18182. {
  18183. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18184. fclose(fptr1);
  18185. return ;
  18186. }
  18187. //random_uuid(guid);
  18188. strncpy(guid, str+6, 36); //copy guid
  18189. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18190. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18191. {
  18192. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18193. }
  18194. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18195. OCPP_insert_transaction_msg(NO, str);
  18196. memset(str,0,ARRAY_SIZE(str));
  18197. }
  18198. }
  18199. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18200. fclose(fptr1);
  18201. remove(TempStopTransaction); // remove the original file
  18202. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18203. }
  18204. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18205. {
  18206. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18207. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18208. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18209. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18210. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18211. }
  18212. int GetWebSocketPingInterval(void)
  18213. {
  18214. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18215. }
  18216. int GetServerSign(void)
  18217. {
  18218. return server_sign;
  18219. }
  18220. uint8_t GetOcppSecurityProfile()
  18221. {
  18222. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18223. }
  18224. void GetOcppChargerBoxId(uint8_t *data)
  18225. {
  18226. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18227. }
  18228. void GetOcppSecurityPassword(uint8_t *data)
  18229. {
  18230. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18231. }
  18232. void SetOcppVersion(uint8_t *version)
  18233. {
  18234. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18235. DEBUG_INFO("ocpp version: %s\n", version);
  18236. if(strstr((char*)version, "ocpp1.6") != NULL)
  18237. {
  18238. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18239. }
  18240. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18241. {
  18242. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18243. system("pkill OcppBackend");
  18244. }
  18245. }
  18246. void SetServerSign(int value)
  18247. {
  18248. server_sign = value;
  18249. }
  18250. int GetBootNotificationInterval(void)
  18251. {
  18252. return BootNotificationInterval;
  18253. }
  18254. int GetInternetConn(void)
  18255. {
  18256. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18257. }
  18258. int GetBackendConnectionTimeout(void)
  18259. {
  18260. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18261. }
  18262. int isConnectorInitMode(int gun_index)
  18263. {
  18264. int tempIndex = 0;
  18265. int result = TRUE;
  18266. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18267. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18268. {
  18269. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18270. {
  18271. tempIndex = ((gun_index==2) ? 1: 0);
  18272. }
  18273. else
  18274. {
  18275. tempIndex = gun_index;
  18276. }
  18277. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18278. {
  18279. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18280. {
  18281. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18282. } //end of the same index
  18283. }//end of for CHAdeMO_QUANTITY
  18284. }
  18285. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18286. {
  18287. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18288. {
  18289. tempIndex = ((gun_index==2) ? 1: 0);
  18290. }
  18291. else
  18292. {
  18293. tempIndex = gun_index;
  18294. }
  18295. for (int index = 0; index < CCS_QUANTITY; index++)
  18296. {
  18297. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18298. {
  18299. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18300. } //end of the same index
  18301. } // end of for CCS_QUANTITY
  18302. }
  18303. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18304. {
  18305. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18306. {
  18307. tempIndex = ((gun_index==2) ? 1: 0);
  18308. }
  18309. else
  18310. {
  18311. tempIndex = gun_index;
  18312. }
  18313. for (int index = 0; index < GB_QUANTITY; index++)
  18314. {
  18315. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18316. {
  18317. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18318. } //end of the same index
  18319. } // end of for GB_QUANTITY
  18320. }
  18321. else if(gunType[gun_index] == GUN_TYPE_DO)
  18322. {
  18323. tempIndex = gun_index;
  18324. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18325. {
  18326. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18327. {
  18328. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18329. } //end of the same index
  18330. }
  18331. }
  18332. else
  18333. {
  18334. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18335. {
  18336. tempIndex = 2;
  18337. }
  18338. else
  18339. {
  18340. tempIndex = gun_index;
  18341. }
  18342. for (int index = 0; index < AC_QUANTITY; index++)
  18343. {
  18344. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18345. {
  18346. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18347. }//end of the same index
  18348. }//end of for AC_QUANTITY
  18349. }
  18350. return result;
  18351. }
  18352. void refreshProcDogTimer()
  18353. {
  18354. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  18355. }
  18356. void InitialSystemValue(void)
  18357. {
  18358. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18359. locallistVersion=0;
  18360. BootNotificationInterval = 0;
  18361. authorizeRetryTimes = 0;
  18362. GunStatusInterval = 10;
  18363. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18364. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18365. //Hear Beat
  18366. HeartBeatWithNOResponse = 0;
  18367. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18368. FirstHeartBeat = 0;
  18369. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18370. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18371. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18372. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18373. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18374. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18375. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18376. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18377. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18378. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18379. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18380. //Status && ConnectorPlugIn Setting
  18381. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18382. {
  18383. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18384. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18385. }
  18386. for (int index = 0; index < CCS_QUANTITY; index++)
  18387. {
  18388. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18389. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18390. }
  18391. for (int index = 0; index < GB_QUANTITY; index++)
  18392. {
  18393. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18394. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18395. }
  18396. for (int index = 0; index < AC_QUANTITY; index++)
  18397. {
  18398. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18399. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18400. }
  18401. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18402. {
  18403. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18404. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18405. }
  18406. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18407. {
  18408. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18409. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18410. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18411. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18412. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18413. }
  18414. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18415. refreshStartTimer(&clientTime.Heartbeat);
  18416. sleep(1);
  18417. }
  18418. void LWS_Send(char *str)
  18419. {
  18420. //=====================================================
  18421. // Check InternetConn 0: disconnected, 1: connected
  18422. //====================================================
  18423. if(GetOcppConnStatus() == 0)
  18424. {
  18425. DEBUG_INFO("offline now !!!\n");
  18426. return;
  18427. }
  18428. // Only disable isWebsocketSendable operation initiated by charger
  18429. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18430. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18431. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18432. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18433. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18434. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18435. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18436. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18437. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18438. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18439. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18440. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18441. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18442. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18443. {
  18444. isWebsocketSendable = 0;
  18445. }
  18446. pthread_mutex_lock(&lock_send);
  18447. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18448. sprintf((char *)SendBuffer, "%s", str);
  18449. SendBufLen = strlen(str);
  18450. pthread_mutex_unlock(&lock_send);
  18451. lws_callback_on_writable(wsi_client);
  18452. //lws_service(context, 0);
  18453. //sleep(1);
  18454. }
  18455. void LWS_SendNow(char *str)
  18456. {
  18457. //=====================================================
  18458. // Check InternetConn 0: disconnected, 1: connected
  18459. //====================================================
  18460. if(GetOcppConnStatus() == 0)
  18461. {
  18462. DEBUG_INFO("offline now !!!\n");
  18463. return;
  18464. }
  18465. // Only disable isWebsocketSendable operation initiated by charger
  18466. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18467. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18468. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18469. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18470. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18471. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18472. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18473. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18474. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18475. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18476. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18477. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18478. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18479. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18480. {
  18481. isWebsocketSendable = 0;
  18482. }
  18483. pthread_mutex_lock(&lock_send);
  18484. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18485. sprintf((char *)SendBuffer, "%s", str);
  18486. SendBufLen = strlen(str);
  18487. pthread_mutex_unlock(&lock_send);
  18488. lws_callback_on_writable(wsi_client);
  18489. lws_service(context, 0);
  18490. //sleep(1);
  18491. }