MessageHandler.c 926 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137
  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)
  1102. {
  1103. int result = PASS;
  1104. char* errMsg = NULL;
  1105. char sqlStr[8192];
  1106. sprintf(sqlStr, "insert into report_deduct_info(transactionId, creditNo, deductResult, isDonateInvoice, isUploaded) values('%d', '%s', '%d', '%d', '0');", txId, creditNo, deductResult, isDonateInvoice);
  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. json_object *deductData = json_object_new_object();
  1136. json_object_object_add(deductData, "txId", json_object_new_int(atoi(columnValue[1])));
  1137. json_object_object_add(deductData, "creditNo", json_object_new_string(columnValue[2]));
  1138. json_object_object_add(deductData, "deductResult", json_object_new_boolean(atoi(columnValue[3])));
  1139. json_object_object_add(deductData, "isDonateInvoice", json_object_new_boolean(atoi(columnValue[4])));
  1140. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1141. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"ID_CreditDeductResult");
  1142. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(deductData, JSON_C_TO_STRING_PLAIN));
  1143. json_object_put(deductData);
  1144. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1145. return 0;
  1146. }
  1147. void OCPP_query_deduct_info()
  1148. {
  1149. int rc = 0;
  1150. char sql[100];
  1151. char zErrMsg[100];
  1152. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1153. /* Execute SQL statement */
  1154. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1155. if( rc != SQLITE_OK )
  1156. {
  1157. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1158. }
  1159. }
  1160. //==========================================
  1161. // Check time passed since today
  1162. //==========================================
  1163. long long DiffTimebWithNow(struct timeb ST)
  1164. {
  1165. //return milli-second
  1166. struct timeb ET;
  1167. long long StartTime,StopTime;
  1168. ftime(&ET);
  1169. StartTime=(long long)ST.time;
  1170. StopTime=(long long)ET.time;
  1171. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1172. }
  1173. int getTimePassSinceToday(uint8_t gun_index)
  1174. {
  1175. int result = -1;
  1176. static time_t lastTime[4];
  1177. time_t t;
  1178. struct tm *tmStartToday;
  1179. struct timeb tbStartToday;
  1180. t=time(NULL);
  1181. if(difftime(t, lastTime[gun_index])>0)
  1182. {
  1183. tmStartToday=localtime(&t);
  1184. tmStartToday->tm_hour = 0;
  1185. tmStartToday->tm_min = 0;
  1186. tmStartToday->tm_sec = 0;
  1187. tbStartToday.time = mktime(tmStartToday);
  1188. tbStartToday.millitm = 0;
  1189. result = DiffTimebWithNow(tbStartToday)/1000;
  1190. lastTime[gun_index] = t;
  1191. }
  1192. return result;
  1193. }
  1194. void getNowDatetime(uint8_t *data)
  1195. {
  1196. time_t t = time(NULL);
  1197. struct tm tm = *localtime(&t);
  1198. 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);
  1199. }
  1200. int syncDateTimeRTC(uint8_t *data)
  1201. {
  1202. struct ParsingResult
  1203. {
  1204. int result;
  1205. int scanedElement;
  1206. int year;
  1207. int month;
  1208. int mday;
  1209. int hour;
  1210. int min;
  1211. int sec;
  1212. int tz_hour;
  1213. int tz_min;
  1214. float minSec;
  1215. }result;
  1216. struct tm tmOrg;
  1217. struct tm *tmTarget;
  1218. struct timeb tbTarget;
  1219. char buf[128];
  1220. memset(&result, 0x00, sizeof(struct ParsingResult));
  1221. result.result = PASS;
  1222. if(strstr((char*)data, ".") != NULL)
  1223. {
  1224. // Original data with mini second
  1225. if(strstr((char*)data, "Z") != NULL)
  1226. {
  1227. // Original data with Z
  1228. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1229. &result.year,
  1230. &result.month,
  1231. &result.mday,
  1232. &result.hour,
  1233. &result.min,
  1234. &result.sec,
  1235. &result.minSec);
  1236. }
  1237. else
  1238. {
  1239. // Original data without Z
  1240. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1241. &result.year,
  1242. &result.month,
  1243. &result.mday,
  1244. &result.hour,
  1245. &result.min,
  1246. &result.sec,
  1247. &result.minSec,
  1248. &result.tz_hour,
  1249. &result.tz_min);
  1250. }
  1251. }
  1252. else
  1253. {
  1254. // Original data without mini second
  1255. if(strstr((char*)data, "Z") != NULL)
  1256. {
  1257. // Original data with Z
  1258. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1259. &result.year,
  1260. &result.month,
  1261. &result.mday,
  1262. &result.hour,
  1263. &result.min,
  1264. &result.sec);
  1265. }
  1266. else
  1267. {
  1268. // Original data without Z
  1269. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1270. &result.year,
  1271. &result.month,
  1272. &result.mday,
  1273. &result.hour,
  1274. &result.min,
  1275. &result.sec,
  1276. &result.tz_hour,
  1277. &result.tz_min);
  1278. }
  1279. }
  1280. tmOrg.tm_year = result.year - 1900;
  1281. tmOrg.tm_mon = result.month - 1;
  1282. tmOrg.tm_mday = result.mday;
  1283. tmOrg.tm_hour = result.hour;
  1284. tmOrg.tm_min = result.min;
  1285. tmOrg.tm_sec = result.sec;
  1286. tmOrg.tm_gmtoff = 0;
  1287. tbTarget.time = mktime(&tmOrg);
  1288. tbTarget.timezone = 0;
  1289. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1290. tmTarget = gmtime(&tbTarget.time);
  1291. 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);
  1292. //DEBUG_INFO(" org date time: %s\n", data);
  1293. //DEBUG_INFO("parse date time: %s\n", buf);
  1294. system(buf);
  1295. system("/sbin/hwclock -w --systohc");
  1296. if(result.scanedElement < 6)
  1297. result.result = FAIL;
  1298. return result.result;
  1299. }
  1300. //==========================================
  1301. // GetCompositeSchedule logic related function
  1302. //==========================================
  1303. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1304. {
  1305. //return milli-second
  1306. unsigned int StartTime,StopTime;
  1307. StartTime=(unsigned int)ST.time;
  1308. StopTime=(unsigned int)ET.time;
  1309. return (StopTime-StartTime);
  1310. }
  1311. int DiffTimebWithNowSec(struct timeb ST)
  1312. {
  1313. //return milli-second
  1314. struct timeb ET;
  1315. unsigned int StartTime,StopTime;
  1316. ftime(&ET);
  1317. StartTime=(unsigned int)ST.time;
  1318. StopTime=(unsigned int)ET.time;
  1319. return (StopTime-StartTime);
  1320. }
  1321. int getStartStop(uint8_t *start, uint8_t *stop)
  1322. {
  1323. int result = -1;
  1324. struct tm tmStart;
  1325. struct timeb tbStart;
  1326. struct tm tmStop;
  1327. struct timeb tbStop;
  1328. 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) &&
  1329. (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))
  1330. {
  1331. //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);
  1332. //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);
  1333. tmStart.tm_year -= 1900;
  1334. tmStart.tm_mon -= 1;
  1335. tbStart.time = mktime(&tmStart);
  1336. tbStart.millitm = 0;
  1337. tmStop.tm_year -= 1900;
  1338. tmStop.tm_mon -= 1;
  1339. tbStop.time = mktime(&tmStop);
  1340. tbStop.millitm = 0;
  1341. result = DiffTimebSec(tbStart, tbStop);
  1342. //DEBUG_INFO("getStartStop(): %d\n", result);
  1343. }
  1344. else
  1345. {
  1346. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1347. }
  1348. return result;
  1349. }
  1350. int isOvertNow(uint8_t *start)
  1351. {
  1352. int result = NO;
  1353. struct ParsingResult
  1354. {
  1355. int result;
  1356. int scanedElement;
  1357. int year;
  1358. int month;
  1359. int mday;
  1360. int hour;
  1361. int min;
  1362. int sec;
  1363. int tz_hour;
  1364. int tz_min;
  1365. float minSec;
  1366. }parsingResult;
  1367. struct tm tmStart;
  1368. struct timeb tbStart;
  1369. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1370. if(strstr((char*)start, ".") != NULL)
  1371. {
  1372. // Original data with mini second
  1373. if(strstr((char*)start, "Z") != NULL)
  1374. {
  1375. // Original data with Z
  1376. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1377. &parsingResult.year,
  1378. &parsingResult.month,
  1379. &parsingResult.mday,
  1380. &parsingResult.hour,
  1381. &parsingResult.min,
  1382. &parsingResult.sec,
  1383. &parsingResult.minSec);
  1384. }
  1385. else
  1386. {
  1387. // Original data without Z
  1388. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1389. &parsingResult.year,
  1390. &parsingResult.month,
  1391. &parsingResult.mday,
  1392. &parsingResult.hour,
  1393. &parsingResult.min,
  1394. &parsingResult.sec,
  1395. &parsingResult.minSec,
  1396. &parsingResult.tz_hour,
  1397. &parsingResult.tz_min);
  1398. }
  1399. }
  1400. else
  1401. {
  1402. // Original data without mini second
  1403. if(strstr((char*)start, "Z") != NULL)
  1404. {
  1405. // Original data with Z
  1406. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1407. &parsingResult.year,
  1408. &parsingResult.month,
  1409. &parsingResult.mday,
  1410. &parsingResult.hour,
  1411. &parsingResult.min,
  1412. &parsingResult.sec);
  1413. }
  1414. else
  1415. {
  1416. // Original data without Z
  1417. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1418. &parsingResult.year,
  1419. &parsingResult.month,
  1420. &parsingResult.mday,
  1421. &parsingResult.hour,
  1422. &parsingResult.min,
  1423. &parsingResult.sec,
  1424. &parsingResult.tz_hour,
  1425. &parsingResult.tz_min);
  1426. }
  1427. }
  1428. if(parsingResult.scanedElement >= 6)
  1429. {
  1430. tmStart.tm_year = parsingResult.year - 1900;
  1431. tmStart.tm_mon = parsingResult.month - 1;
  1432. tmStart.tm_mday = parsingResult.mday;
  1433. tmStart.tm_hour = parsingResult.hour;
  1434. tmStart.tm_min = parsingResult.min;
  1435. tmStart.tm_sec = parsingResult.sec;
  1436. tmStart.tm_gmtoff = 0;
  1437. tbStart.time = mktime(&tmStart);
  1438. tbStart.timezone = 0;
  1439. tbStart.millitm = 0;
  1440. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1441. if(DiffTimebWithNowSec(tbStart) <= 0)
  1442. result = NO;
  1443. else
  1444. result = YES;
  1445. }
  1446. else
  1447. {
  1448. DEBUG_WARN("Start date parsing error.\n");
  1449. }
  1450. return result;
  1451. }
  1452. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1453. {
  1454. int result = -1;
  1455. struct tm tmStart;
  1456. struct timeb tbStart;
  1457. struct tm tmStop;
  1458. struct timeb tbStop;
  1459. 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) &&
  1460. (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))
  1461. {
  1462. tmStart.tm_year -= 1900;
  1463. tmStart.tm_mon -= 1;
  1464. tbStart.time = mktime(&tmStart);
  1465. tbStart.millitm = 0;
  1466. tmStop.tm_year -= 1900;
  1467. tmStop.tm_mon -= 1;
  1468. tbStop.time = mktime(&tmStop);
  1469. tbStop.millitm = 0;
  1470. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1471. }
  1472. return result;
  1473. }
  1474. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1475. {
  1476. FILE *fp;
  1477. char profileFileName[128];
  1478. char *line = NULL;
  1479. size_t len = 0;
  1480. time_t CurrentTime;
  1481. struct tm *tmComposite;
  1482. struct StructChargingProfile maxProfile;
  1483. uint8_t limitMax=0;
  1484. int compositePeriodIdx = 0;
  1485. CurrentTime = time(NULL);
  1486. tmComposite=localtime(&CurrentTime);
  1487. 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);
  1488. if(isUnitA)
  1489. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1490. else
  1491. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1492. compositeProfile->ChargingSchedule.Duration = durationReq;
  1493. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1494. {
  1495. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1496. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1497. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1498. }
  1499. compositeProfile->ChargingProfileId = 0;
  1500. compositeProfile->StackLevel = 99 ;
  1501. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1502. maxProfile.ChargingProfileId = -1;
  1503. maxProfile.ChargingSchedule.Duration = -1;
  1504. system("rm -f /tmp/*.json");
  1505. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1506. // Search max profile
  1507. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1508. if((access(profileFileName, F_OK))!=-1)
  1509. {
  1510. fp = fopen(profileFileName, "r");
  1511. while(getline(&line, &len, fp) != -1)
  1512. {
  1513. json_object *obj = NULL;
  1514. obj = json_tokener_parse(line);
  1515. if(is_error(obj))
  1516. {
  1517. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1518. }
  1519. else
  1520. {
  1521. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1522. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1523. )
  1524. {
  1525. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1526. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1527. )
  1528. {
  1529. struct tm tmFrom, tmTo;
  1530. struct timeb tbFrom, tbTo;
  1531. 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) &&
  1532. (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))
  1533. {
  1534. tmFrom.tm_year -= 1900;
  1535. tmFrom.tm_mon -= 1;
  1536. tbFrom.time = mktime(&tmFrom);
  1537. tmTo.tm_year -= 1900;
  1538. tmTo.tm_mon -= 1;
  1539. tbTo.time = mktime(&tmTo);
  1540. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1541. {
  1542. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1543. {
  1544. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1545. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1546. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1547. }
  1548. maxProfile.ChargingProfileId = -1;
  1549. maxProfile.StackLevel = -1;
  1550. if(maxProfile.ChargingProfileId == -1)
  1551. DEBUG_INFO("MaxProfile found.\n");
  1552. else
  1553. DEBUG_INFO("MaxProfile updated.\n");
  1554. // Required item
  1555. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1556. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1557. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1558. if(isUnitA)
  1559. {
  1560. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1561. 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++)
  1562. {
  1563. 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"));
  1564. 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?
  1565. 3:
  1566. 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")));
  1567. 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")));
  1568. }
  1569. }
  1570. else
  1571. {
  1572. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1573. 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++)
  1574. {
  1575. 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"));
  1576. 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?
  1577. 3:
  1578. 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")));
  1579. 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));
  1580. }
  1581. }
  1582. // Optional item
  1583. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1584. {
  1585. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1586. }
  1587. else
  1588. {
  1589. sprintf((char*)maxProfile.ValidFrom, " ");
  1590. }
  1591. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1592. {
  1593. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1594. }
  1595. else
  1596. {
  1597. sprintf((char*)maxProfile.ValidTo, " ");
  1598. }
  1599. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1600. {
  1601. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1602. }
  1603. else
  1604. {
  1605. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1606. }
  1607. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1608. {
  1609. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1610. }
  1611. else
  1612. {
  1613. maxProfile.TransactionId = -1;
  1614. }
  1615. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1616. {
  1617. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1618. }
  1619. else
  1620. {
  1621. maxProfile.ChargingSchedule.Duration = 86400;
  1622. }
  1623. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1624. {
  1625. 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")));
  1626. }
  1627. else
  1628. {
  1629. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1630. }
  1631. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1632. {
  1633. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1634. }
  1635. else
  1636. {
  1637. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1638. }
  1639. }
  1640. }
  1641. }
  1642. else
  1643. {
  1644. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1645. {
  1646. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1647. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1648. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1649. }
  1650. maxProfile.ChargingProfileId = -1;
  1651. maxProfile.StackLevel = -1;
  1652. if(maxProfile.ChargingProfileId == -1)
  1653. DEBUG_INFO("MaxProfile found.\n");
  1654. else
  1655. DEBUG_INFO("MaxProfile updated.\n");
  1656. // Required item
  1657. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1658. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1659. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1660. if(isUnitA)
  1661. {
  1662. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1663. 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++)
  1664. {
  1665. 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"));
  1666. 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?
  1667. 3:
  1668. 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")));
  1669. 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")));
  1670. }
  1671. }
  1672. else
  1673. {
  1674. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1675. 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++)
  1676. {
  1677. 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"));
  1678. 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?
  1679. 3:
  1680. 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")));
  1681. 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));
  1682. }
  1683. }
  1684. // Optional item
  1685. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1686. {
  1687. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1688. }
  1689. else
  1690. {
  1691. sprintf((char*)maxProfile.ValidFrom, " ");
  1692. }
  1693. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1694. {
  1695. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1696. }
  1697. else
  1698. {
  1699. sprintf((char*)maxProfile.ValidTo, " ");
  1700. }
  1701. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1702. {
  1703. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1704. }
  1705. else
  1706. {
  1707. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1708. }
  1709. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1710. {
  1711. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1712. }
  1713. else
  1714. {
  1715. maxProfile.TransactionId = -1;
  1716. }
  1717. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1718. {
  1719. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1720. }
  1721. else
  1722. {
  1723. maxProfile.ChargingSchedule.Duration = 86400;
  1724. }
  1725. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1726. {
  1727. 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")));
  1728. }
  1729. else
  1730. {
  1731. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1732. }
  1733. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1734. {
  1735. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1736. }
  1737. else
  1738. {
  1739. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1740. }
  1741. }
  1742. }
  1743. }
  1744. json_object_put(obj);
  1745. }
  1746. fclose(fp);
  1747. /*
  1748. if(maxProfile.ChargingProfileId !=-1)
  1749. {
  1750. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1751. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1752. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1753. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1754. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1755. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1756. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1757. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1758. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1759. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1760. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1761. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1762. {
  1763. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1764. {
  1765. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1766. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1767. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1768. }
  1769. }
  1770. }
  1771. else
  1772. DEBUG_INFO("MaxProfile not found.\n");
  1773. DEBUG_INFO("------------------------------------\n");*/
  1774. }
  1775. if(maxProfile.ChargingProfileId != -1)
  1776. {
  1777. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1778. {
  1779. if(maxProfile.ChargingSchedule.Duration != -1)
  1780. {
  1781. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1782. 0:
  1783. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1784. }
  1785. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1786. {
  1787. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1788. {
  1789. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1790. 0:
  1791. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1792. if(idxPeriod > 0)
  1793. {
  1794. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1795. {
  1796. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1797. }
  1798. }
  1799. }
  1800. }
  1801. }
  1802. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1803. {
  1804. if(maxProfile.ChargingSchedule.Duration != -1)
  1805. {
  1806. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1807. }
  1808. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1809. {
  1810. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1811. {
  1812. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1813. if(idxPeriod > 0)
  1814. {
  1815. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1816. {
  1817. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1818. }
  1819. }
  1820. }
  1821. }
  1822. }
  1823. else
  1824. {
  1825. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1826. {
  1827. if(maxProfile.ChargingSchedule.Duration != -1)
  1828. {
  1829. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1830. 0:
  1831. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1832. }
  1833. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1834. {
  1835. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1836. {
  1837. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1838. 0:
  1839. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1840. if(idxPeriod > 0)
  1841. {
  1842. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1843. {
  1844. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1845. }
  1846. }
  1847. }
  1848. }
  1849. }
  1850. else
  1851. {
  1852. if(maxProfile.ChargingSchedule.Duration != -1)
  1853. {
  1854. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1855. 0:
  1856. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1857. }
  1858. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1859. {
  1860. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1861. {
  1862. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1863. 0:
  1864. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1865. if(idxPeriod > 0)
  1866. {
  1867. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1868. {
  1869. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1870. }
  1871. }
  1872. }
  1873. }
  1874. }
  1875. }
  1876. /*
  1877. DEBUG_INFO("MaxProfile after align.\n");
  1878. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1879. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1880. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1881. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1882. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1883. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1884. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1885. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1886. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1887. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1888. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1889. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1890. {
  1891. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1892. {
  1893. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1894. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1895. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1896. }
  1897. }
  1898. DEBUG_INFO("------------------------------------\n");*/
  1899. }
  1900. // Find each profile period quantity
  1901. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1902. {
  1903. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1904. limitMax = idx+1;
  1905. }
  1906. if(maxProfile.ChargingProfileId != -1)
  1907. {
  1908. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1909. {
  1910. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1911. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1912. (maxProfile.ChargingSchedule.Duration > 0))
  1913. {
  1914. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1915. {
  1916. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1917. compositePeriodIdx++;
  1918. }
  1919. else
  1920. {
  1921. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1922. }
  1923. }
  1924. }
  1925. }
  1926. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1927. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1928. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1929. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1930. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1931. {
  1932. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1933. {
  1934. compositeProfile->ChargingProfileId = 1;
  1935. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1936. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1937. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1938. }
  1939. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1940. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1941. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1942. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1943. }
  1944. if(line)
  1945. free(line);
  1946. }
  1947. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1948. {
  1949. FILE *fp;
  1950. char profileFileName[128];
  1951. char *line = NULL;
  1952. size_t len = 0;
  1953. time_t CurrentTime;
  1954. struct tm *tmComposite;
  1955. struct StructChargingProfile maxProfile;
  1956. struct StructChargingProfile defaultTxProfile;
  1957. struct StructChargingProfile txProfile;
  1958. struct StructChargingSchedulePeriod tmpPeriod;
  1959. uint8_t limitMax=0;
  1960. uint8_t limitDef=0;
  1961. uint8_t limitTx=0;
  1962. int compositePeriodIdx = 0;
  1963. CurrentTime = time(NULL);
  1964. tmComposite=localtime(&CurrentTime);
  1965. 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);
  1966. if(isUnitA)
  1967. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1968. else
  1969. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1970. compositeProfile->ChargingSchedule.Duration = durationReq;
  1971. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1972. {
  1973. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1974. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1975. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1976. }
  1977. compositeProfile->ChargingProfileId = 0;
  1978. compositeProfile->StackLevel = 99 ;
  1979. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1980. maxProfile.ChargingProfileId = -1;
  1981. defaultTxProfile.ChargingProfileId = -1;
  1982. txProfile.ChargingProfileId = -1;
  1983. maxProfile.ChargingSchedule.Duration = -1;
  1984. defaultTxProfile.ChargingSchedule.Duration = -1;
  1985. txProfile.ChargingSchedule.Duration = -1;
  1986. system("rm -f /tmp/*.json");
  1987. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1988. /*
  1989. * Search valid charging profile
  1990. */
  1991. //DEBUG_INFO("====================================\n");
  1992. // Search tx profile
  1993. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1994. if((access(profileFileName, F_OK))!=-1)
  1995. {
  1996. fp = fopen(profileFileName, "r");
  1997. while(getline(&line, &len, fp) != -1)
  1998. {
  1999. json_object *obj = NULL;
  2000. obj = json_tokener_parse(line);
  2001. if(is_error(obj))
  2002. {
  2003. DEBUG_ERROR("Parse txProfile from file error.\n");
  2004. }
  2005. else
  2006. {
  2007. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2008. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2009. )
  2010. {
  2011. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2012. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2013. )
  2014. {
  2015. struct tm tmFrom, tmTo;
  2016. struct timeb tbFrom, tbTo;
  2017. 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) &&
  2018. (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))
  2019. {
  2020. tmFrom.tm_year -= 1900;
  2021. tmFrom.tm_mon -= 1;
  2022. tbFrom.time = mktime(&tmFrom);
  2023. tmTo.tm_year -= 1900;
  2024. tmTo.tm_mon -= 1;
  2025. tbTo.time = mktime(&tmTo);
  2026. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2027. {
  2028. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2029. {
  2030. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2031. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2032. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2033. }
  2034. txProfile.ChargingProfileId = -1;
  2035. txProfile.StackLevel = -1;
  2036. if(txProfile.ChargingProfileId == -1)
  2037. DEBUG_INFO("TxProfile found.\n");
  2038. else
  2039. DEBUG_INFO("TxProfile updated.\n");
  2040. // Required item
  2041. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2042. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2043. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2044. if(isUnitA)
  2045. {
  2046. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2047. 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++)
  2048. {
  2049. 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"));
  2050. 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?
  2051. 3:
  2052. 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")));
  2053. 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")));
  2054. }
  2055. }
  2056. else
  2057. {
  2058. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2059. 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++)
  2060. {
  2061. 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"));
  2062. 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?
  2063. 3:
  2064. 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")));
  2065. 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));
  2066. }
  2067. }
  2068. // Optional item
  2069. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2070. {
  2071. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2072. }
  2073. else
  2074. {
  2075. sprintf((char*)txProfile.ValidFrom, " ");
  2076. }
  2077. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2078. {
  2079. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2080. }
  2081. else
  2082. {
  2083. sprintf((char*)txProfile.ValidTo, " ");
  2084. }
  2085. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2086. {
  2087. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2088. }
  2089. else
  2090. {
  2091. sprintf((char*)txProfile.RecurrencyKind, " ");
  2092. }
  2093. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2094. {
  2095. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2096. }
  2097. else
  2098. {
  2099. txProfile.TransactionId = -1;
  2100. }
  2101. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2102. {
  2103. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2104. }
  2105. else
  2106. {
  2107. txProfile.ChargingSchedule.Duration = 86400;
  2108. }
  2109. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2110. {
  2111. 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")));
  2112. }
  2113. else
  2114. {
  2115. 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));
  2116. }
  2117. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2118. {
  2119. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2120. }
  2121. else
  2122. {
  2123. txProfile.ChargingSchedule.MinChargingRate = -1;
  2124. }
  2125. }
  2126. }
  2127. }
  2128. else
  2129. {
  2130. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2131. {
  2132. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2133. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2134. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2135. }
  2136. txProfile.ChargingProfileId = -1;
  2137. txProfile.StackLevel = -1;
  2138. if(txProfile.ChargingProfileId == -1)
  2139. DEBUG_INFO("TxProfile found.\n");
  2140. else
  2141. DEBUG_INFO("TxProfile updated.\n");
  2142. // Required item
  2143. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2144. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2145. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2146. if(isUnitA)
  2147. {
  2148. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2149. 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++)
  2150. {
  2151. 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"));
  2152. 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?
  2153. 3:
  2154. 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")));
  2155. 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")));
  2156. }
  2157. }
  2158. else
  2159. {
  2160. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2161. 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++)
  2162. {
  2163. 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"));
  2164. 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?
  2165. 3:
  2166. 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")));
  2167. 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));
  2168. }
  2169. }
  2170. // Optional item
  2171. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2172. {
  2173. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2174. }
  2175. else
  2176. {
  2177. sprintf((char*)txProfile.ValidFrom, " ");
  2178. }
  2179. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2180. {
  2181. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2182. }
  2183. else
  2184. {
  2185. sprintf((char*)txProfile.ValidTo, " ");
  2186. }
  2187. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2188. {
  2189. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2190. }
  2191. else
  2192. {
  2193. sprintf((char*)txProfile.RecurrencyKind, " ");
  2194. }
  2195. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2196. {
  2197. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2198. }
  2199. else
  2200. {
  2201. txProfile.TransactionId = -1;
  2202. }
  2203. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2204. {
  2205. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2206. }
  2207. else
  2208. {
  2209. txProfile.ChargingSchedule.Duration = 86400;
  2210. }
  2211. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2212. {
  2213. 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")));
  2214. }
  2215. else
  2216. {
  2217. 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));
  2218. }
  2219. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2220. {
  2221. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2222. }
  2223. else
  2224. {
  2225. txProfile.ChargingSchedule.MinChargingRate = -1;
  2226. }
  2227. }
  2228. }
  2229. }
  2230. json_object_put(obj);
  2231. }
  2232. fclose(fp);
  2233. /*
  2234. if(txProfile.ChargingProfileId != -1)
  2235. {
  2236. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2237. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2238. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2239. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2240. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2241. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2242. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2243. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2244. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2245. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2246. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2247. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2248. {
  2249. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2250. {
  2251. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2252. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2253. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2254. }
  2255. }
  2256. }
  2257. else
  2258. DEBUG_INFO("TxProfile not found.\n");*/
  2259. }
  2260. // Search default tx profile
  2261. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2262. if((access(profileFileName, F_OK))==-1)
  2263. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2264. if((access(profileFileName, F_OK))!=-1)
  2265. {
  2266. fp = fopen(profileFileName, "r");
  2267. while(getline(&line, &len, fp) != -1)
  2268. {
  2269. json_object *obj = NULL;
  2270. obj = json_tokener_parse(line);
  2271. if(is_error(obj))
  2272. {
  2273. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2274. }
  2275. else
  2276. {
  2277. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2278. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2279. )
  2280. {
  2281. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2282. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2283. )
  2284. {
  2285. struct tm tmFrom, tmTo;
  2286. struct timeb tbFrom, tbTo;
  2287. 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) &&
  2288. (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))
  2289. {
  2290. tmFrom.tm_year -= 1900;
  2291. tmFrom.tm_mon -= 1;
  2292. tbFrom.time = mktime(&tmFrom);
  2293. tmTo.tm_year -= 1900;
  2294. tmTo.tm_mon -= 1;
  2295. tbTo.time = mktime(&tmTo);
  2296. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2297. {
  2298. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2299. {
  2300. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2301. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2302. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2303. }
  2304. defaultTxProfile.ChargingProfileId = -1;
  2305. defaultTxProfile.StackLevel = -1;
  2306. if(defaultTxProfile.ChargingProfileId == -1)
  2307. DEBUG_INFO("TxDefaultProfile found.\n");
  2308. else
  2309. DEBUG_INFO("TxDefaultProfile updated.\n");
  2310. // Required item
  2311. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2312. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2313. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2314. if(isUnitA)
  2315. {
  2316. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2317. 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++)
  2318. {
  2319. 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"));
  2320. 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?
  2321. 3:
  2322. 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")));
  2323. 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")));
  2324. }
  2325. }
  2326. else
  2327. {
  2328. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2329. 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++)
  2330. {
  2331. 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"));
  2332. 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?
  2333. 3:
  2334. 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")));
  2335. 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));
  2336. }
  2337. }
  2338. // Optional item
  2339. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2340. {
  2341. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2342. }
  2343. else
  2344. {
  2345. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2346. }
  2347. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2348. {
  2349. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2350. }
  2351. else
  2352. {
  2353. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2354. }
  2355. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2356. {
  2357. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2358. }
  2359. else
  2360. {
  2361. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2362. }
  2363. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2364. {
  2365. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2366. }
  2367. else
  2368. {
  2369. defaultTxProfile.TransactionId = -1;
  2370. }
  2371. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2372. {
  2373. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2374. }
  2375. else
  2376. {
  2377. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2378. }
  2379. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2380. {
  2381. 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")));
  2382. }
  2383. else
  2384. {
  2385. 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));
  2386. }
  2387. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2388. {
  2389. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2390. }
  2391. else
  2392. {
  2393. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2394. }
  2395. }
  2396. }
  2397. }
  2398. else
  2399. {
  2400. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2401. {
  2402. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2403. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2404. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2405. }
  2406. defaultTxProfile.ChargingProfileId = -1;
  2407. defaultTxProfile.StackLevel = -1;
  2408. if(defaultTxProfile.ChargingProfileId == -1)
  2409. DEBUG_INFO("TxDefaultProfile found.\n");
  2410. else
  2411. DEBUG_INFO("TxDefaultProfile updated.\n");
  2412. // Required item
  2413. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2414. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2415. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2416. if(isUnitA)
  2417. {
  2418. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2419. 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++)
  2420. {
  2421. 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"));
  2422. 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?
  2423. 3:
  2424. 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")));
  2425. 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")));
  2426. }
  2427. }
  2428. else
  2429. {
  2430. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2431. 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++)
  2432. {
  2433. 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"));
  2434. 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?
  2435. 3:
  2436. 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")));
  2437. 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));
  2438. }
  2439. }
  2440. // Optional item
  2441. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2442. {
  2443. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2444. }
  2445. else
  2446. {
  2447. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2448. }
  2449. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2450. {
  2451. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2452. }
  2453. else
  2454. {
  2455. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2456. }
  2457. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2458. {
  2459. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2460. }
  2461. else
  2462. {
  2463. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2464. }
  2465. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2466. {
  2467. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2468. }
  2469. else
  2470. {
  2471. defaultTxProfile.TransactionId = -1;
  2472. }
  2473. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2474. {
  2475. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2476. }
  2477. else
  2478. {
  2479. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2480. }
  2481. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2482. {
  2483. 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")));
  2484. }
  2485. else
  2486. {
  2487. 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));
  2488. }
  2489. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2490. {
  2491. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2492. }
  2493. else
  2494. {
  2495. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2496. }
  2497. }
  2498. }
  2499. }
  2500. json_object_put(obj);
  2501. }
  2502. fclose(fp);
  2503. /*
  2504. if(defaultTxProfile.ChargingProfileId != -1)
  2505. {
  2506. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2507. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2508. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2509. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2510. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2511. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2512. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2513. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2514. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2515. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2516. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2517. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2518. {
  2519. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2520. {
  2521. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2522. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2523. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2524. }
  2525. }
  2526. }
  2527. else
  2528. DEBUG_INFO("TxDefaultProfile not found.\n");
  2529. DEBUG_INFO("------------------------------------\n");*/
  2530. }
  2531. // Search max profile
  2532. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2533. if((access(profileFileName, F_OK))!=-1)
  2534. {
  2535. fp = fopen(profileFileName, "r");
  2536. while(getline(&line, &len, fp) != -1)
  2537. {
  2538. json_object *obj = NULL;
  2539. obj = json_tokener_parse(line);
  2540. if(is_error(obj))
  2541. {
  2542. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2543. }
  2544. else
  2545. {
  2546. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2547. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2548. )
  2549. {
  2550. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2551. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2552. )
  2553. {
  2554. struct tm tmFrom, tmTo;
  2555. struct timeb tbFrom, tbTo;
  2556. 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) &&
  2557. (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))
  2558. {
  2559. tmFrom.tm_year -= 1900;
  2560. tmFrom.tm_mon -= 1;
  2561. tbFrom.time = mktime(&tmFrom);
  2562. tmTo.tm_year -= 1900;
  2563. tmTo.tm_mon -= 1;
  2564. tbTo.time = mktime(&tmTo);
  2565. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2566. {
  2567. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2568. {
  2569. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2570. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2571. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2572. }
  2573. maxProfile.ChargingProfileId = -1;
  2574. maxProfile.StackLevel = -1;
  2575. if(maxProfile.ChargingProfileId == -1)
  2576. DEBUG_INFO("MaxProfile found.\n");
  2577. else
  2578. DEBUG_INFO("MaxProfile updated.\n");
  2579. // Required item
  2580. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2581. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2582. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2583. if(isUnitA)
  2584. {
  2585. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2586. 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++)
  2587. {
  2588. 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"));
  2589. 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?
  2590. 3:
  2591. 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")));
  2592. 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")));
  2593. }
  2594. }
  2595. else
  2596. {
  2597. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2598. 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++)
  2599. {
  2600. 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"));
  2601. 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?
  2602. 3:
  2603. 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")));
  2604. 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));
  2605. }
  2606. }
  2607. // Optional item
  2608. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2609. {
  2610. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2611. }
  2612. else
  2613. {
  2614. sprintf((char*)maxProfile.ValidFrom, " ");
  2615. }
  2616. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2617. {
  2618. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2619. }
  2620. else
  2621. {
  2622. sprintf((char*)maxProfile.ValidTo, " ");
  2623. }
  2624. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2625. {
  2626. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2627. }
  2628. else
  2629. {
  2630. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2631. }
  2632. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2633. {
  2634. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2635. }
  2636. else
  2637. {
  2638. maxProfile.TransactionId = -1;
  2639. }
  2640. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2641. {
  2642. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2643. }
  2644. else
  2645. {
  2646. maxProfile.ChargingSchedule.Duration = 86400;
  2647. }
  2648. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2649. {
  2650. 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")));
  2651. }
  2652. else
  2653. {
  2654. 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));
  2655. }
  2656. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2657. {
  2658. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2659. }
  2660. else
  2661. {
  2662. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2663. }
  2664. }
  2665. }
  2666. }
  2667. else
  2668. {
  2669. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2670. {
  2671. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2672. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2673. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2674. }
  2675. maxProfile.ChargingProfileId = -1;
  2676. maxProfile.StackLevel = -1;
  2677. if(maxProfile.ChargingProfileId == -1)
  2678. DEBUG_INFO("MaxProfile found.\n");
  2679. else
  2680. DEBUG_INFO("MaxProfile updated.\n");
  2681. // Required item
  2682. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2683. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2684. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2685. if(isUnitA)
  2686. {
  2687. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2688. 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++)
  2689. {
  2690. 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"));
  2691. 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?
  2692. 3:
  2693. 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")));
  2694. 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")));
  2695. }
  2696. }
  2697. else
  2698. {
  2699. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2700. 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++)
  2701. {
  2702. 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"));
  2703. 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?
  2704. 3:
  2705. 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")));
  2706. 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));
  2707. }
  2708. }
  2709. // Optional item
  2710. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2711. {
  2712. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2713. }
  2714. else
  2715. {
  2716. sprintf((char*)maxProfile.ValidFrom, " ");
  2717. }
  2718. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2719. {
  2720. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2721. }
  2722. else
  2723. {
  2724. sprintf((char*)maxProfile.ValidTo, " ");
  2725. }
  2726. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2727. {
  2728. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2729. }
  2730. else
  2731. {
  2732. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2733. }
  2734. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2735. {
  2736. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2737. }
  2738. else
  2739. {
  2740. maxProfile.TransactionId = -1;
  2741. }
  2742. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2743. {
  2744. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2745. }
  2746. else
  2747. {
  2748. maxProfile.ChargingSchedule.Duration = 86400;
  2749. }
  2750. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2751. {
  2752. 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")));
  2753. }
  2754. else
  2755. {
  2756. 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));
  2757. }
  2758. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2759. {
  2760. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2761. }
  2762. else
  2763. {
  2764. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2765. }
  2766. }
  2767. }
  2768. }
  2769. json_object_put(obj);
  2770. }
  2771. fclose(fp);
  2772. /*
  2773. if(maxProfile.ChargingProfileId !=-1)
  2774. {
  2775. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2776. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2777. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2778. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2779. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2780. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2781. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2782. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2783. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2784. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2785. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2786. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2787. {
  2788. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2789. {
  2790. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2791. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2792. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2793. }
  2794. }
  2795. }
  2796. else
  2797. DEBUG_INFO("MaxProfile not found.\n");
  2798. DEBUG_INFO("------------------------------------\n");*/
  2799. }
  2800. /*
  2801. * Align found profile start schedule & periods
  2802. */
  2803. //DEBUG_INFO("====================================\n");
  2804. /*
  2805. // For local test usage, force modify found profile start schedule info
  2806. 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);
  2807. 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);
  2808. 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);
  2809. */
  2810. if(txProfile.ChargingProfileId != -1)
  2811. {
  2812. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2813. {
  2814. if(txProfile.ChargingSchedule.Duration != -1)
  2815. {
  2816. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2817. 0:
  2818. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2819. }
  2820. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2821. {
  2822. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2823. {
  2824. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2825. 0:
  2826. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2827. if(idxPeriod > 0)
  2828. {
  2829. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2830. {
  2831. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2832. }
  2833. }
  2834. }
  2835. }
  2836. }
  2837. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2838. {
  2839. if(txProfile.ChargingSchedule.Duration != -1)
  2840. {
  2841. 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?
  2842. 0:
  2843. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2844. }
  2845. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2846. {
  2847. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2848. {
  2849. 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?
  2850. 0:
  2851. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2852. if(idxPeriod > 0)
  2853. {
  2854. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2855. {
  2856. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2857. }
  2858. }
  2859. }
  2860. }
  2861. }
  2862. else
  2863. {
  2864. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2865. {
  2866. if(txProfile.ChargingSchedule.Duration != -1)
  2867. {
  2868. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2869. 0:
  2870. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2871. }
  2872. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2873. {
  2874. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2875. {
  2876. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2877. 0:
  2878. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2879. if(idxPeriod > 0)
  2880. {
  2881. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2882. {
  2883. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2884. }
  2885. }
  2886. }
  2887. }
  2888. }
  2889. else
  2890. {
  2891. if(txProfile.ChargingSchedule.Duration != -1)
  2892. {
  2893. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2894. 0:
  2895. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2896. }
  2897. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2898. {
  2899. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2900. {
  2901. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2902. 0:
  2903. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2904. if(idxPeriod > 0)
  2905. {
  2906. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2907. {
  2908. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2909. }
  2910. }
  2911. }
  2912. }
  2913. }
  2914. }
  2915. /*
  2916. DEBUG_INFO("txProfile after align.\n");
  2917. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2918. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2919. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2920. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2921. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2922. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2923. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2924. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2925. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2926. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2927. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2928. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2929. {
  2930. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2931. {
  2932. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2933. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2934. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2935. }
  2936. }*/
  2937. }
  2938. if(defaultTxProfile.ChargingProfileId != -1)
  2939. {
  2940. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2941. {
  2942. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2943. {
  2944. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2945. 0:
  2946. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2947. }
  2948. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2949. {
  2950. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2951. {
  2952. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2953. 0:
  2954. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2955. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2956. {
  2957. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2958. }
  2959. if(idxPeriod > 0)
  2960. {
  2961. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2962. {
  2963. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2964. }
  2965. }
  2966. }
  2967. }
  2968. }
  2969. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2970. {
  2971. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2972. {
  2973. 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?
  2974. 0:
  2975. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2976. }
  2977. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2978. {
  2979. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2980. {
  2981. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !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?
  2982. 0:
  2983. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2984. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2985. {
  2986. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2987. }
  2988. if(idxPeriod > 0)
  2989. {
  2990. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2991. {
  2992. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2993. }
  2994. }
  2995. }
  2996. }
  2997. }
  2998. else
  2999. {
  3000. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3001. {
  3002. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3003. {
  3004. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  3005. 0:
  3006. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  3007. }
  3008. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3009. {
  3010. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3011. {
  3012. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  3013. 0:
  3014. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  3015. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  3016. {
  3017. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3018. }
  3019. if(idxPeriod > 0)
  3020. {
  3021. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3022. {
  3023. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3024. }
  3025. }
  3026. }
  3027. }
  3028. }
  3029. else
  3030. {
  3031. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3032. {
  3033. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  3034. 0:
  3035. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  3036. }
  3037. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3038. {
  3039. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3040. {
  3041. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  3042. 0:
  3043. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  3044. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  3045. {
  3046. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3047. }
  3048. if(idxPeriod > 0)
  3049. {
  3050. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3051. {
  3052. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3053. }
  3054. }
  3055. }
  3056. }
  3057. }
  3058. }
  3059. /*
  3060. DEBUG_INFO("defaultTxProfile after align.\n");
  3061. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3062. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3063. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3064. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3065. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3066. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3067. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3068. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3069. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3070. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3071. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3072. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3073. {
  3074. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3075. {
  3076. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3077. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3078. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3079. }
  3080. }
  3081. DEBUG_INFO("------------------------------------\n");*/
  3082. }
  3083. if(maxProfile.ChargingProfileId != -1)
  3084. {
  3085. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3086. {
  3087. if(maxProfile.ChargingSchedule.Duration != -1)
  3088. {
  3089. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  3090. 0:
  3091. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  3092. }
  3093. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3094. {
  3095. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3096. {
  3097. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  3098. 0:
  3099. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  3100. if(idxPeriod > 0)
  3101. {
  3102. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3103. {
  3104. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3105. }
  3106. }
  3107. }
  3108. }
  3109. }
  3110. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3111. {
  3112. if(maxProfile.ChargingSchedule.Duration != -1)
  3113. {
  3114. 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?
  3115. 0:
  3116. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  3117. }
  3118. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3119. {
  3120. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3121. {
  3122. 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?
  3123. 0:
  3124. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  3125. if(idxPeriod > 0)
  3126. {
  3127. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3128. {
  3129. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3130. }
  3131. }
  3132. }
  3133. }
  3134. }
  3135. else
  3136. {
  3137. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3138. {
  3139. if(maxProfile.ChargingSchedule.Duration != -1)
  3140. {
  3141. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  3142. 0:
  3143. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  3144. }
  3145. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3146. {
  3147. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3148. {
  3149. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  3150. 0:
  3151. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  3152. if(idxPeriod > 0)
  3153. {
  3154. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3155. {
  3156. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3157. }
  3158. }
  3159. }
  3160. }
  3161. }
  3162. else
  3163. {
  3164. if(maxProfile.ChargingSchedule.Duration != -1)
  3165. {
  3166. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  3167. 0:
  3168. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  3169. }
  3170. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3171. {
  3172. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3173. {
  3174. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  3175. 0:
  3176. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  3177. if(idxPeriod > 0)
  3178. {
  3179. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3180. {
  3181. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3182. }
  3183. }
  3184. }
  3185. }
  3186. }
  3187. }
  3188. /*
  3189. DEBUG_INFO("MaxProfile after align.\n");
  3190. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3191. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3192. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3193. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3194. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3195. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3196. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3197. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3198. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3199. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3200. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3201. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3202. {
  3203. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3204. {
  3205. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3206. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3207. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3208. }
  3209. }
  3210. DEBUG_INFO("------------------------------------\n");*/
  3211. }
  3212. /*
  3213. * Merge to conposite schedule
  3214. */
  3215. //DEBUG_INFO("====================================\n");
  3216. // Find each profile period quantity
  3217. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3218. {
  3219. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3220. limitMax = idx+1;
  3221. }
  3222. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3223. {
  3224. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3225. limitDef = idx+1;
  3226. }
  3227. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3228. {
  3229. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3230. limitTx = idx+1;
  3231. }
  3232. // TxProfile found, composite schedule based on it
  3233. if(txProfile.ChargingProfileId != -1)
  3234. {
  3235. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3236. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3237. {
  3238. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3239. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3240. (txProfile.ChargingSchedule.Duration > 0))
  3241. {
  3242. if(maxProfile.ChargingProfileId != -1)
  3243. {
  3244. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3245. {
  3246. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3247. {
  3248. if((maxProfile.ChargingSchedule.Duration > 0))
  3249. {
  3250. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3251. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3252. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3253. }
  3254. else
  3255. {
  3256. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3257. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3258. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3259. }
  3260. }
  3261. if(idxMaxPeriod == (limitMax-1))
  3262. {
  3263. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3264. {
  3265. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3266. {
  3267. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3268. compositePeriodIdx++;
  3269. }
  3270. else
  3271. {
  3272. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3273. }
  3274. }
  3275. }
  3276. }
  3277. }
  3278. else
  3279. {
  3280. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3281. {
  3282. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3283. compositePeriodIdx++;
  3284. }
  3285. else
  3286. {
  3287. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3288. }
  3289. }
  3290. }
  3291. if(idxTxPeriod == (limitTx-1))
  3292. {
  3293. if(defaultTxProfile.ChargingProfileId != -1)
  3294. {
  3295. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  3296. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3297. {
  3298. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3299. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3300. (defaultTxProfile.ChargingSchedule.Duration>0))
  3301. {
  3302. if(maxProfile.ChargingProfileId != -1)
  3303. {
  3304. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3305. {
  3306. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3307. {
  3308. if((maxProfile.ChargingSchedule.Duration > 0))
  3309. {
  3310. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3311. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3312. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3313. }
  3314. else
  3315. {
  3316. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3317. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3318. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3319. }
  3320. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3321. {
  3322. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3323. {
  3324. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3325. compositePeriodIdx++;
  3326. }
  3327. else
  3328. {
  3329. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3330. }
  3331. }
  3332. // Delete duplicate period
  3333. if(compositePeriodIdx > 1)
  3334. {
  3335. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3336. {
  3337. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3338. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3339. compositePeriodIdx -= 1;
  3340. }
  3341. }
  3342. }
  3343. else
  3344. {
  3345. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3346. {
  3347. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3348. compositePeriodIdx++;
  3349. }
  3350. else
  3351. {
  3352. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3353. }
  3354. break;
  3355. }
  3356. }
  3357. }
  3358. else
  3359. {
  3360. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3361. {
  3362. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3363. compositePeriodIdx++;
  3364. }
  3365. else
  3366. {
  3367. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3368. }
  3369. }
  3370. }
  3371. }
  3372. }
  3373. }
  3374. }
  3375. }
  3376. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3377. else if(defaultTxProfile.ChargingProfileId != -1)
  3378. {
  3379. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3380. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3381. {
  3382. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3383. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3384. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3385. {
  3386. if(maxProfile.ChargingProfileId != -1)
  3387. {
  3388. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3389. {
  3390. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3391. {
  3392. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3393. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3394. if((maxProfile.ChargingSchedule.Duration > 0))
  3395. {
  3396. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3397. }
  3398. else
  3399. {
  3400. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3401. }
  3402. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3403. {
  3404. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3405. {
  3406. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3407. compositePeriodIdx++;
  3408. }
  3409. else
  3410. {
  3411. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3412. }
  3413. }
  3414. // Delete duplicate period
  3415. if(compositePeriodIdx > 1)
  3416. {
  3417. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3418. {
  3419. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3420. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3421. compositePeriodIdx -= 1;
  3422. }
  3423. }
  3424. }
  3425. else
  3426. {
  3427. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3428. {
  3429. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3430. compositePeriodIdx++;
  3431. }
  3432. else
  3433. {
  3434. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3435. }
  3436. break;
  3437. }
  3438. }
  3439. }
  3440. else
  3441. {
  3442. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3443. {
  3444. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3445. compositePeriodIdx++;
  3446. }
  3447. else
  3448. {
  3449. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3450. }
  3451. }
  3452. }
  3453. }
  3454. }
  3455. // Fill other period by MaxProfile
  3456. if(maxProfile.ChargingProfileId != -1)
  3457. {
  3458. if(compositePeriodIdx==0)
  3459. {
  3460. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3461. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3462. {
  3463. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3464. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3465. (maxProfile.ChargingSchedule.Duration > 0))
  3466. {
  3467. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3468. {
  3469. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3470. compositePeriodIdx++;
  3471. }
  3472. else
  3473. {
  3474. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3475. }
  3476. }
  3477. }
  3478. }
  3479. else
  3480. {
  3481. int lastCompositePeriodIdx = compositePeriodIdx;
  3482. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3483. {
  3484. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3485. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3486. (maxProfile.ChargingSchedule.Duration > 0))
  3487. {
  3488. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3489. {
  3490. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3491. {
  3492. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3493. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3494. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3495. }
  3496. else
  3497. {
  3498. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3499. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3500. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3501. }
  3502. }
  3503. if(tmpPeriod.Limit != -1)
  3504. {
  3505. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3506. {
  3507. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3508. {
  3509. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3510. compositePeriodIdx++;
  3511. }
  3512. else
  3513. {
  3514. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3515. }
  3516. }
  3517. // Delete duplicate period
  3518. if(compositePeriodIdx > 1)
  3519. {
  3520. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3521. {
  3522. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3523. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3524. compositePeriodIdx -= 1;
  3525. }
  3526. }
  3527. }
  3528. }
  3529. }
  3530. }
  3531. }
  3532. compositeProfile->ChargingSchedule.Duration = durationReq;
  3533. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3534. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3535. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3536. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3537. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3538. {
  3539. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3540. {
  3541. compositeProfile->ChargingProfileId = 1;
  3542. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3543. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3544. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3545. }
  3546. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3547. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3548. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3549. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3550. }
  3551. if(line)
  3552. free(line);
  3553. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3554. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3555. }
  3556. //==========================================
  3557. // Init all share memory
  3558. //==========================================
  3559. int InitShareMemory()
  3560. {
  3561. int result = PASS;
  3562. int MeterSMId;
  3563. //creat ShmSysConfigAndInfo
  3564. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3565. {
  3566. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3567. result = FAIL;
  3568. }
  3569. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3570. {
  3571. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3572. result = FAIL;
  3573. }
  3574. else
  3575. {}
  3576. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3577. {
  3578. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3579. result = FAIL;
  3580. }
  3581. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3582. {
  3583. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3584. result = FAIL;
  3585. }
  3586. else
  3587. {}
  3588. //creat ShmPsuData
  3589. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3590. {
  3591. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3592. result = FAIL;
  3593. }
  3594. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3595. {
  3596. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3597. result = FAIL;
  3598. }
  3599. else
  3600. {}
  3601. //creat ShmOCPP16Data
  3602. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3603. {
  3604. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3605. result = FAIL;
  3606. }
  3607. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3608. {
  3609. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3610. result = FAIL;
  3611. }
  3612. else
  3613. {}
  3614. /****************************** For Initial Settings************************************************/
  3615. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3616. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3617. // allocate Configuration memory address
  3618. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3619. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3620. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3621. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3622. //offline MeterValue Interval
  3623. TempMeterValueInterval = 0;
  3624. return result;
  3625. }
  3626. int ProcessShareMemory()
  3627. {
  3628. int result = PASS;
  3629. if(InitShareMemory() == FAIL)
  3630. {
  3631. DEBUG_ERROR("InitShareMemory NG\n");
  3632. if(ShmStatusCodeData!=NULL)
  3633. {
  3634. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3635. }
  3636. result = FAIL;
  3637. }
  3638. // Model name parsing
  3639. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3640. {
  3641. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3642. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3643. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3644. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3645. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3646. ) // 'D' means DC
  3647. {
  3648. // DO series
  3649. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3650. {
  3651. SystemInitial += 1;
  3652. gunTotalNumber += 1;
  3653. gunType[gun_index] = GUN_TYPE_DO;
  3654. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3655. {
  3656. case Gun_Type_Chademo:
  3657. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3658. break;
  3659. case Gun_Type_CCS_2:
  3660. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3661. break;
  3662. case Gun_Type_GB:
  3663. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3664. break;
  3665. case Gun_Type_AC:
  3666. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3667. break;
  3668. default:
  3669. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3670. break;
  3671. }
  3672. }
  3673. }
  3674. else
  3675. {
  3676. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3677. {
  3678. SystemInitial += 1;
  3679. gunTotalNumber += 1;
  3680. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3681. {
  3682. case Gun_Type_Chademo:
  3683. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3684. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3685. break;
  3686. case Gun_Type_CCS_2:
  3687. gunType[gun_index] = GUN_TYPE_CCS;
  3688. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3689. break;
  3690. case Gun_Type_GB:
  3691. gunType[gun_index] = GUN_TYPE_GBT;
  3692. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3693. break;
  3694. case Gun_Type_AC:
  3695. gunType[gun_index] = GUN_TYPE_AC;
  3696. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3697. break;
  3698. default:
  3699. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3700. break;
  3701. }
  3702. }
  3703. }
  3704. }
  3705. else
  3706. {
  3707. DEBUG_ERROR("Model name parsing fail.\n");
  3708. result = FAIL;
  3709. }
  3710. if(result != PASS)sleep(5);
  3711. return result;
  3712. }
  3713. void checkRemoteStart(uint8_t connectorIdInt)
  3714. {
  3715. uint8_t tempIndex;
  3716. int result = PASS;
  3717. char cmdBuf[512];
  3718. //check Transaction active
  3719. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3720. {
  3721. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3722. {
  3723. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3724. }
  3725. else
  3726. {
  3727. tempIndex = connectorIdInt -1;
  3728. }
  3729. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3730. {
  3731. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3732. {
  3733. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3734. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3735. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3736. {
  3737. //Reserved
  3738. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3739. }
  3740. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3741. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3742. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3743. {
  3744. //Reserved
  3745. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3746. result = FAIL;
  3747. goto end;
  3748. }
  3749. else
  3750. {
  3751. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3752. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3753. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3754. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3755. {
  3756. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  3757. result = FAIL;
  3758. goto end;
  3759. }
  3760. }//END FOR ELSE
  3761. }
  3762. }// END FOR CHAdeMO_QUANTITY
  3763. }
  3764. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3765. {
  3766. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3767. {
  3768. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3769. }
  3770. else
  3771. {
  3772. tempIndex = connectorIdInt -1;
  3773. }
  3774. for (int index = 0; index < CCS_QUANTITY; index++)
  3775. {
  3776. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3777. {
  3778. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3779. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3780. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3781. {
  3782. //Reserved
  3783. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3784. }
  3785. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3786. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3787. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3788. {
  3789. //Reserved
  3790. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3791. result = FAIL;
  3792. goto end;
  3793. }
  3794. else
  3795. {
  3796. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3797. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3798. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3799. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3800. {
  3801. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3802. result = FAIL;
  3803. goto end;
  3804. }
  3805. }// END FOR ELSE
  3806. }
  3807. }// END FOR CCS_QUANTITY
  3808. }
  3809. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3810. {
  3811. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3812. {
  3813. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3814. }
  3815. else
  3816. {
  3817. tempIndex = connectorIdInt -1;
  3818. }
  3819. for (int index = 0; index < GB_QUANTITY; index++)
  3820. {
  3821. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3822. {
  3823. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3824. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3825. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3826. {
  3827. //Reserved
  3828. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3829. }
  3830. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3831. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3832. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3833. {
  3834. //Reserved
  3835. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3836. result = FAIL;
  3837. goto end;
  3838. }
  3839. else
  3840. {
  3841. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3842. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3843. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3844. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3845. {
  3846. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  3847. result = FAIL;
  3848. goto end;
  3849. }
  3850. }// END FOR ELSE
  3851. }
  3852. } // END FOR GB_QUANTITY
  3853. }
  3854. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3855. {
  3856. tempIndex = connectorIdInt -1;
  3857. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3858. {
  3859. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3860. {
  3861. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3862. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3863. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3864. {
  3865. //Reserved
  3866. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3867. }
  3868. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3869. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3870. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3871. {
  3872. //Reserved
  3873. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3874. result = FAIL;
  3875. goto end;
  3876. }
  3877. else
  3878. {
  3879. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3880. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3881. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3882. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3883. {
  3884. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  3885. result = FAIL;
  3886. goto end;
  3887. }
  3888. }// END FOR ELSE
  3889. }
  3890. } // END FOR GB_QUANTITY
  3891. }
  3892. else
  3893. {
  3894. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3895. {
  3896. tempIndex = 2;
  3897. }
  3898. else
  3899. {
  3900. tempIndex = connectorIdInt -1;
  3901. }
  3902. for (int index = 0; index < AC_QUANTITY; index++)
  3903. {
  3904. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3905. {
  3906. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3907. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3908. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3909. {
  3910. //Reserved
  3911. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3912. }
  3913. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3914. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3915. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3916. {
  3917. //Reserved
  3918. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3919. result = FAIL;
  3920. goto end;
  3921. }
  3922. else
  3923. {
  3924. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3925. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3926. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3927. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3928. {
  3929. DEBUG_WARN("AC connector not allow start cause busy.\n");
  3930. result = FAIL;
  3931. goto end;
  3932. }
  3933. }//END FOR ELSE
  3934. }
  3935. }// END FOR AC_QUANTITY
  3936. }
  3937. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3938. {
  3939. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3940. {
  3941. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  3942. {
  3943. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3944. system(cmdBuf);
  3945. }
  3946. }
  3947. else
  3948. {
  3949. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3950. result = FAIL;
  3951. }
  3952. }
  3953. end:
  3954. if(result == PASS)
  3955. {
  3956. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3957. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3958. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3959. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3960. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3961. }
  3962. }
  3963. void CheckSystemValue(void)
  3964. {
  3965. char filenmae[100]={0};
  3966. char str[100]={0};
  3967. int tempIndex = 0;
  3968. //===============================
  3969. // send Heartbeat
  3970. //===============================
  3971. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3972. {
  3973. //parameter for test
  3974. sendHeartbeatRequest(0);
  3975. //===========================
  3976. // Reset Waiting Time
  3977. //===========================
  3978. HeartBeatWithNOResponse += 1;
  3979. }
  3980. //===============================
  3981. // Credit deduct report
  3982. //===============================
  3983. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  3984. {
  3985. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo, ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice);
  3986. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  3987. }
  3988. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3989. {
  3990. OCPP_query_deduct_info();
  3991. refreshStartTimer(&clientTime.TcciQueryDeduct);
  3992. }
  3993. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3994. {
  3995. // ClockAlign MeterValue
  3996. 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))
  3997. {
  3998. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3999. {
  4000. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4001. {
  4002. tempIndex = ((gun_index==2) ? 1: 0);
  4003. }
  4004. else
  4005. {
  4006. tempIndex = gun_index;
  4007. }
  4008. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4009. {
  4010. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4011. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4012. {
  4013. reqClockAlignMeter[gun_index] = 1;
  4014. }
  4015. }// End for CHAdeMO
  4016. }
  4017. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4018. {
  4019. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4020. {
  4021. tempIndex = ((gun_index==2) ? 1: 0);
  4022. }
  4023. else
  4024. {
  4025. tempIndex = gun_index;
  4026. }
  4027. for (int index = 0; index < CCS_QUANTITY; index++)
  4028. {
  4029. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4030. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4031. {
  4032. reqClockAlignMeter[gun_index] = 1;
  4033. }
  4034. } // End for CCS
  4035. }
  4036. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4037. {
  4038. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4039. {
  4040. tempIndex = ((gun_index==2) ? 1: 0);
  4041. }
  4042. else
  4043. {
  4044. tempIndex = gun_index;
  4045. }
  4046. for (int index = 0; index < GB_QUANTITY; index++)
  4047. {
  4048. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4049. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4050. {
  4051. reqClockAlignMeter[gun_index] = 1;
  4052. }
  4053. }// End for GB
  4054. }
  4055. else if(gunType[gun_index] == GUN_TYPE_DO)
  4056. {
  4057. tempIndex = gun_index;
  4058. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4059. {
  4060. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4061. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4062. {
  4063. reqClockAlignMeter[gun_index] = 1;
  4064. }
  4065. }
  4066. }
  4067. else
  4068. {
  4069. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4070. {
  4071. tempIndex = 2;
  4072. }
  4073. else
  4074. {
  4075. tempIndex = gun_index;
  4076. }
  4077. for (int index = 0; index < AC_QUANTITY; index++)
  4078. {
  4079. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4080. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4081. {
  4082. reqClockAlignMeter[gun_index] = 1;
  4083. }
  4084. }//End for AC
  4085. }
  4086. }
  4087. }
  4088. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4089. {
  4090. //==========================================
  4091. // Check remote start without connector id
  4092. //==========================================
  4093. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4094. {
  4095. int connectorIdInt = -1;
  4096. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4097. {
  4098. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4099. {
  4100. connectorIdInt = (gun_index+1);
  4101. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4102. checkRemoteStart(connectorIdInt);
  4103. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4104. break;
  4105. }
  4106. }
  4107. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4108. {
  4109. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4110. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4111. }
  4112. }
  4113. //==========================================
  4114. // csu trigger DataTransferReq
  4115. //==========================================
  4116. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4117. {
  4118. sendDataTransferRequest(gun_index);
  4119. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4120. }
  4121. //==========================================
  4122. // CSU Trigger Authorize Request
  4123. //==========================================
  4124. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4125. {
  4126. sendAuthorizeRequest(0);
  4127. authorizeRetryTimes = authorizeRetryTimes + 1;
  4128. if(authorizeRetryTimes < 3)
  4129. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4130. }
  4131. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4132. {
  4133. authorizeRetryTimes = 0;
  4134. SetOcppConnStatus(FALSE);
  4135. server_sign = FALSE;
  4136. }
  4137. 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))
  4138. {
  4139. sendAuthorizeRequest(0);
  4140. }
  4141. //==========================================
  4142. // Charger start transaction
  4143. //==========================================
  4144. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4145. {
  4146. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4147. sendStartTransactionRequest(gun_index);
  4148. refreshStartTimer(&clientTime.StartTransaction);
  4149. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4150. storeTempStopTransaction(gun_index);
  4151. }
  4152. //==========================================
  4153. // Charger stop transaction
  4154. //==========================================
  4155. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4156. {
  4157. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4158. sendStopTransactionRequest(gun_index);
  4159. OCPP_updatePeriodEnergy(gun_index);
  4160. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4161. refreshStartTimer(&clientTime.StopTransaction);
  4162. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4163. }
  4164. //==========================================
  4165. // Charger status report
  4166. //==========================================
  4167. //--- Check Mode Change ---//
  4168. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4169. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4170. {
  4171. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4172. {
  4173. tempIndex = ((gun_index==2) ? 1: 0);
  4174. }
  4175. else
  4176. {
  4177. tempIndex = gun_index;
  4178. }
  4179. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4180. {
  4181. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4182. {
  4183. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4184. {
  4185. // Sent unplug message for California pricing logic
  4186. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  4187. {
  4188. uint8_t ts[20];
  4189. getNowDatetime(ts);
  4190. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4191. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4192. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4193. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4194. }
  4195. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4196. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4197. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4198. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4199. {
  4200. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4201. if((access(filenmae,F_OK))!=-1)
  4202. {
  4203. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4204. sprintf(str,"rm -f %s",filenmae);
  4205. system(str);
  4206. }
  4207. }
  4208. }
  4209. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4210. #if 1 // for TempStopTransaction
  4211. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4212. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4213. {
  4214. checkTempStopTransaction(gun_index);
  4215. }
  4216. #endif
  4217. }
  4218. }
  4219. }
  4220. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4221. {
  4222. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4223. {
  4224. tempIndex = ((gun_index==2) ? 1: 0);
  4225. }
  4226. else
  4227. {
  4228. tempIndex = gun_index;
  4229. }
  4230. for (int index = 0; index < CCS_QUANTITY; index++)
  4231. {
  4232. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4233. {
  4234. 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]*/ )
  4235. {
  4236. // Sent unplug message for California pricing logic
  4237. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  4238. {
  4239. uint8_t ts[20];
  4240. getNowDatetime(ts);
  4241. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4242. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4243. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4244. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4245. }
  4246. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4247. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4248. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4249. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4250. {
  4251. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4252. if((access(filenmae,F_OK))!=-1)
  4253. {
  4254. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4255. sprintf(str,"rm -f %s",filenmae);
  4256. system(str);
  4257. }
  4258. }
  4259. }
  4260. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4261. #if 1 // for TempStopTransaction
  4262. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4263. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4264. {
  4265. checkTempStopTransaction(gun_index);
  4266. }
  4267. #endif
  4268. }
  4269. }
  4270. }
  4271. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4272. {
  4273. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4274. {
  4275. tempIndex = ((gun_index==2) ? 1: 0);
  4276. }
  4277. else
  4278. {
  4279. tempIndex = gun_index;
  4280. }
  4281. for (int index = 0; index < GB_QUANTITY; index++)
  4282. {
  4283. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4284. {
  4285. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4286. {
  4287. // Sent unplug message for California pricing logic
  4288. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  4289. {
  4290. uint8_t ts[20];
  4291. getNowDatetime(ts);
  4292. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4293. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4294. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4295. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4296. }
  4297. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4298. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4299. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4300. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4301. {
  4302. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4303. if((access(filenmae,F_OK))!=-1)
  4304. {
  4305. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4306. sprintf(str,"rm -f %s",filenmae);
  4307. system(str);
  4308. }
  4309. }
  4310. }
  4311. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4312. #if 1 // for TempStopTransaction
  4313. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4314. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4315. {
  4316. checkTempStopTransaction(gun_index);
  4317. }
  4318. #endif
  4319. }
  4320. }
  4321. }
  4322. else if(gunType[gun_index] == GUN_TYPE_DO)
  4323. {
  4324. tempIndex = gun_index;
  4325. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4326. {
  4327. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4328. {
  4329. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4330. {
  4331. // Sent unplug message for California pricing logic
  4332. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  4333. {
  4334. uint8_t ts[20];
  4335. getNowDatetime(ts);
  4336. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4337. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4338. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4339. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4340. }
  4341. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4342. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4343. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4344. 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
  4345. {
  4346. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4347. if((access(filenmae,F_OK))!=-1)
  4348. {
  4349. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4350. sprintf(str,"rm -f %s",filenmae);
  4351. system(str);
  4352. }
  4353. }
  4354. }
  4355. 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);
  4356. #if 1 // for TempStopTransaction
  4357. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4358. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4359. {
  4360. checkTempStopTransaction(gun_index);
  4361. }
  4362. #endif
  4363. }
  4364. }
  4365. }
  4366. else
  4367. {
  4368. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4369. {
  4370. tempIndex = 2;
  4371. }
  4372. else
  4373. {
  4374. tempIndex = gun_index;
  4375. }
  4376. for (int index = 0; index < AC_QUANTITY; index++)
  4377. {
  4378. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4379. {
  4380. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4381. {
  4382. // Sent unplug message for California pricing logic
  4383. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  4384. {
  4385. uint8_t ts[20];
  4386. getNowDatetime(ts);
  4387. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4388. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4389. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4390. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4391. }
  4392. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4393. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4394. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4395. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4396. {
  4397. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4398. if((access(filenmae,F_OK))!=-1)
  4399. {
  4400. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4401. sprintf(str,"rm -f %s",filenmae);
  4402. system(str);
  4403. }
  4404. }
  4405. }
  4406. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4407. #if 1 // for TempStopTransaction
  4408. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4409. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4410. {
  4411. checkTempStopTransaction(gun_index);
  4412. }
  4413. #endif
  4414. }
  4415. }// END
  4416. }
  4417. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  4418. (
  4419. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4420. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4421. )
  4422. )
  4423. {
  4424. if(SystemInitial > 0)
  4425. SystemInitial -= 1;
  4426. sendStatusNotificationRequest(gun_index);
  4427. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4428. }
  4429. //==============================================
  4430. // CSU Trigger Smart Charging Profile
  4431. //==============================================
  4432. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4433. {
  4434. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4435. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4436. }
  4437. //==============================================
  4438. // Meter report
  4439. //==============================================
  4440. // Trigger MeterValue
  4441. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4442. {
  4443. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4444. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4445. }
  4446. // Clock-aligned Meter value
  4447. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4448. {
  4449. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4450. reqClockAlignMeter[gun_index] = 0;
  4451. }
  4452. // Sample period MeterValue
  4453. 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))))
  4454. {
  4455. //check Transaction active
  4456. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4457. {
  4458. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4459. {
  4460. tempIndex = ((gun_index==2) ? 1: 0);
  4461. }
  4462. else
  4463. {
  4464. tempIndex = gun_index;
  4465. }
  4466. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4467. {
  4468. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4469. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4470. {
  4471. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4472. {
  4473. reqSampleMeter[gun_index] = 1;
  4474. }
  4475. }
  4476. }// End for CHAdeMO
  4477. }
  4478. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4479. {
  4480. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4481. {
  4482. tempIndex = ((gun_index==2) ? 1: 0);
  4483. }
  4484. else
  4485. {
  4486. tempIndex = gun_index;
  4487. }
  4488. for (int index = 0; index < CCS_QUANTITY; index++)
  4489. {
  4490. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4491. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4492. {
  4493. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4494. {
  4495. reqSampleMeter[gun_index] = 1;
  4496. }
  4497. }
  4498. } // End for CCS
  4499. }
  4500. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4501. {
  4502. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4503. {
  4504. tempIndex = ((gun_index==2) ? 1: 0);
  4505. }
  4506. else
  4507. {
  4508. tempIndex = gun_index;
  4509. }
  4510. for (int index = 0; index < GB_QUANTITY; index++)
  4511. {
  4512. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4513. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4514. {
  4515. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4516. {
  4517. reqSampleMeter[gun_index] = 1;
  4518. }
  4519. }
  4520. }// End for GB
  4521. }
  4522. else if(gunType[gun_index] == GUN_TYPE_DO)
  4523. {
  4524. tempIndex = gun_index;
  4525. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4526. {
  4527. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4528. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4529. {
  4530. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4531. {
  4532. reqSampleMeter[gun_index] = 1;
  4533. }
  4534. }
  4535. }
  4536. }
  4537. else
  4538. {
  4539. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4540. {
  4541. tempIndex = 2;
  4542. }
  4543. else
  4544. {
  4545. tempIndex = gun_index;
  4546. }
  4547. for (int index = 0; index < AC_QUANTITY; index++)
  4548. {
  4549. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4550. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4551. {
  4552. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4553. {
  4554. reqSampleMeter[gun_index] = 1;
  4555. }
  4556. }
  4557. }//End for AC
  4558. }
  4559. if(reqSampleMeter[gun_index] == 1)
  4560. {
  4561. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4562. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4563. storeTempStopTransaction(gun_index);
  4564. reqSampleMeter[gun_index] = 0;
  4565. }
  4566. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4567. }
  4568. //==============================================
  4569. // Check Connector reserved
  4570. //==============================================
  4571. //===============================
  4572. // Check if Reserve is expired
  4573. //===============================
  4574. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4575. {
  4576. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4577. {
  4578. DEBUG_INFO("reserve expired.\n");
  4579. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4580. }
  4581. }//END OF Check if Reserve is expired
  4582. //==========================================
  4583. // csu trigger FirmwareStatusNotificationReq
  4584. //==========================================
  4585. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4586. {
  4587. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  4588. }
  4589. //==========================================
  4590. // csu trigger DiagnosticsStatusNotificationReq
  4591. //==========================================
  4592. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4593. {
  4594. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  4595. }
  4596. //==========================================
  4597. // csu trigger CancelReservationConf
  4598. //==========================================
  4599. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4600. {
  4601. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  4602. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4603. }
  4604. //==========================================
  4605. // csu trigger ChangeAvailabilityConf
  4606. //==========================================
  4607. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4608. {
  4609. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  4610. }
  4611. //==========================================
  4612. // csu trigger UnlockConnectorConf
  4613. //==========================================
  4614. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4615. {
  4616. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  4617. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4618. }
  4619. //==========================================
  4620. // csu trigger ReserveNowConf
  4621. //==========================================
  4622. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4623. {
  4624. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  4625. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4626. }
  4627. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  4628. {
  4629. sendSignCertificateRequest();
  4630. }
  4631. }
  4632. }
  4633. //==========================================
  4634. // send request routine
  4635. //==========================================
  4636. int sendAuthorizeRequest(int gun_index)
  4637. {
  4638. mtrace();
  4639. int result = FAIL;
  4640. char message[100]={0};
  4641. char guid[37];
  4642. char tempdata[65]={0};
  4643. DEBUG_INFO("sendAuthorizeRequest...\n");
  4644. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4645. //Local Authorize
  4646. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  4647. {
  4648. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4649. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4650. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4651. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4652. result = PASS;
  4653. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4654. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4655. authorizeRetryTimes = 0;
  4656. return result;
  4657. }
  4658. 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))||
  4659. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4660. {
  4661. // Query from cache
  4662. DEBUG_INFO("Authorize from cache.\n");
  4663. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4664. // Query from list
  4665. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4666. {
  4667. DEBUG_INFO("Authorize from list.\n");
  4668. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4669. }
  4670. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4671. {
  4672. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4673. {
  4674. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4675. }
  4676. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4677. {
  4678. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4679. }
  4680. if(!GetOcppConnStatus())
  4681. {
  4682. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4683. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4684. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4685. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4686. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4687. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4688. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4689. authorizeRetryTimes = 0;
  4690. return result;
  4691. }
  4692. }
  4693. else
  4694. {
  4695. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4696. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4697. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4698. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4699. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  4700. else
  4701. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4702. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4703. result = PASS;
  4704. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4705. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4706. authorizeRetryTimes = 0;
  4707. return result;
  4708. }
  4709. }
  4710. //initialize struct Authorize
  4711. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  4712. //get data from shared memory
  4713. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4714. random_uuid(guid);
  4715. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  4716. LWS_Send(message);
  4717. sprintf(tempdata, "Authorize,%d", gun_index);
  4718. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4719. {
  4720. result = PASS;
  4721. DEBUG_INFO("Authorize mapItem pass\n");
  4722. }
  4723. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4724. return result;
  4725. }
  4726. int sendBootNotificationRequest(void)
  4727. {
  4728. mtrace();
  4729. int result = FAIL;
  4730. char message[500]={0}, payload[700]={0};
  4731. char guid[37]={0};
  4732. char tempdata[65]={0};
  4733. // Fill BootNotification fields
  4734. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  4735. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4736. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4737. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4738. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4739. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4740. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4741. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4742. ShmOCPP16Data->ChargeBoxId
  4743. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4744. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4745. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4746. ,ShmOCPP16Data->BootNotification.CpFwVersion
  4747. ,ShmOCPP16Data->BootNotification.CpIccid
  4748. ,ShmOCPP16Data->BootNotification.CpImsi);
  4749. random_uuid(guid);
  4750. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4751. LWS_Send(message);
  4752. sprintf(tempdata, "BootNotification,0");
  4753. 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*/)
  4754. {
  4755. result = PASS;
  4756. }
  4757. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4758. strcpy(queuedata,message);
  4759. return result;
  4760. }
  4761. int sendDataTransferRequest(int gun_index)
  4762. {
  4763. mtrace();
  4764. char message[1000]={0};
  4765. char guid[37]={0};
  4766. char tempdata[65]={0};
  4767. int result = FAIL;
  4768. random_uuid(guid);
  4769. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4770. MESSAGE_TYPE_CALL,
  4771. guid,
  4772. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4773. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4774. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4775. LWS_Send(message);
  4776. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4777. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4778. {
  4779. result = PASS;
  4780. DEBUG_INFO("DataTransfer mapItem pass\n");
  4781. }
  4782. return result;
  4783. }
  4784. int sendDiagnosticsStatusNotificationRequest(char *status)
  4785. {
  4786. mtrace();
  4787. int result = FAIL;
  4788. char message[110]={0};
  4789. char guid[37]={0};
  4790. char tempdata[65]={0};
  4791. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4792. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4793. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4794. random_uuid(guid);
  4795. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4796. LWS_SendNow(message);
  4797. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4798. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4799. {
  4800. result = PASS;
  4801. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4802. }
  4803. //#ifdef SystemLogMessage
  4804. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4805. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4806. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4807. //#endif
  4808. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4809. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4810. //record status
  4811. if(strcmp(status,"Idle")==0)
  4812. {
  4813. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4814. }
  4815. else if(strcmp(status,"Uploaded")==0)
  4816. {
  4817. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4818. }
  4819. else if(strcmp(status,"UploadFailed")==0)
  4820. {
  4821. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4822. }
  4823. else if(strcmp(status,"Uploading")==0)
  4824. {
  4825. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4826. }
  4827. return result;
  4828. }
  4829. int sendFirmwareStatusNotificationRequest(char *status)
  4830. {
  4831. mtrace();
  4832. int result = FAIL;
  4833. char message[110]={0};
  4834. char guid[37]={0};
  4835. char tempdata[65]={0};
  4836. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4837. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4838. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4839. random_uuid(guid);
  4840. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4841. LWS_SendNow(message);
  4842. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4843. 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*/)
  4844. {
  4845. result = PASS;
  4846. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4847. }
  4848. //#ifdef SystemLogMessage
  4849. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4850. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4851. //#endif
  4852. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4853. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4854. //record status
  4855. if(strcmp(status,"Downloaded")==0)
  4856. {
  4857. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4858. }
  4859. else if(strcmp(status,"DownloadFailed")==0)
  4860. {
  4861. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4862. }
  4863. else if(strcmp(status,"Downloading")==0)
  4864. {
  4865. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4866. }
  4867. else if(strcmp(status,"Idle")==0)
  4868. {
  4869. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4870. }
  4871. else if(strcmp(status,"InstallationFailed")==0)
  4872. {
  4873. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4874. }
  4875. else if(strcmp(status,"Installing")==0)
  4876. {
  4877. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4878. }
  4879. else if(strcmp(status,"Installed")==0)
  4880. {
  4881. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4882. }
  4883. return result;
  4884. }
  4885. int sendHeartbeatRequest(int gun_index)
  4886. {
  4887. mtrace();
  4888. int result = FAIL;
  4889. char message[80]={0};
  4890. char guid[37]={0};
  4891. char tempdata[65]={0};
  4892. random_uuid(guid);
  4893. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4894. , MESSAGE_TYPE_CALL
  4895. , guid );
  4896. LWS_Send(message);
  4897. sprintf(tempdata, "Heartbeat,%d", 0);
  4898. 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*/)
  4899. {
  4900. result = PASS;
  4901. }
  4902. return result;
  4903. }
  4904. int sendStartTransactionRequest(int gun_index)
  4905. {
  4906. mtrace();
  4907. int result = FAIL;
  4908. char message[250]={0};
  4909. char guid[37]={0};
  4910. struct timeval tmnow;
  4911. struct tm *tm;
  4912. char buf[28];//, usec_buf[6];
  4913. char tempdata[65]={0};
  4914. int tempIndex = 0;
  4915. DEBUG_INFO("sendStartTransactionRequest...\n");
  4916. gettimeofday(&tmnow, NULL);
  4917. time_t t;
  4918. t = time(NULL);
  4919. /*UTC time and date*/
  4920. tm = gmtime(&t);
  4921. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4922. #if 0 // remove temporally
  4923. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4924. strcat(buf,".");
  4925. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4926. strcat(buf,usec_buf);
  4927. #endif
  4928. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4929. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4930. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4931. // clear StartTransaction Response
  4932. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4933. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4934. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4935. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4936. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4937. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4938. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4939. {
  4940. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4941. {
  4942. tempIndex = ((gun_index==2) ? 1: 0);
  4943. }
  4944. else
  4945. {
  4946. tempIndex = gun_index;
  4947. }
  4948. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4949. {
  4950. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4951. {
  4952. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4953. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4954. }
  4955. }
  4956. }
  4957. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4958. {
  4959. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4960. {
  4961. tempIndex = ((gun_index==2) ? 1: 0);
  4962. }
  4963. else
  4964. {
  4965. tempIndex = gun_index;
  4966. }
  4967. for (int index = 0; index < CCS_QUANTITY; index++)
  4968. {
  4969. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4970. {
  4971. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4972. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4973. }
  4974. }
  4975. }
  4976. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4977. {
  4978. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4979. {
  4980. tempIndex = ((gun_index==2) ? 1: 0);
  4981. }
  4982. else
  4983. {
  4984. tempIndex = gun_index;
  4985. }
  4986. for (int index = 0; index < GB_QUANTITY; index++)
  4987. {
  4988. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4989. {
  4990. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4991. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4992. }
  4993. }
  4994. }
  4995. else if(gunType[gun_index] == GUN_TYPE_DO)
  4996. {
  4997. tempIndex = gun_index;
  4998. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4999. {
  5000. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5001. {
  5002. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5003. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5004. }
  5005. }
  5006. }
  5007. else
  5008. {
  5009. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5010. {
  5011. tempIndex = 2;
  5012. }
  5013. else
  5014. {
  5015. tempIndex = gun_index;
  5016. }
  5017. for (int index = 0; index < AC_QUANTITY; index++)
  5018. {
  5019. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5020. {
  5021. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5022. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5023. }
  5024. }
  5025. }
  5026. random_uuid(guid);
  5027. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5028. {
  5029. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5030. , gun_index +1
  5031. , MESSAGE_TYPE_CALL
  5032. , guid
  5033. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5034. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5035. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5036. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5037. }
  5038. else
  5039. {
  5040. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5041. , gun_index +1
  5042. , MESSAGE_TYPE_CALL
  5043. , guid
  5044. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5045. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5046. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5047. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  5048. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5049. }
  5050. #if 1
  5051. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5052. 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*/)
  5053. {
  5054. result = PASS;
  5055. }
  5056. #endif
  5057. strcpy(queuedata, message);
  5058. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5059. OCPP_insert_transaction_msg(YES, queuedata);
  5060. return result;
  5061. }
  5062. int sendStatusNotificationRequest(int gun_index)
  5063. {
  5064. mtrace();
  5065. int result = FAIL;
  5066. char message[600]={0};
  5067. char guid[37];
  5068. int currentStatus = 0;
  5069. struct timeval tmnow;
  5070. struct tm *tm;
  5071. char buf[28];//, usec_buf[6];
  5072. char tempdata[65]={0};
  5073. int tempIndex = 0;
  5074. uint8_t isStateChanged = TRUE;
  5075. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5076. gettimeofday(&tmnow, NULL);
  5077. time_t t;
  5078. t = time(NULL);
  5079. /*UTC time and date*/
  5080. tm = gmtime(&t);
  5081. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5082. #if 0 // remove temporally
  5083. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5084. strcat(buf,".");
  5085. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5086. strcat(buf,usec_buf);
  5087. #endif
  5088. //printf("%s",buf);
  5089. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5090. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5091. // it's option
  5092. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5093. /*
  5094. enum _SYSTEM_STATUS
  5095. {
  5096. S_BOOTING = 0,
  5097. S_IDLE, = 1
  5098. S_AUTHORIZING, =2
  5099. S_REASSIGN_CHECK, =3
  5100. S_REASSIGN, =4
  5101. S_PRECHARGE, =5
  5102. S_PREPARING_FOR_EV, =6
  5103. S_PREPARING_FOR_EVSE, =7
  5104. S_CHARGING, =8
  5105. S_TERMINATING, =9
  5106. S_COMPLETE, =10
  5107. S_ALARM, =11
  5108. S_FAULT =12
  5109. }
  5110. */
  5111. //check Transaction active
  5112. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5113. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5114. {
  5115. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5116. {
  5117. tempIndex = ((gun_index==2) ? 1: 0);
  5118. }
  5119. else
  5120. {
  5121. tempIndex = gun_index;
  5122. }
  5123. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5124. {
  5125. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5126. {
  5127. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5128. {
  5129. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5130. {
  5131. currentStatus = Preparing; //OCPP Status: Preparing
  5132. }
  5133. else
  5134. {
  5135. currentStatus = Available; //OCPP Status: Available
  5136. }
  5137. }
  5138. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5139. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5140. ) //S_PRECHARGE
  5141. {
  5142. currentStatus = Preparing; //OCPP Status: Preparing
  5143. }
  5144. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5145. {
  5146. currentStatus = Charging; //OCPP Status: Charging
  5147. }
  5148. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5149. {
  5150. currentStatus = Finishing; //OCPP Status: Finishing
  5151. }
  5152. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5153. {
  5154. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5155. }
  5156. 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
  5157. {
  5158. currentStatus = Unavailable; //OCPP Status: Unavailable
  5159. }
  5160. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5161. {
  5162. currentStatus = Faulted; //OCPP Status: Faulted
  5163. }
  5164. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5165. {
  5166. currentStatus = Reserved; //OCPP Status: Reserved
  5167. }
  5168. } //end of the same index
  5169. }//end of for CHAdeMO_QUANTITY
  5170. }
  5171. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5172. {
  5173. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5174. {
  5175. tempIndex = ((gun_index==2) ? 1: 0);
  5176. }
  5177. else
  5178. {
  5179. tempIndex = gun_index;
  5180. }
  5181. for (int index = 0; index < CCS_QUANTITY; index++)
  5182. {
  5183. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5184. {
  5185. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5186. {
  5187. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5188. {
  5189. currentStatus = Preparing; //OCPP Status: Preparing
  5190. }
  5191. else
  5192. {
  5193. currentStatus = Available; //OCPP Status: Available
  5194. }
  5195. }
  5196. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5197. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5198. ) //S_PRECHARGE
  5199. {
  5200. currentStatus = Preparing; //OCPP Status: Preparing
  5201. }
  5202. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5203. {
  5204. currentStatus = Charging; //OCPP Status: Charging
  5205. }
  5206. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5207. {
  5208. currentStatus = Finishing; //OCPP Status: Finishing
  5209. }
  5210. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5211. {
  5212. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5213. }
  5214. 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
  5215. {
  5216. currentStatus = Unavailable; //OCPP Status : Unavailable
  5217. }
  5218. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5219. {
  5220. currentStatus = Faulted; //OCPP Status: Faulted
  5221. }
  5222. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5223. {
  5224. currentStatus = Reserved; //OCPP Status: Reserved
  5225. }
  5226. } //end of the same index
  5227. } // end of for CCS_QUANTITY
  5228. }
  5229. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5230. {
  5231. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5232. {
  5233. tempIndex = ((gun_index==2) ? 1: 0);
  5234. }
  5235. else
  5236. {
  5237. tempIndex = gun_index;
  5238. }
  5239. for (int index = 0; index < GB_QUANTITY; index++)
  5240. {
  5241. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5242. {
  5243. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5244. {
  5245. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5246. {
  5247. currentStatus = Preparing; //OCPP Status: Preparing
  5248. }
  5249. else
  5250. {
  5251. currentStatus = Available; //OCPP Status: Available
  5252. }
  5253. }
  5254. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5255. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5256. ) //S_PRECHARGE
  5257. {
  5258. currentStatus = Preparing; //OCPP Status: Preparing
  5259. }
  5260. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5261. {
  5262. currentStatus = Charging; //OCPP Status: Charging
  5263. }
  5264. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5265. {
  5266. currentStatus = Finishing; //OCPP Status: Finishing
  5267. }
  5268. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5269. {
  5270. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5271. }
  5272. 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
  5273. {
  5274. currentStatus = Unavailable; //OCPP Status: Unavailable
  5275. }
  5276. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5277. {
  5278. currentStatus = Faulted; //OCPP Status: Faulted
  5279. }
  5280. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5281. {
  5282. currentStatus = Reserved; //OCPP Status: Reserved
  5283. }
  5284. } //end of the same index
  5285. } // end of for GB_QUANTITY
  5286. }
  5287. else if(gunType[gun_index] == GUN_TYPE_DO)
  5288. {
  5289. tempIndex = gun_index;
  5290. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5291. {
  5292. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5293. {
  5294. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5295. {
  5296. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5297. {
  5298. currentStatus = Preparing; //OCPP Status: Preparing
  5299. }
  5300. else
  5301. {
  5302. currentStatus = Available; //OCPP Status: Available
  5303. }
  5304. }
  5305. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5306. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5307. ) //S_PRECHARGE
  5308. {
  5309. currentStatus = Preparing; //OCPP Status: Preparing
  5310. }
  5311. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5312. {
  5313. currentStatus = Charging; //OCPP Status: Charging
  5314. }
  5315. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5316. {
  5317. currentStatus = Finishing; //OCPP Status: Finishing
  5318. }
  5319. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5320. {
  5321. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5322. }
  5323. 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
  5324. {
  5325. currentStatus = Unavailable; //OCPP Status: Unavailable
  5326. }
  5327. 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
  5328. {
  5329. currentStatus = Faulted; //OCPP Status: Faulted
  5330. }
  5331. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5332. {
  5333. currentStatus = Reserved; //OCPP Status: Reserved
  5334. }
  5335. } //end of the same index
  5336. }
  5337. }
  5338. else
  5339. {
  5340. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5341. {
  5342. tempIndex = 2;
  5343. }
  5344. else
  5345. {
  5346. tempIndex = gun_index;
  5347. }
  5348. for (int index = 0; index < AC_QUANTITY; index++)
  5349. {
  5350. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5351. {
  5352. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5353. {
  5354. 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))
  5355. {
  5356. currentStatus = Preparing; //OCPP Status: Preparing
  5357. }
  5358. else
  5359. {
  5360. currentStatus = Available; //OCPP Status: Available
  5361. }
  5362. }
  5363. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5364. {
  5365. currentStatus = Preparing; //OCPP Status: Preparing
  5366. }
  5367. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5368. {
  5369. currentStatus = Charging; //OCPP Status: Charging
  5370. }
  5371. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5372. {
  5373. currentStatus = Finishing; //OCPP Status: Finishing
  5374. }
  5375. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5376. {
  5377. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5378. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5379. else
  5380. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5381. }
  5382. 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
  5383. {
  5384. currentStatus = Unavailable; //OCPP Status: Unavailable
  5385. }
  5386. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5387. {
  5388. currentStatus = Faulted; //OCPP Status: Faulted
  5389. }
  5390. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5391. {
  5392. currentStatus = Reserved; //OCPP Status: Reserved
  5393. }
  5394. }//end of the same index
  5395. }//end of for AC_QUANTITY
  5396. }
  5397. //it's option
  5398. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5399. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5400. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5401. {
  5402. isStateChanged = FALSE;
  5403. }
  5404. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5405. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5406. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5407. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5408. random_uuid(guid);
  5409. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5410. , MESSAGE_TYPE_CALL
  5411. , guid
  5412. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5413. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5414. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5415. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5416. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5417. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5418. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5419. if((server_sign == TRUE) && isStateChanged)
  5420. {
  5421. LWS_Send(message);
  5422. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5423. 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*/)
  5424. {
  5425. //DEBUG_ERROR("statusNotification mapitem pass");
  5426. result = PASS;
  5427. }
  5428. }
  5429. else
  5430. {
  5431. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5432. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5433. result = PASS;
  5434. }
  5435. return result;
  5436. }
  5437. int sendStopTransactionRequest(int gun_index)
  5438. {
  5439. mtrace();
  5440. int result = FAIL;
  5441. //char message[1500]={0};
  5442. char guid[37]={0};
  5443. char tempdata[65]={0};
  5444. int tempIndex = 0;
  5445. char TempStopTransaction[256];
  5446. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5447. //int idx_sample=0;
  5448. DEBUG_INFO("sendStopTransactionRequest \n");
  5449. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5450. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5451. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5452. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5453. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5454. {
  5455. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5456. {
  5457. tempIndex = ((gun_index==2) ? 1: 0);
  5458. }
  5459. else
  5460. {
  5461. tempIndex = gun_index;
  5462. }
  5463. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5464. {
  5465. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5466. {
  5467. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5468. }
  5469. }// END OF CHAdeMO_QUANTITY
  5470. }
  5471. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5472. {
  5473. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5474. {
  5475. tempIndex = ((gun_index==2) ? 1: 0);
  5476. }
  5477. else
  5478. {
  5479. tempIndex = gun_index;
  5480. }
  5481. for (int index = 0; index < CCS_QUANTITY; index++)
  5482. {
  5483. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5484. {
  5485. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5486. }
  5487. }// END OF CCS_QUANTITY
  5488. }
  5489. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5490. {
  5491. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5492. {
  5493. tempIndex = ((gun_index==2) ? 1: 0);
  5494. }
  5495. else
  5496. {
  5497. tempIndex = gun_index;
  5498. }
  5499. for (int index = 0; index < GB_QUANTITY; index++)
  5500. {
  5501. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5502. {
  5503. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5504. }
  5505. }// END OF GB_QUANTITY
  5506. }
  5507. else if(gunType[gun_index] == GUN_TYPE_DO)
  5508. {
  5509. tempIndex = gun_index;
  5510. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5511. {
  5512. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5513. {
  5514. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5515. }
  5516. }// END OF GB_QUANTITY
  5517. }
  5518. else
  5519. {
  5520. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5521. {
  5522. tempIndex = 2;
  5523. }
  5524. else
  5525. {
  5526. tempIndex = gun_index;
  5527. }
  5528. for (int index = 0; index < AC_QUANTITY; index++)
  5529. {
  5530. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5531. {
  5532. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5533. }
  5534. }// END OF AC_QUANTITY
  5535. }
  5536. //====================================== Stop Transaction Time =====================================================
  5537. struct timeval tmnow;
  5538. struct tm *tm;
  5539. char buf[28];//, usec_buf[6];
  5540. gettimeofday(&tmnow, NULL);
  5541. time_t t;
  5542. t = time(NULL);
  5543. /*UTC time and date*/
  5544. tm = gmtime(&t);
  5545. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5546. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  5547. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  5548. random_uuid(guid);
  5549. /***********************************transactionData******************************************************/
  5550. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5551. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5552. //=================================
  5553. // Transaction_Begin
  5554. //=================================
  5555. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5556. {
  5557. //============================================ Energy.Active.Import.Interval ================================
  5558. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5559. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5560. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5561. 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*/]);
  5562. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5563. 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))
  5564. {
  5565. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5566. }
  5567. else
  5568. {
  5569. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5570. }
  5571. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5572. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5573. }
  5574. //=================================
  5575. // Transaction_End
  5576. //=================================
  5577. // ================================= Current.Import L1 ===============================================
  5578. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5579. {
  5580. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5581. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5582. {
  5583. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5584. {
  5585. tempIndex = ((gun_index==2) ? 1: 0);
  5586. }
  5587. else
  5588. {
  5589. tempIndex = gun_index;
  5590. }
  5591. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5592. {
  5593. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5594. {
  5595. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5596. }
  5597. }// End of for CHAdeMO_QUANTITY
  5598. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5599. }
  5600. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5601. {
  5602. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5603. {
  5604. tempIndex = ((gun_index==2) ? 1: 0);
  5605. }
  5606. else
  5607. {
  5608. tempIndex = gun_index;
  5609. }
  5610. for (int index = 0; index < CCS_QUANTITY; index++)
  5611. {
  5612. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5613. {
  5614. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5615. }
  5616. }// End of for CCS_QUANTITY
  5617. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5618. }
  5619. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5620. {
  5621. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5622. {
  5623. tempIndex = ((gun_index==2) ? 1: 0);
  5624. }
  5625. else
  5626. {
  5627. tempIndex = gun_index;
  5628. }
  5629. for (int index = 0; index < GB_QUANTITY; index++)
  5630. {
  5631. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5632. {
  5633. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5634. }
  5635. }// End of for GB_QUANTITY
  5636. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5637. }
  5638. else if(gunType[gun_index] == GUN_TYPE_DO)
  5639. {
  5640. tempIndex = gun_index;
  5641. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5642. {
  5643. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5644. {
  5645. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5646. }
  5647. }
  5648. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5649. }
  5650. else
  5651. {
  5652. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5653. {
  5654. tempIndex = 2;
  5655. }
  5656. else
  5657. {
  5658. tempIndex = gun_index;
  5659. }
  5660. for (int index = 0; index < AC_QUANTITY; index++)
  5661. {
  5662. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5663. {
  5664. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5665. }
  5666. }// End of for AC_QUANTITY
  5667. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5668. }
  5669. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5670. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5671. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5672. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5673. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5674. }
  5675. // ================================= Energy.Active.Import.Interval ==============================================
  5676. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5677. {
  5678. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5679. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5680. {
  5681. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5682. {
  5683. tempIndex = ((gun_index==2) ? 1: 0);
  5684. }
  5685. else
  5686. {
  5687. tempIndex = gun_index;
  5688. }
  5689. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5690. {
  5691. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5692. {
  5693. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5694. }
  5695. }// END OF CHAdeMO_QUANTITY
  5696. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5697. }
  5698. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5699. {
  5700. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5701. {
  5702. tempIndex = ((gun_index==2) ? 1: 0);
  5703. }
  5704. else
  5705. {
  5706. tempIndex = gun_index;
  5707. }
  5708. for (int index = 0; index < CCS_QUANTITY; index++)
  5709. {
  5710. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5711. {
  5712. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5713. }
  5714. }// END OF CCS_QUANTITY
  5715. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5716. }
  5717. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5718. {
  5719. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5720. {
  5721. tempIndex = ((gun_index==2) ? 1: 0);
  5722. }
  5723. else
  5724. {
  5725. tempIndex = gun_index;
  5726. }
  5727. for (int index = 0; index < GB_QUANTITY; index++)
  5728. {
  5729. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5730. {
  5731. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5732. }
  5733. }// END OF GB_QUANTITY
  5734. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5735. }
  5736. else if(gunType[gun_index] == GUN_TYPE_DO)
  5737. {
  5738. tempIndex = gun_index;
  5739. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5740. {
  5741. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5742. {
  5743. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5744. }
  5745. }
  5746. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5747. }
  5748. else
  5749. {
  5750. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5751. {
  5752. tempIndex = 2;
  5753. }
  5754. else
  5755. {
  5756. tempIndex = gun_index;
  5757. }
  5758. for (int index = 0; index < AC_QUANTITY; index++)
  5759. {
  5760. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5761. {
  5762. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5763. }
  5764. }// END OF AC_QUANTITY
  5765. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5766. }
  5767. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5768. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5769. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5770. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5771. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5772. }
  5773. //=================================== Power.Active.Import ==================================================
  5774. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5775. {
  5776. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5777. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5778. {
  5779. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5780. {
  5781. tempIndex = ((gun_index==2) ? 1: 0);
  5782. }
  5783. else
  5784. {
  5785. tempIndex = gun_index;
  5786. }
  5787. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5788. {
  5789. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5790. {
  5791. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5792. }
  5793. } // End for CHAdeMO_QUANTITY
  5794. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5795. }
  5796. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5797. {
  5798. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5799. {
  5800. tempIndex = ((gun_index==2) ? 1: 0);
  5801. }
  5802. else
  5803. {
  5804. tempIndex = gun_index;
  5805. }
  5806. for (int index = 0; index < CCS_QUANTITY; index++)
  5807. {
  5808. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5809. {
  5810. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5811. }
  5812. } // END for CCS_QUANTITY
  5813. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5814. }
  5815. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5816. {
  5817. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5818. {
  5819. tempIndex = ((gun_index==2) ? 1: 0);
  5820. }
  5821. else
  5822. {
  5823. tempIndex = gun_index;
  5824. }
  5825. for (int index = 0; index < GB_QUANTITY; index++)
  5826. {
  5827. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5828. {
  5829. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5830. }
  5831. }// END for GB_QUANTITY
  5832. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5833. }
  5834. else if(gunType[gun_index] == GUN_TYPE_DO)
  5835. {
  5836. tempIndex = gun_index;
  5837. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5838. {
  5839. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5840. {
  5841. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5842. }
  5843. }
  5844. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5845. }
  5846. else
  5847. {
  5848. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5849. {
  5850. tempIndex = 2;
  5851. }
  5852. else
  5853. {
  5854. tempIndex = gun_index;
  5855. }
  5856. for (int index = 0; index < AC_QUANTITY; index++)
  5857. {
  5858. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5859. {
  5860. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5861. }
  5862. } // END for AC_QUANTITY
  5863. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5864. }
  5865. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5866. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5867. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5868. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5869. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5870. }
  5871. //============================ Voltage L1 ====================================
  5872. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5873. {
  5874. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5875. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5876. {
  5877. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5878. {
  5879. tempIndex = ((gun_index==2) ? 1: 0);
  5880. }
  5881. else
  5882. {
  5883. tempIndex = gun_index;
  5884. }
  5885. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5886. {
  5887. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5888. {
  5889. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5890. }
  5891. } // END OF FOR CHAdeMO_QUANTITY
  5892. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5893. }
  5894. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5895. {
  5896. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5897. {
  5898. tempIndex = ((gun_index==2) ? 1: 0);
  5899. }
  5900. else
  5901. {
  5902. tempIndex = gun_index;
  5903. }
  5904. for (int index = 0; index < CCS_QUANTITY; index++)
  5905. {
  5906. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5907. {
  5908. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5909. }
  5910. } // END OF FOR CCS_QUANTITY
  5911. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5912. }
  5913. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5914. {
  5915. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5916. {
  5917. tempIndex = ((gun_index==2) ? 1: 0);
  5918. }
  5919. else
  5920. {
  5921. tempIndex = gun_index;
  5922. }
  5923. for (int index = 0; index < GB_QUANTITY; index++)
  5924. {
  5925. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5926. {
  5927. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5928. }
  5929. } // END OF FOR GB_QUANTITY
  5930. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5931. }
  5932. else if(gunType[gun_index] == GUN_TYPE_DO)
  5933. {
  5934. tempIndex = gun_index;
  5935. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5936. {
  5937. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5938. {
  5939. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5940. }
  5941. }
  5942. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5943. }
  5944. else
  5945. {
  5946. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5947. {
  5948. tempIndex = 2;
  5949. }
  5950. else
  5951. {
  5952. tempIndex = gun_index;
  5953. }
  5954. for (int index = 0; index < AC_QUANTITY; index++)
  5955. {
  5956. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5957. {
  5958. 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
  5959. }
  5960. } // END OF FOR AC_QUANTITY
  5961. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5962. }
  5963. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5964. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5965. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5966. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5967. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5968. }
  5969. //====================== End SoC ================================
  5970. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5971. {
  5972. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5973. 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))
  5974. {
  5975. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5976. {
  5977. tempIndex = ((gun_index==2) ? 1: 0);
  5978. }
  5979. else
  5980. {
  5981. tempIndex = gun_index;
  5982. }
  5983. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5984. {
  5985. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5986. {
  5987. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5988. {
  5989. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5990. }
  5991. }
  5992. }
  5993. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5994. {
  5995. for (int index = 0; index < CCS_QUANTITY; index++)
  5996. {
  5997. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5998. {
  5999. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6000. }
  6001. }
  6002. }
  6003. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6004. {
  6005. for (int index = 0; index < GB_QUANTITY; index++)
  6006. {
  6007. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6008. {
  6009. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6010. }
  6011. }
  6012. }
  6013. else if(gunType[gun_index] == GUN_TYPE_DO)
  6014. {
  6015. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6016. {
  6017. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6018. {
  6019. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6020. }
  6021. }
  6022. }
  6023. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6024. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6025. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6026. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6027. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6028. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6029. } // END FOR DC CASE
  6030. }
  6031. // ================================= Current.Import L2 ===============================================
  6032. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6033. {
  6034. // AC 3 phse L2 current
  6035. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6036. {
  6037. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6038. {
  6039. tempIndex = 2;
  6040. }
  6041. else
  6042. {
  6043. tempIndex = gun_index;
  6044. }
  6045. for (int index = 0; index < AC_QUANTITY; index++)
  6046. {
  6047. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6048. {
  6049. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6050. }
  6051. }// End of for AC_QUANTITY
  6052. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6053. }
  6054. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6055. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6056. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6057. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6058. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6059. }
  6060. // ================================= Current.Import L3 ===============================================
  6061. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6062. {
  6063. // AC 3 phse L3 current
  6064. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6065. {
  6066. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6067. {
  6068. tempIndex = 2;
  6069. }
  6070. else
  6071. {
  6072. tempIndex = gun_index;
  6073. }
  6074. for (int index = 0; index < AC_QUANTITY; index++)
  6075. {
  6076. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6077. {
  6078. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6079. }
  6080. }// End of for AC_QUANTITY
  6081. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6082. }
  6083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6084. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6085. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6086. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6087. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6088. }
  6089. //============================ Voltage L2 ====================================
  6090. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6091. {
  6092. // AC 3 phse L2 voltage
  6093. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6094. {
  6095. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6096. {
  6097. tempIndex = 2;
  6098. }
  6099. else
  6100. {
  6101. tempIndex = gun_index;
  6102. }
  6103. for (int index = 0; index < AC_QUANTITY; index++)
  6104. {
  6105. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6106. {
  6107. 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
  6108. }
  6109. } // END OF FOR AC_QUANTITY
  6110. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6111. }
  6112. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6113. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6114. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6115. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6116. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6117. }
  6118. //============================ Voltage L3 ====================================
  6119. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6120. {
  6121. // AC 3 phse L3 voltage
  6122. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6123. {
  6124. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6125. {
  6126. tempIndex = 2;
  6127. }
  6128. else
  6129. {
  6130. tempIndex = gun_index;
  6131. }
  6132. for (int index = 0; index < AC_QUANTITY; index++)
  6133. {
  6134. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6135. {
  6136. 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
  6137. }
  6138. } // END OF FOR AC_QUANTITY
  6139. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6140. }
  6141. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6142. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6143. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6144. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6145. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6146. }
  6147. //====================== Start SoC ================================
  6148. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6149. {
  6150. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6151. 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))
  6152. {
  6153. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6154. {
  6155. tempIndex = ((gun_index==2) ? 1: 0);
  6156. }
  6157. else
  6158. {
  6159. tempIndex = gun_index;
  6160. }
  6161. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6162. {
  6163. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6164. {
  6165. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6166. {
  6167. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6168. }
  6169. }
  6170. }
  6171. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6172. {
  6173. for (int index = 0; index < CCS_QUANTITY; index++)
  6174. {
  6175. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6176. {
  6177. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6178. }
  6179. }
  6180. }
  6181. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6182. {
  6183. for (int index = 0; index < GB_QUANTITY; index++)
  6184. {
  6185. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6186. {
  6187. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6188. }
  6189. }
  6190. }
  6191. else if(gunType[gun_index] == GUN_TYPE_DO)
  6192. {
  6193. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6194. {
  6195. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6196. {
  6197. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6198. }
  6199. }
  6200. }
  6201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6203. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6204. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6205. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6206. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6207. } // END FOR DC CASE
  6208. }
  6209. //================================================ Message create ====================================================
  6210. json_object *StopTransaction = json_object_new_object();
  6211. json_object *transactionDatas = json_object_new_array();
  6212. json_object *sampledValues = json_object_new_array();
  6213. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6214. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6215. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6216. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6217. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6218. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6219. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6220. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6221. {
  6222. json_object *transactionData = json_object_new_object();
  6223. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6224. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6225. {
  6226. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6227. {
  6228. json_object *sampledValue = json_object_new_object();
  6229. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6230. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6231. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6232. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6233. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6234. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6235. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6236. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6237. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6238. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6239. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6240. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6241. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6242. json_object_array_add(sampledValues, sampledValue);
  6243. }
  6244. }
  6245. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6246. json_object_array_add(transactionDatas, transactionData);
  6247. }
  6248. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6249. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6250. ,MESSAGE_TYPE_CALL
  6251. ,guid
  6252. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6253. json_object_put(StopTransaction);
  6254. #if 1 // for TempStopTransaction
  6255. //Delete TempStopTransaction
  6256. if((access(TempStopTransaction,F_OK))!=-1)
  6257. {
  6258. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6259. }
  6260. #endif
  6261. #if 1
  6262. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6263. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6264. {
  6265. result = PASS;
  6266. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6267. }
  6268. #endif
  6269. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6270. OCPP_insert_transaction_msg(NO, queuedata);
  6271. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6272. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6273. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6274. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6275. {
  6276. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6277. }
  6278. //for test
  6279. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6280. return result;
  6281. }
  6282. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6283. {
  6284. mtrace();
  6285. int result = FAIL;
  6286. char guid[37]={0};
  6287. char tempdata[65]={0};
  6288. int tempIndex = 0;
  6289. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6290. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6291. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6292. //set value
  6293. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6294. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6295. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6296. -1);
  6297. random_uuid(guid);
  6298. //UTC Date time
  6299. struct timeval tmnow;
  6300. struct tm *tm;
  6301. char buf[28];//, usec_buf[6];
  6302. gettimeofday(&tmnow, NULL);
  6303. time_t t;
  6304. t = time(NULL);
  6305. /*UTC time and date*/
  6306. tm = gmtime(&t);
  6307. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6308. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6309. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6310. //********************************(1)Current.Import L1************************************************/
  6311. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6312. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6313. (dataType == ReadingContext_Trigger))
  6314. {
  6315. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6316. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6317. {
  6318. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6319. {
  6320. tempIndex = ((gun_index==2) ? 1: 0);
  6321. }
  6322. else
  6323. {
  6324. tempIndex = gun_index;
  6325. }
  6326. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6327. {
  6328. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6329. {
  6330. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6331. }
  6332. }
  6333. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6334. }
  6335. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6336. {
  6337. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6338. {
  6339. tempIndex = ((gun_index==2) ? 1: 0);
  6340. }
  6341. else
  6342. {
  6343. tempIndex = gun_index;
  6344. }
  6345. for (int index = 0; index < CCS_QUANTITY; index++)
  6346. {
  6347. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6348. {
  6349. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6350. }
  6351. }
  6352. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6353. }
  6354. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6355. {
  6356. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6357. {
  6358. tempIndex = ((gun_index==2) ? 1: 0);
  6359. }
  6360. else
  6361. {
  6362. tempIndex = gun_index;
  6363. }
  6364. for (int index = 0; index < GB_QUANTITY; index++)
  6365. {
  6366. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6367. {
  6368. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6369. }
  6370. }
  6371. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6372. }
  6373. else if(gunType[gun_index] == GUN_TYPE_DO)
  6374. {
  6375. tempIndex = gun_index;
  6376. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6377. {
  6378. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6379. {
  6380. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6381. }
  6382. }
  6383. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6384. }
  6385. else
  6386. {
  6387. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6388. {
  6389. tempIndex = 2;
  6390. }
  6391. else
  6392. {
  6393. tempIndex = gun_index;
  6394. }
  6395. for (int index = 0; index < AC_QUANTITY; index++)
  6396. {
  6397. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6398. {
  6399. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6400. }
  6401. }
  6402. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6403. }
  6404. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6405. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6406. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6407. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6408. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6409. }
  6410. //********************************(2)Energy.Active.Import.Register ************************************************/
  6411. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6412. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6413. (dataType == ReadingContext_Trigger))
  6414. {
  6415. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6416. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6417. {
  6418. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6419. {
  6420. tempIndex = ((gun_index==2) ? 1: 0);
  6421. }
  6422. else
  6423. {
  6424. tempIndex = gun_index;
  6425. }
  6426. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6427. {
  6428. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6429. {
  6430. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6431. }
  6432. }
  6433. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6434. }
  6435. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6436. {
  6437. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6438. {
  6439. tempIndex = ((gun_index==2) ? 1: 0);
  6440. }
  6441. else
  6442. {
  6443. tempIndex = gun_index;
  6444. }
  6445. for (int index = 0; index < CCS_QUANTITY; index++)
  6446. {
  6447. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6448. {
  6449. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6450. }
  6451. }
  6452. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6453. }
  6454. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6455. {
  6456. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6457. {
  6458. tempIndex = ((gun_index==2) ? 1: 0);
  6459. }
  6460. else
  6461. {
  6462. tempIndex = gun_index;
  6463. }
  6464. for (int index = 0; index < GB_QUANTITY; index++)
  6465. {
  6466. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6467. {
  6468. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6469. }
  6470. }
  6471. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6472. }
  6473. else if(gunType[gun_index] == GUN_TYPE_DO)
  6474. {
  6475. tempIndex = gun_index;
  6476. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6477. {
  6478. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6479. {
  6480. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6481. }
  6482. }
  6483. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6484. }
  6485. else
  6486. {
  6487. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6488. {
  6489. tempIndex = 2;
  6490. }
  6491. else
  6492. {
  6493. tempIndex = gun_index;
  6494. }
  6495. for (int index = 0; index < AC_QUANTITY; index++)
  6496. {
  6497. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6498. {
  6499. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6500. }
  6501. }
  6502. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6503. }
  6504. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6505. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6506. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6507. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6508. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6509. }
  6510. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6511. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6512. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6513. (dataType == ReadingContext_Trigger))
  6514. {
  6515. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6516. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6517. {
  6518. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6519. {
  6520. tempIndex = ((gun_index==2) ? 1: 0);
  6521. }
  6522. else
  6523. {
  6524. tempIndex = gun_index;
  6525. }
  6526. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6527. {
  6528. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6529. {
  6530. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6531. }
  6532. } // END OF FOR CHAdeMO_QUANTITY
  6533. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6534. }
  6535. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6536. {
  6537. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6538. {
  6539. tempIndex = ((gun_index==2) ? 1: 0);
  6540. }
  6541. else
  6542. {
  6543. tempIndex = gun_index;
  6544. }
  6545. for (int index = 0; index < CCS_QUANTITY; index++)
  6546. {
  6547. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6548. {
  6549. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6550. }
  6551. } // END OF CCS_QUANTITY
  6552. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6553. }
  6554. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6555. {
  6556. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6557. {
  6558. tempIndex = ((gun_index==2) ? 1: 0);
  6559. }
  6560. else
  6561. {
  6562. tempIndex = gun_index;
  6563. }
  6564. for (int index = 0; index < GB_QUANTITY; index++)
  6565. {
  6566. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6567. {
  6568. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6569. }
  6570. } // END OF GB_QUANTITY
  6571. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6572. }
  6573. else if(gunType[gun_index] == GUN_TYPE_DO)
  6574. {
  6575. tempIndex = gun_index;
  6576. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6577. {
  6578. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6579. {
  6580. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6581. }
  6582. }
  6583. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6584. }
  6585. else
  6586. {
  6587. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6588. {
  6589. tempIndex = 2;
  6590. }
  6591. else
  6592. {
  6593. tempIndex = gun_index;
  6594. }
  6595. for (int index = 0; index < AC_QUANTITY; index++)
  6596. {
  6597. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6598. {
  6599. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6600. }
  6601. }
  6602. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6603. }
  6604. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6605. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6606. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6607. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6608. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6609. }
  6610. //********************************(4)Power.Active.Import************************************************/
  6611. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6612. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6613. (dataType == ReadingContext_Trigger))
  6614. {
  6615. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6616. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6617. {
  6618. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6619. {
  6620. tempIndex = ((gun_index==2) ? 1: 0);
  6621. }
  6622. else
  6623. {
  6624. tempIndex = gun_index;
  6625. }
  6626. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6627. {
  6628. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6629. {
  6630. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6631. }
  6632. } // END OF FOR
  6633. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6634. }
  6635. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6636. {
  6637. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6638. {
  6639. tempIndex = ((gun_index==2) ? 1: 0);
  6640. }
  6641. else
  6642. {
  6643. tempIndex = gun_index;
  6644. }
  6645. for (int index = 0; index < CCS_QUANTITY; index++)
  6646. {
  6647. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6648. {
  6649. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6650. }
  6651. }
  6652. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6653. }
  6654. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6655. {
  6656. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6657. {
  6658. tempIndex = ((gun_index==2) ? 1: 0);
  6659. }
  6660. else
  6661. {
  6662. tempIndex = gun_index;
  6663. }
  6664. for (int index = 0; index < GB_QUANTITY; index++)
  6665. {
  6666. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6667. {
  6668. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6669. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6670. }
  6671. }
  6672. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6673. }
  6674. else if(gunType[gun_index] == GUN_TYPE_DO)
  6675. {
  6676. tempIndex = gun_index;
  6677. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6678. {
  6679. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6680. {
  6681. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6682. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6683. }
  6684. }
  6685. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6686. }
  6687. else
  6688. {
  6689. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6690. {
  6691. tempIndex = 2;
  6692. }
  6693. else
  6694. {
  6695. tempIndex = gun_index;
  6696. }
  6697. for (int index = 0; index < AC_QUANTITY; index++)
  6698. {
  6699. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6700. {
  6701. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6702. }
  6703. }
  6704. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6705. }
  6706. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6707. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6708. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6709. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6710. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6711. }
  6712. //***********************************************(5)VOLTAGE L1******************************************************/
  6713. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6714. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6715. (dataType == ReadingContext_Trigger))
  6716. {
  6717. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6718. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6719. {
  6720. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6721. {
  6722. tempIndex = ((gun_index==2) ? 1: 0);
  6723. }
  6724. else
  6725. {
  6726. tempIndex = gun_index;
  6727. }
  6728. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6729. {
  6730. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6731. {
  6732. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6733. }
  6734. }
  6735. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6736. }
  6737. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6738. {
  6739. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6740. {
  6741. tempIndex = ((gun_index==2) ? 1: 0);
  6742. }
  6743. else
  6744. {
  6745. tempIndex = gun_index;
  6746. }
  6747. for (int index = 0; index < CCS_QUANTITY; index++)
  6748. {
  6749. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6750. {
  6751. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6752. }
  6753. }
  6754. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6755. }
  6756. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6757. {
  6758. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6759. {
  6760. tempIndex = ((gun_index==2) ? 1: 0);
  6761. }
  6762. else
  6763. {
  6764. tempIndex = gun_index;
  6765. }
  6766. for (int index = 0; index < GB_QUANTITY; index++)
  6767. {
  6768. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6769. {
  6770. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6771. }
  6772. }
  6773. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6774. }
  6775. else if(gunType[gun_index] == GUN_TYPE_DO)
  6776. {
  6777. tempIndex = gun_index;
  6778. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6779. {
  6780. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6781. {
  6782. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6783. }
  6784. }
  6785. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6786. }
  6787. else
  6788. {
  6789. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6790. {
  6791. tempIndex = 2;
  6792. }
  6793. else
  6794. {
  6795. tempIndex = gun_index;
  6796. }
  6797. for (int index = 0; index < AC_QUANTITY; index++)
  6798. {
  6799. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6800. {
  6801. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6802. }
  6803. }
  6804. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6805. }
  6806. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6807. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6808. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6809. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6810. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6811. }
  6812. //***********************************************(6)SOC******************************************************/
  6813. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6814. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6815. (dataType == ReadingContext_Trigger))
  6816. {
  6817. 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))
  6818. {
  6819. //idx_sample=5;
  6820. //sampledValue = NULL;
  6821. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6822. {
  6823. tempIndex = ((gun_index==2) ? 1: 0);
  6824. }
  6825. else
  6826. {
  6827. tempIndex = gun_index;
  6828. }
  6829. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6830. {
  6831. //tempIndex = ((gun_index==2) ? 1: 0);
  6832. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6833. {
  6834. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6835. {
  6836. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6837. }
  6838. }
  6839. }
  6840. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6841. {
  6842. //tempIndex = ((gun_index==2) ? 1: 0);
  6843. for (int index = 0; index < CCS_QUANTITY; index++)
  6844. {
  6845. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6846. {
  6847. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6848. }
  6849. }
  6850. }
  6851. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6852. {
  6853. //tempIndex = ((gun_index==2) ? 1: 0);
  6854. for (int index = 0; index < GB_QUANTITY; index++)
  6855. {
  6856. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6857. {
  6858. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6859. }
  6860. }
  6861. }
  6862. else if(gunType[gun_index] == GUN_TYPE_DO)
  6863. {
  6864. //tempIndex = ((gun_index==2) ? 1: 0);
  6865. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6866. {
  6867. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6868. {
  6869. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6870. }
  6871. }
  6872. }
  6873. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6874. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6875. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6876. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6877. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6878. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6879. }
  6880. }
  6881. //********************************(7)Current.Import L2************************************************/
  6882. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6883. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6884. (dataType == ReadingContext_Trigger))
  6885. {
  6886. // Only for AC 3 phase
  6887. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6888. {
  6889. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6890. {
  6891. tempIndex = 2;
  6892. }
  6893. else
  6894. {
  6895. tempIndex = gun_index;
  6896. }
  6897. for (int index = 0; index < AC_QUANTITY; index++)
  6898. {
  6899. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6900. {
  6901. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6902. }
  6903. }
  6904. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6905. }
  6906. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6907. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6908. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6909. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6910. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6911. }
  6912. //********************************(8)Current.Import L3************************************************/
  6913. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6914. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6915. (dataType == ReadingContext_Trigger))
  6916. {
  6917. // Only for AC 3 phase
  6918. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6919. {
  6920. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6921. {
  6922. tempIndex = 2;
  6923. }
  6924. else
  6925. {
  6926. tempIndex = gun_index;
  6927. }
  6928. for (int index = 0; index < AC_QUANTITY; index++)
  6929. {
  6930. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6931. {
  6932. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6933. }
  6934. }
  6935. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6936. }
  6937. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6938. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6939. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6940. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6941. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6942. }
  6943. //***********************************************(9)VOLTAGE L2******************************************************/
  6944. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6945. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6946. (dataType == ReadingContext_Trigger))
  6947. {
  6948. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6949. {
  6950. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6951. {
  6952. tempIndex = 2;
  6953. }
  6954. else
  6955. {
  6956. tempIndex = gun_index;
  6957. }
  6958. for (int index = 0; index < AC_QUANTITY; index++)
  6959. {
  6960. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6961. {
  6962. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6963. }
  6964. }
  6965. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6966. }
  6967. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6968. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6969. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6970. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6971. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6972. }
  6973. //***********************************************(10)VOLTAGE L3******************************************************/
  6974. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6975. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6976. (dataType == ReadingContext_Trigger))
  6977. {
  6978. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6979. {
  6980. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6981. {
  6982. tempIndex = 2;
  6983. }
  6984. else
  6985. {
  6986. tempIndex = gun_index;
  6987. }
  6988. for (int index = 0; index < AC_QUANTITY; index++)
  6989. {
  6990. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6991. {
  6992. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6993. }
  6994. }
  6995. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6996. }
  6997. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6998. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6999. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7000. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7001. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7002. }
  7003. //***********************************************(11)Current.Offered******************************************************/
  7004. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7005. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7006. (dataType == ReadingContext_Trigger))
  7007. {
  7008. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7009. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7010. {
  7011. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7012. {
  7013. tempIndex = ((gun_index==2) ? 1: 0);
  7014. }
  7015. else
  7016. {
  7017. tempIndex = gun_index;
  7018. }
  7019. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7020. {
  7021. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7022. {
  7023. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7024. }
  7025. } // END OF FOR CHAdeMO_QUANTITY
  7026. }
  7027. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7028. {
  7029. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7030. {
  7031. tempIndex = ((gun_index==2) ? 1: 0);
  7032. }
  7033. else
  7034. {
  7035. tempIndex = gun_index;
  7036. }
  7037. for (int index = 0; index < CCS_QUANTITY; index++)
  7038. {
  7039. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7040. {
  7041. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7042. }
  7043. } // END OF CCS_QUANTITY
  7044. }
  7045. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7046. {
  7047. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7048. {
  7049. tempIndex = ((gun_index==2) ? 1: 0);
  7050. }
  7051. else
  7052. {
  7053. tempIndex = gun_index;
  7054. }
  7055. for (int index = 0; index < GB_QUANTITY; index++)
  7056. {
  7057. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7058. {
  7059. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7060. }
  7061. } // END OF GB_QUANTITY
  7062. }
  7063. else if(gunType[gun_index] == GUN_TYPE_DO)
  7064. {
  7065. tempIndex = gun_index;
  7066. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7067. {
  7068. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7069. {
  7070. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7071. }
  7072. }
  7073. }
  7074. else
  7075. {
  7076. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7077. {
  7078. tempIndex = 2;
  7079. }
  7080. else
  7081. {
  7082. tempIndex = gun_index;
  7083. }
  7084. for (int index = 0; index < AC_QUANTITY; index++)
  7085. {
  7086. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7087. {
  7088. uint16_t currentOffer;
  7089. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7090. {
  7091. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7092. }
  7093. else
  7094. {
  7095. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7096. }
  7097. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7098. }
  7099. }
  7100. }
  7101. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7102. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7103. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7104. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7105. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7106. }
  7107. //***********************************************(12)Power.Offered******************************************************/
  7108. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7109. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7110. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7111. {
  7112. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7113. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7114. {
  7115. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7116. {
  7117. tempIndex = ((gun_index==2) ? 1: 0);
  7118. }
  7119. else
  7120. {
  7121. tempIndex = gun_index;
  7122. }
  7123. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7124. {
  7125. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7126. {
  7127. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7128. }
  7129. } // END OF FOR CHAdeMO_QUANTITY
  7130. }
  7131. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7132. {
  7133. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7134. {
  7135. tempIndex = ((gun_index==2) ? 1: 0);
  7136. }
  7137. else
  7138. {
  7139. tempIndex = gun_index;
  7140. }
  7141. for (int index = 0; index < CCS_QUANTITY; index++)
  7142. {
  7143. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7144. {
  7145. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7146. }
  7147. } // END OF CCS_QUANTITY
  7148. }
  7149. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7150. {
  7151. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7152. {
  7153. tempIndex = ((gun_index==2) ? 1: 0);
  7154. }
  7155. else
  7156. {
  7157. tempIndex = gun_index;
  7158. }
  7159. for (int index = 0; index < GB_QUANTITY; index++)
  7160. {
  7161. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7162. {
  7163. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7164. }
  7165. } // END OF GB_QUANTITY
  7166. }
  7167. else if(gunType[gun_index] == GUN_TYPE_DO)
  7168. {
  7169. tempIndex = gun_index;
  7170. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7171. {
  7172. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7173. {
  7174. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7175. }
  7176. }
  7177. }
  7178. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7179. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7180. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7181. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7182. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7183. }
  7184. // Message create ====================================================================================================
  7185. if(TRUE)
  7186. {
  7187. json_object *MeterValueReq = json_object_new_object();
  7188. json_object *MeterValues = json_object_new_array();
  7189. json_object *sampledValues = json_object_new_array();
  7190. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7191. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7192. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7193. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7194. {
  7195. json_object *MeterValue = json_object_new_object();
  7196. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7197. {
  7198. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7199. {
  7200. json_object *sampledValue = json_object_new_object();
  7201. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7202. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7203. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7204. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7205. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7206. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7207. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7208. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7209. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7210. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7211. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7212. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7213. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7214. json_object_array_add(sampledValues, sampledValue);
  7215. }
  7216. }
  7217. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7218. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7219. json_object_array_add(MeterValues, MeterValue);
  7220. }
  7221. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7222. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7223. ,gun_index + 1
  7224. ,MESSAGE_TYPE_CALL
  7225. ,guid
  7226. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7227. json_object_put(MeterValueReq);
  7228. }
  7229. // Put request guid to hash map
  7230. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7231. 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*/)
  7232. {
  7233. result = PASS;
  7234. //DEBUG_INFO("MeterValues mapitem pass\n");
  7235. }
  7236. if((dataType != ReadingContext_Trigger) &&
  7237. (dataType != ReadingContext_Sample_Clock) &&
  7238. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7239. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7240. else
  7241. {
  7242. if(FirstHeartBeat)
  7243. LWS_Send(queuedata +2);
  7244. }
  7245. return result;
  7246. }
  7247. int sendLogStatusNotificationRequest(char *status)
  7248. {
  7249. mtrace();
  7250. int result = PASS;
  7251. char message[4096]={0};
  7252. char guid[37]={0};
  7253. char tempdata[128]={0};
  7254. json_object *LogStatusNotification = json_object_new_object();
  7255. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7256. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7257. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7258. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7259. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7260. random_uuid(guid);
  7261. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7262. json_object_put(LogStatusNotification);
  7263. LWS_Send(message);
  7264. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7265. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7266. {
  7267. result = PASS;
  7268. }
  7269. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7270. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7271. return result;
  7272. }
  7273. int sendSecurityEventNotificationRequest()
  7274. {
  7275. mtrace();
  7276. int result = PASS;
  7277. char message[4096]={0};
  7278. char guid[37]={0};
  7279. char tempdata[128]={0};
  7280. json_object *SecurityEventNotification = json_object_new_object();
  7281. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7282. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7283. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7284. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7285. random_uuid(guid);
  7286. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7287. json_object_put(SecurityEventNotification);
  7288. LWS_Send(message);
  7289. sprintf(tempdata, "SecurityEventNotification,0");
  7290. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7291. {
  7292. result = PASS;
  7293. }
  7294. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7295. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7296. return result;
  7297. }
  7298. int sendSignCertificateRequest()
  7299. {
  7300. mtrace();
  7301. int result = PASS;
  7302. char message[4096]={0};
  7303. char guid[37]={0};
  7304. char tempdata[128]={0};
  7305. json_object *SignCertificate = json_object_new_object();
  7306. DEBUG_INFO("sendSignCertificateRequest...\n");
  7307. // Read csr file content
  7308. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7309. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7310. char *line = NULL;
  7311. size_t len = 0;
  7312. while(getline(&line, &len, fp) != -1)
  7313. {
  7314. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7315. {
  7316. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7317. }
  7318. }
  7319. fclose(fp);
  7320. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7321. random_uuid(guid);
  7322. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7323. json_object_put(SignCertificate);
  7324. LWS_Send(message);
  7325. sprintf(tempdata, "SignCertificate,0");
  7326. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7327. {
  7328. result = PASS;
  7329. }
  7330. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7331. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7332. return result;
  7333. }
  7334. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7335. {
  7336. mtrace();
  7337. int result = PASS;
  7338. char message[110]={0};
  7339. char guid[37]={0};
  7340. char tempdata[65]={0};
  7341. json_object *FirmwareStatusNotification = json_object_new_object();
  7342. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7343. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7344. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7345. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7346. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7347. random_uuid(guid);
  7348. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7349. json_object_put(FirmwareStatusNotification);
  7350. LWS_Send(message);
  7351. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7352. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7353. {
  7354. result = PASS;
  7355. }
  7356. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7357. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7358. return result;
  7359. }
  7360. //==========================================
  7361. // send confirm routine
  7362. //==========================================
  7363. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7364. {
  7365. mtrace();
  7366. int result = FAIL;
  7367. char message[100]={0};
  7368. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7369. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7370. LWS_Send(message);
  7371. result = TRUE;
  7372. return result;
  7373. }
  7374. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7375. {
  7376. mtrace();
  7377. int result = FAIL;
  7378. char message[100]={0};
  7379. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7380. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7381. LWS_Send(message);
  7382. result = TRUE;
  7383. return result;
  7384. }
  7385. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7386. {
  7387. mtrace();
  7388. int result = FAIL;
  7389. char message[100]={0};
  7390. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7391. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7392. LWS_Send(message);
  7393. result = TRUE;
  7394. return result;
  7395. }
  7396. int sendClearCacheConfirmation(char *uuid,char *payload)
  7397. {
  7398. mtrace();
  7399. int result = FAIL;
  7400. char message[500]={0};
  7401. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7402. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7403. LWS_Send(message);
  7404. return result;
  7405. }
  7406. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7407. {
  7408. mtrace();
  7409. int result = FAIL;
  7410. char message[500]={0};
  7411. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7412. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7413. LWS_Send(message);
  7414. return result;
  7415. }
  7416. int sendDataTransferConfirmation(char *uuid,char *payload)
  7417. {
  7418. mtrace();
  7419. char statusStr[20]={0};
  7420. char dataStr[10]={0};
  7421. char sstr[20]={0};
  7422. int c = 0;
  7423. char *loc;
  7424. int result = FAIL;
  7425. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7426. /**********************status**************************/
  7427. loc = strstr(payload, "status");
  7428. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7429. c = 0;
  7430. while (loc[3+strlen("status")+c] != '\"')
  7431. {
  7432. sstr[c] = loc[3+strlen("status")+c];
  7433. c++;
  7434. }
  7435. sstr[c] = '\0';
  7436. strcpy(statusStr, sstr);
  7437. /**********************data**************************/
  7438. loc = strstr(payload, "data");
  7439. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7440. c = 0;
  7441. while (loc[3+strlen("data")+c] != '\"')
  7442. {
  7443. sstr[c] = loc[3+strlen("data")+c];
  7444. c++;
  7445. }
  7446. sstr[c] = '\0';
  7447. strcpy(dataStr, sstr);
  7448. return result;
  7449. }
  7450. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7451. {
  7452. mtrace();
  7453. int result = FAIL;
  7454. char message[1000]={0};
  7455. int CompositeScheduleIndex = 0;
  7456. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7457. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7458. if(nPeriod == 0)
  7459. {
  7460. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7461. {
  7462. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7463. ,MESSAGE_TYPE_CALLRESULT
  7464. ,uuid
  7465. ,payload
  7466. ,connectorIdInt);
  7467. }
  7468. else
  7469. {
  7470. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7471. ,MESSAGE_TYPE_CALLRESULT
  7472. ,uuid
  7473. ,payload
  7474. ,connectorIdInt
  7475. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7476. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7477. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7478. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7479. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7480. }
  7481. }
  7482. else
  7483. {
  7484. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7485. ,MESSAGE_TYPE_CALLRESULT
  7486. ,uuid
  7487. ,payload
  7488. ,connectorIdInt
  7489. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7490. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7491. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7492. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7493. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7494. {
  7495. if (idx_sample == 0)
  7496. {
  7497. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7498. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7499. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7500. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7501. }
  7502. else
  7503. {
  7504. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7505. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7506. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7507. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7508. }
  7509. }
  7510. sprintf(message + strlen(message), "]}}]");
  7511. }
  7512. LWS_Send(message);
  7513. result = TRUE;
  7514. return result;
  7515. }
  7516. int sendGetConfigurationConfirmation(char *uuid)
  7517. {
  7518. mtrace();
  7519. int result = FAIL;
  7520. int MaxKeySupported = 0;
  7521. int sentConfigurationNumber= 0;
  7522. int sentunConfigurationNumber= 0;
  7523. char message[1024*10]={0};
  7524. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7525. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7526. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7527. ,MESSAGE_TYPE_CALLRESULT
  7528. ,uuid );
  7529. //configuration key
  7530. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7531. {
  7532. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7533. {
  7534. if (sentConfigurationNumber == 0)
  7535. {
  7536. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7537. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7538. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7539. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7540. }
  7541. else
  7542. {
  7543. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7544. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7545. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7546. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7547. }
  7548. sentConfigurationNumber = sentConfigurationNumber + 1;
  7549. }
  7550. }
  7551. sprintf(message + strlen(message), "]");
  7552. if(UnknownKeynum != 0)
  7553. {
  7554. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7555. //unkown key
  7556. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7557. {
  7558. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7559. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7560. if(sentunConfigurationNumber == 0)
  7561. {
  7562. sprintf(message + strlen(message), "\"%s\""
  7563. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7564. }
  7565. else
  7566. {
  7567. sprintf(message + strlen(message), ",\"%s\""
  7568. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7569. }
  7570. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7571. }
  7572. sprintf(message + strlen(message), "]");
  7573. }
  7574. sprintf(message + strlen(message), "}]");
  7575. LWS_Send(message);
  7576. return result;
  7577. }
  7578. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7579. {
  7580. mtrace();
  7581. int result = FAIL;
  7582. char message[400]={0};
  7583. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7584. if(strcmp(payload,"")==0)
  7585. {
  7586. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7587. }
  7588. else
  7589. {
  7590. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7591. }
  7592. LWS_Send(message);
  7593. result = TRUE;
  7594. return result;
  7595. }
  7596. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7597. {
  7598. mtrace();
  7599. int result = FAIL;
  7600. char message[80]={0};
  7601. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7602. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  7603. LWS_Send(message);
  7604. result = TRUE;
  7605. return result;
  7606. }
  7607. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7608. {
  7609. mtrace();
  7610. int result = FAIL;
  7611. char message[80]={0};
  7612. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7613. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7614. LWS_Send(message);
  7615. result = TRUE;
  7616. return result;
  7617. }
  7618. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7619. {
  7620. mtrace();
  7621. int result = FAIL;
  7622. char message[80]={0};
  7623. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7624. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7625. LWS_Send(message);
  7626. result = TRUE;
  7627. return result;
  7628. }
  7629. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7630. {
  7631. mtrace();
  7632. int result = FAIL;
  7633. char message[80]={0};
  7634. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7635. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7636. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7637. LWS_Send(message);
  7638. result = TRUE;
  7639. return result;
  7640. }
  7641. int sendResetConfirmation(char *uuid,char *payload)
  7642. {
  7643. mtrace();
  7644. int result = FAIL;
  7645. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7646. char message[80]={0};
  7647. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  7648. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7649. LWS_Send(message);
  7650. result = TRUE;
  7651. return result;
  7652. }
  7653. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7654. {
  7655. mtrace();
  7656. int result = FAIL;
  7657. char message[500]={0};
  7658. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7659. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7660. LWS_Send(message);
  7661. result = TRUE;
  7662. return result;
  7663. }
  7664. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7665. {
  7666. mtrace();
  7667. int result = FAIL;
  7668. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7669. char message[80]={0};
  7670. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7671. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7672. LWS_Send(message);
  7673. result = TRUE;
  7674. return result;
  7675. }
  7676. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7677. {
  7678. mtrace();
  7679. int result = FAIL;
  7680. char message[80]={0};
  7681. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7682. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7683. LWS_Send(message);
  7684. result = TRUE;
  7685. return result;
  7686. }
  7687. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7688. {
  7689. mtrace();
  7690. int result = FAIL;
  7691. char message[80]={0};
  7692. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7693. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7694. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7695. LWS_Send(message);
  7696. result = TRUE;
  7697. return result;
  7698. }
  7699. int sendUpdateFirmwareConfirmation(char *uuid)
  7700. {
  7701. mtrace();
  7702. int result = FAIL;
  7703. char message[60]={0};
  7704. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7705. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7706. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7707. LWS_Send(message);
  7708. result = TRUE;
  7709. return result;
  7710. }
  7711. int sendCertificateSignedConfirmation(char *uuid)
  7712. {
  7713. mtrace();
  7714. int result = PASS;
  7715. char message[4096]={0};
  7716. json_object *CertificateSigned = json_object_new_object();
  7717. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7718. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  7719. sprintf(message,"[%d,\"%s\",%s]"
  7720. ,MESSAGE_TYPE_CALLRESULT
  7721. ,uuid
  7722. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7723. json_object_put(CertificateSigned);
  7724. LWS_Send(message);
  7725. return result;
  7726. }
  7727. int sendDeleteCertificateConfirmation(char *uuid)
  7728. {
  7729. mtrace();
  7730. int result = PASS;
  7731. char message[4096]={0};
  7732. json_object *DeleteCertificate = json_object_new_object();
  7733. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7734. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  7735. sprintf(message,"[%d,\"%s\",%s]"
  7736. ,MESSAGE_TYPE_CALLRESULT
  7737. ,uuid
  7738. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7739. json_object_put(DeleteCertificate);
  7740. LWS_Send(message);
  7741. return result;
  7742. }
  7743. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7744. {
  7745. mtrace();
  7746. int result = PASS;
  7747. char message[4096]={0};
  7748. json_object *ExtendedTriggerMessage = json_object_new_object();
  7749. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7750. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  7751. sprintf(message,"[%d,\"%s\",%s]"
  7752. ,MESSAGE_TYPE_CALLRESULT
  7753. ,uuid
  7754. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7755. json_object_put(ExtendedTriggerMessage);
  7756. LWS_Send(message);
  7757. return result;
  7758. }
  7759. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7760. {
  7761. mtrace();
  7762. int result = PASS;
  7763. char message[4096]={0};
  7764. json_object *GetInstalledCertificateIds = json_object_new_object();
  7765. json_object *certificateHashDataDatas = json_object_new_array();
  7766. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7767. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  7768. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7769. {
  7770. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7771. {
  7772. json_object *certificateHashData = json_object_new_object();
  7773. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7774. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7775. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7776. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7777. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7778. }
  7779. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7780. }
  7781. else
  7782. {
  7783. json_object_put(certificateHashDataDatas);
  7784. }
  7785. sprintf(message,"[%d,\"%s\",%s]"
  7786. ,MESSAGE_TYPE_CALLRESULT
  7787. ,uuid
  7788. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7789. json_object_put(GetInstalledCertificateIds);
  7790. LWS_Send(message);
  7791. return result;
  7792. }
  7793. int sendGetLogConfirmation(char *uuid)
  7794. {
  7795. mtrace();
  7796. int result = PASS;
  7797. char message[4096]={0};
  7798. json_object *GetLog = json_object_new_object();
  7799. DEBUG_INFO("sendGetLogConfirmation...\n");
  7800. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  7801. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  7802. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  7803. sprintf(message,"[%d,\"%s\",%s]"
  7804. ,MESSAGE_TYPE_CALLRESULT
  7805. ,uuid
  7806. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7807. json_object_put(GetLog);
  7808. LWS_Send(message);
  7809. return result;
  7810. }
  7811. int sendInstallCertificateConfirmation(char *uuid)
  7812. {
  7813. mtrace();
  7814. int result = PASS;
  7815. char message[4096]={0};
  7816. json_object *InstallCertificate = json_object_new_object();
  7817. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7818. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  7819. sprintf(message,"[%d,\"%s\",%s]"
  7820. ,MESSAGE_TYPE_CALLRESULT
  7821. ,uuid
  7822. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7823. json_object_put(InstallCertificate);
  7824. LWS_Send(message);
  7825. return result;
  7826. }
  7827. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7828. {
  7829. mtrace();
  7830. int result = PASS;
  7831. char message[4096]={0};
  7832. json_object *SignedUpdateFirmware = json_object_new_object();
  7833. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7834. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  7835. sprintf(message,"[%d,\"%s\",%s]"
  7836. ,MESSAGE_TYPE_CALLRESULT
  7837. ,uuid
  7838. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7839. json_object_put(SignedUpdateFirmware);
  7840. LWS_Send(message);
  7841. return result;
  7842. }
  7843. int sendUnknownConfirmation(char *uuid)
  7844. {
  7845. mtrace();
  7846. int result = PASS;
  7847. char message[256]={0};
  7848. DEBUG_INFO("sendUnknownConfirmation...\n");
  7849. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7850. LWS_Send(message);
  7851. return result;
  7852. }
  7853. //==========================================
  7854. // Handle server request routine Start
  7855. //==========================================
  7856. int handleCancelReservationRequest(char *uuid, char *payload)
  7857. {
  7858. mtrace();
  7859. int result = FAIL;
  7860. int gunNO = 0;
  7861. int reservationIdInt = -1;
  7862. char comfirmstr[20];
  7863. DEBUG_INFO("handleCancelReservationRequest...\n");
  7864. json_object *CancelReservation;
  7865. CancelReservation = json_tokener_parse(payload);
  7866. if(!is_error(CancelReservation))
  7867. {
  7868. // Required data
  7869. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7870. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7871. }
  7872. json_object_put(CancelReservation);
  7873. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7874. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7875. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7876. if(reservationIdInt != -1)
  7877. {
  7878. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7879. //check Transaction active
  7880. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7881. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7882. {
  7883. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7884. {
  7885. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7886. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7887. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7888. {
  7889. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7890. }
  7891. else
  7892. {
  7893. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7894. }
  7895. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7896. goto end;
  7897. }
  7898. }
  7899. for (int index = 0; index < CCS_QUANTITY; index++)
  7900. {
  7901. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7902. {
  7903. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7904. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7905. if(gunType[2] == GUN_TYPE_CCS)
  7906. {
  7907. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7908. }
  7909. else
  7910. {
  7911. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7912. }
  7913. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7914. goto end;
  7915. }
  7916. }
  7917. for (int index = 0; index < GB_QUANTITY; index++)
  7918. {
  7919. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7920. {
  7921. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7922. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7923. if(gunType[2] == GUN_TYPE_GBT)
  7924. {
  7925. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7926. }
  7927. else
  7928. {
  7929. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7930. }
  7931. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7932. goto end;
  7933. }
  7934. }
  7935. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7936. {
  7937. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7938. {
  7939. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7940. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7941. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7942. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7943. goto end;
  7944. }
  7945. }
  7946. for (int index = 0; index < AC_QUANTITY; index++)
  7947. {
  7948. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7949. {
  7950. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7951. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7952. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7953. {
  7954. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7955. }
  7956. else
  7957. {
  7958. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7959. }
  7960. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7961. goto end;
  7962. }
  7963. }
  7964. }
  7965. //The reservationId does NOT match the reservationId
  7966. sendCancelReservationConfirmation(uuid, comfirmstr);
  7967. end:
  7968. // Fill in ocpp packet uuid
  7969. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  7970. return result;
  7971. }
  7972. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7973. {
  7974. mtrace();
  7975. int result = FAIL;
  7976. int gunIndex = -1;
  7977. char typeStr[16]={0};
  7978. char comfirmstr[20];
  7979. int specificId = FALSE;
  7980. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7981. json_object *ChangeAvailability;
  7982. ChangeAvailability = json_tokener_parse(payload);
  7983. if(!is_error(ChangeAvailability))
  7984. {
  7985. // Required data
  7986. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7987. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7988. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7989. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7990. }
  7991. json_object_put(ChangeAvailability);
  7992. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7993. {
  7994. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7995. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7996. }
  7997. else if(gunIndex == 0)
  7998. {
  7999. for(int i=0; i < gunTotalNumber; i++)
  8000. {
  8001. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8002. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8003. }
  8004. }
  8005. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8006. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8007. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8008. {
  8009. specificId = TRUE;
  8010. }
  8011. if(specificId == FALSE)
  8012. goto end;
  8013. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8014. {
  8015. //----------------------gunIndex is 0 ------------------------------------------------//
  8016. if(gunIndex == 0)
  8017. {
  8018. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8019. {
  8020. for(int i=0; i < gunTotalNumber; i++)
  8021. {
  8022. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8023. {
  8024. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8025. {
  8026. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8027. {
  8028. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8029. goto end;
  8030. }
  8031. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8032. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8033. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8034. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8035. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8036. {
  8037. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8038. goto end;
  8039. }
  8040. }
  8041. }//END FOR CHAdeMO_QUANTITY
  8042. for (int index = 0; index < CCS_QUANTITY; index++)
  8043. {
  8044. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8045. {
  8046. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8047. {
  8048. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8049. goto end;
  8050. }
  8051. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8052. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8053. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8054. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8055. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8056. {
  8057. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8058. goto end;
  8059. }
  8060. }
  8061. }//END FOR CCS_QUANTITY
  8062. for (int index = 0; index < GB_QUANTITY; index++)
  8063. {
  8064. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8065. {
  8066. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8067. {
  8068. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8069. goto end;
  8070. }
  8071. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8072. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8073. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8074. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8075. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8076. {
  8077. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8078. goto end;
  8079. }
  8080. }
  8081. }// END FOR GB_QUANTITY
  8082. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8083. {
  8084. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8085. {
  8086. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8087. {
  8088. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8089. goto end;
  8090. }
  8091. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8092. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8093. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8094. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8095. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8096. {
  8097. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8098. goto end;
  8099. }
  8100. }
  8101. }// END FOR GENERAL_GUN_QUANTITY
  8102. for (int index = 0; index < AC_QUANTITY; index++)
  8103. {
  8104. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8105. {
  8106. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8107. {
  8108. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8109. goto end;
  8110. }
  8111. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8112. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8113. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8114. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8115. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8116. {
  8117. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8118. goto end;
  8119. }
  8120. }
  8121. }//END FOR AC_QUANTITY
  8122. }// END FOR gunTotalNumber
  8123. }
  8124. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8125. {
  8126. for(int i=0; i < gunTotalNumber; i++)
  8127. {
  8128. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8129. {
  8130. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8131. goto end;
  8132. }
  8133. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8134. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8135. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8136. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8137. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8138. {
  8139. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8140. goto end;
  8141. }
  8142. }
  8143. }
  8144. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8145. goto end;
  8146. }
  8147. //----------------------gunIndex is not 0 ------------------------------------------------//
  8148. //check Transaction active
  8149. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8150. {
  8151. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8152. {
  8153. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8154. {
  8155. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8156. goto end;
  8157. }
  8158. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8159. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8160. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8161. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8162. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8163. {
  8164. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8165. goto end;
  8166. }
  8167. else
  8168. {
  8169. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8170. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8171. goto end;
  8172. }
  8173. }
  8174. }//END FOR CHAdeMO_QUANTITY
  8175. for (int index = 0; index < CCS_QUANTITY; index++)
  8176. {
  8177. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8178. {
  8179. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8180. {
  8181. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8182. goto end;
  8183. }
  8184. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8185. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8186. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8187. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8188. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8189. {
  8190. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8191. goto end;
  8192. }
  8193. else
  8194. {
  8195. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8196. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8197. goto end;
  8198. }
  8199. }
  8200. }//END FOR CCS_QUANTITY
  8201. for (int index = 0; index < GB_QUANTITY; index++)
  8202. {
  8203. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8204. {
  8205. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8206. {
  8207. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8208. goto end;
  8209. }
  8210. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8211. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8212. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8213. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8214. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8215. {
  8216. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8217. goto end;
  8218. }
  8219. else
  8220. {
  8221. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8222. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8223. goto end;
  8224. }
  8225. }
  8226. }// END FOR GB_QUANTITY
  8227. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8228. {
  8229. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8230. {
  8231. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8232. {
  8233. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8234. goto end;
  8235. }
  8236. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8237. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8238. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8239. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8240. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8241. {
  8242. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8243. goto end;
  8244. }
  8245. else
  8246. {
  8247. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8248. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8249. goto end;
  8250. }
  8251. }
  8252. }// END FOR GENERAL_GUN_QUANTITY
  8253. for (int index = 0; index < AC_QUANTITY; index++)
  8254. {
  8255. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8256. {
  8257. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8258. {
  8259. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8260. goto end;
  8261. }
  8262. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8263. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8264. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8265. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8266. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8267. {
  8268. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8269. goto end;
  8270. }
  8271. else
  8272. {
  8273. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8274. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8275. goto end;
  8276. }
  8277. }
  8278. }//END FOR AC_QUANTITY
  8279. }//END FOR AvailabilityTypeStr[Inoperative]
  8280. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8281. {
  8282. //----------------------gunIndex is 0 ------------------------------------------------//
  8283. if(gunIndex == 0)
  8284. {
  8285. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8286. {
  8287. for(int i=0; i < gunTotalNumber; i++)
  8288. {
  8289. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8290. {
  8291. 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
  8292. {
  8293. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8294. goto end;
  8295. }
  8296. }//END FOR CHAdeMO_QUANTITY
  8297. for (int index = 0; index < CCS_QUANTITY; index++)
  8298. {
  8299. 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
  8300. {
  8301. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8302. goto end;
  8303. }
  8304. }//END FOR CCS_QUANTITY
  8305. for (int index = 0; index < GB_QUANTITY; index++)
  8306. {
  8307. 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
  8308. {
  8309. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8310. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8311. goto end;
  8312. }
  8313. }// END FOR GB_QUANTITY
  8314. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8315. {
  8316. 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
  8317. {
  8318. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8319. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8320. goto end;
  8321. }
  8322. }// END FOR GENERAL_GUN_QUANTITY
  8323. for (int index = 0; index < AC_QUANTITY; index++)
  8324. {
  8325. 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
  8326. {
  8327. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8328. goto end;
  8329. }
  8330. }//END FOR CHAdeMO_QUANTITY
  8331. }// END FOR gunTotalNumber
  8332. }
  8333. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8334. {
  8335. for(int i=0; i < gunTotalNumber; i++)
  8336. {
  8337. for (int index = 0; index < AC_QUANTITY; index++)
  8338. {
  8339. 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
  8340. {
  8341. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8342. goto end;
  8343. }
  8344. }//END FOR CHAdeMO_QUANTITY
  8345. } // END FOR gunTotalNumber
  8346. }
  8347. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8348. goto end;
  8349. }
  8350. //----------------------gunIndex is not 0 ------------------------------------------------//
  8351. //check Transaction active
  8352. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8353. {
  8354. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8355. {
  8356. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8357. goto end;
  8358. }
  8359. }//END FOR CHAdeMO_QUANTITY
  8360. for (int index = 0; index < CCS_QUANTITY; index++)
  8361. {
  8362. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8363. {
  8364. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8365. goto end;
  8366. }
  8367. }//END FOR CCS_QUANTITY
  8368. for (int index = 0; index < GB_QUANTITY; index++)
  8369. {
  8370. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8371. {
  8372. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8373. goto end;
  8374. }
  8375. }// END FOR GB_QUANTITY
  8376. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8377. {
  8378. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8379. {
  8380. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8381. goto end;
  8382. }
  8383. }// END FOR GENERAL_GUN_QUANTITY
  8384. for (int index = 0; index < AC_QUANTITY; index++)
  8385. {
  8386. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8387. {
  8388. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8389. goto end;
  8390. }
  8391. }//END FOR AC_QUANTITY
  8392. }//END FOR AvailabilityTypeStr[Operative]
  8393. end:
  8394. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8395. {
  8396. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8397. }
  8398. else
  8399. {
  8400. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8401. }
  8402. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8403. {
  8404. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8405. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8406. }
  8407. else if(gunIndex == 0)
  8408. {
  8409. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8410. {
  8411. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8412. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8413. }
  8414. }
  8415. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8416. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8417. return result;
  8418. }
  8419. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8420. {
  8421. mtrace();
  8422. int valueInvalid = NO;
  8423. int result = FAIL;
  8424. char keystr[40]={0};
  8425. char valuestr[501]={0}; //value should be limited in 500 bytes
  8426. char comfirmstr[20]={0};
  8427. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8428. json_object *ChangeConfiguration;
  8429. ChangeConfiguration = json_tokener_parse(payload);
  8430. if(!is_error(ChangeConfiguration))
  8431. {
  8432. // Required data
  8433. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8434. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8435. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8436. {
  8437. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8438. }
  8439. else
  8440. {
  8441. valueInvalid = YES;
  8442. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8443. }
  8444. }
  8445. json_object_put(ChangeConfiguration);
  8446. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  8447. {
  8448. DEBUG_ERROR("Payload is null or value is invalid.\n");
  8449. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8450. }
  8451. else
  8452. {
  8453. int status = setKeyValue(keystr, valuestr);
  8454. switch(status)
  8455. {
  8456. case ConfigurationStatus_Accepted:
  8457. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8458. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8459. StoreConfigurationTable();
  8460. break;
  8461. case RebootRequired:
  8462. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8463. StoreConfigurationTable();
  8464. break;
  8465. case NotSupported:
  8466. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8467. break;
  8468. case ConfigurationStatus_Rejected:
  8469. default:
  8470. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8471. break;
  8472. }
  8473. }
  8474. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8475. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8476. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8477. {
  8478. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8479. SetOcppConnStatus(FALSE);
  8480. }
  8481. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8482. {
  8483. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8484. }
  8485. return result;
  8486. }
  8487. int handleClearCacheRequest(char *uuid, char *payload)
  8488. {
  8489. mtrace();
  8490. int result = FAIL;
  8491. char comfirmstr[20];
  8492. char rmFileCmd[100]={0};
  8493. struct stat stats;
  8494. DEBUG_INFO("handleClearCacheRequest...\n");
  8495. stat("/Storage/OCPP", &stats);
  8496. // Check for directory existence
  8497. if (S_ISDIR(stats.st_mode) == 1)
  8498. {}
  8499. else
  8500. {
  8501. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8502. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  8503. system(rmFileCmd);
  8504. }
  8505. if(OCPP_cleanLocalCache())
  8506. {
  8507. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8508. }
  8509. else
  8510. {
  8511. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8512. }
  8513. sendClearCacheConfirmation(uuid, comfirmstr);
  8514. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8515. return result;
  8516. }
  8517. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8518. {
  8519. mtrace();
  8520. int result = FAIL;
  8521. int resultRename;
  8522. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8523. char chargingProfilePurposeStr[26]={0};
  8524. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8525. char tempchargingProfilePurposeStr[26]={0};
  8526. char str[100]={0};
  8527. char fname[200]={0};
  8528. char comfirmstr[20]={0};
  8529. char word[1600]={0};
  8530. int clearflag = FALSE;
  8531. int chargingProfileIdIsNULL = FALSE;
  8532. int connectorIsNULL = FALSE;
  8533. int chargingProfilePurposeIsNULL = FALSE;
  8534. int stackLevelIsNULL = FALSE;
  8535. //int GotoEnd = FALSE;
  8536. FILE *fptr1, *fptr2;
  8537. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  8538. int n_chargingProfile=0;
  8539. int isEmptyFile = FALSE;
  8540. char sLineWord[1600]={0};
  8541. char chargingProfiles[10][100]={0};
  8542. int ChargeProfileCount = 0;
  8543. int ch;
  8544. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8545. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8546. json_object *ClearChargingProfile;
  8547. ClearChargingProfile = json_tokener_parse(payload);
  8548. if(!is_error(ClearChargingProfile))
  8549. {
  8550. // Optional data
  8551. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8552. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8553. else
  8554. chargingProfileIdIsNULL = TRUE;
  8555. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8556. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8557. else
  8558. connectorIsNULL = TRUE;
  8559. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8560. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8561. else
  8562. chargingProfilePurposeIsNULL = TRUE;
  8563. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8564. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8565. else
  8566. stackLevelIsNULL = TRUE;
  8567. }
  8568. json_object_put(ClearChargingProfile);
  8569. if(connectorIsNULL == FALSE)
  8570. {
  8571. switch(connectorIdInt)
  8572. {
  8573. case 0:
  8574. if(chargingProfilePurposeIsNULL == TRUE)
  8575. {
  8576. int l = 0;
  8577. strcpy(fname, ChargePointMaxProfile_JSON);
  8578. if((access(fname,F_OK))!=-1)
  8579. {
  8580. strcpy(chargingProfiles[l], fname);
  8581. l = l + 1;
  8582. }
  8583. strcpy(fname, TxDefaultProfile_0_JSON);
  8584. if((access(fname,F_OK))!=-1)
  8585. {
  8586. strcpy(chargingProfiles[l], fname);
  8587. l = l + 1;
  8588. }
  8589. ChargeProfileCount = l;
  8590. }
  8591. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8592. {
  8593. strcpy(fname, ChargePointMaxProfile_JSON);
  8594. if((access(fname,F_OK))!=-1)
  8595. {
  8596. strcpy(chargingProfiles[0], fname);
  8597. ChargeProfileCount = 1;
  8598. }
  8599. }
  8600. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8601. {
  8602. strcpy(fname, TxDefaultProfile_0_JSON);
  8603. if((access(fname,F_OK))!=-1)
  8604. {
  8605. strcpy(chargingProfiles[0], fname);
  8606. ChargeProfileCount = 1;
  8607. }
  8608. }
  8609. break;
  8610. default:
  8611. if(chargingProfilePurposeIsNULL == TRUE)
  8612. {
  8613. int m = 0;
  8614. memset(fname, 0, ARRAY_SIZE(fname));
  8615. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8616. if((access(fname,F_OK))!=-1)
  8617. {
  8618. strcpy(chargingProfiles[m], fname);
  8619. m = m + 1;
  8620. }
  8621. memset(fname, 0, ARRAY_SIZE(fname));
  8622. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8623. if((access(fname,F_OK))!=-1)
  8624. {
  8625. strcpy(chargingProfiles[m], fname);
  8626. m = m + 1;
  8627. }
  8628. ChargeProfileCount = m;
  8629. }
  8630. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8631. {
  8632. //strcpy(fname, TxDefaultProfile_1_JSON);
  8633. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8634. if((access(fname,F_OK))!=-1)
  8635. {
  8636. strcpy(chargingProfiles[0], fname);
  8637. ChargeProfileCount = 1;
  8638. }
  8639. }
  8640. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8641. {
  8642. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8643. if((access(fname,F_OK))!=-1)
  8644. {
  8645. strcpy(chargingProfiles[0], fname);
  8646. ChargeProfileCount = 1;
  8647. }
  8648. //strcpy(fname, TxProfile_1_JSON);
  8649. }
  8650. //strcpy(fname, ChargePointMaxProfile_JSON );
  8651. break;
  8652. }
  8653. }
  8654. else // Check all Charging Profiles
  8655. {
  8656. int i = 0;
  8657. char fnametemp[200]={0};
  8658. ChargeProfileCount = 0;
  8659. //Check ChargePointMaxProfile.json exit
  8660. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8661. {
  8662. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  8663. i = i + 1;
  8664. }
  8665. //Check TxDefaultProfile_0.json exit
  8666. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8667. {
  8668. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  8669. i = i + 1;
  8670. }
  8671. //Check TxDefaultProfile_%d.json
  8672. for(int j=1; j <= gunTotalNumber; j++)
  8673. {
  8674. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8675. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8676. if((access(fnametemp,F_OK))!=-1)
  8677. {
  8678. strcpy(chargingProfiles[i], fnametemp);
  8679. i = i + 1;
  8680. }
  8681. }
  8682. //Check TxProfile_%d.json
  8683. for(int j=1; j <= gunTotalNumber; j++)
  8684. {
  8685. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8686. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8687. if((access(fnametemp,F_OK))!=-1)
  8688. {
  8689. strcpy(chargingProfiles[i], fnametemp);
  8690. i = i + 1;
  8691. }
  8692. }
  8693. ChargeProfileCount = i;
  8694. }// End connectorIsNULL is TRUE
  8695. if(ChargeProfileCount == 0)
  8696. {
  8697. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8698. goto end;
  8699. }
  8700. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8701. {
  8702. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8703. goto end;
  8704. }
  8705. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8706. {
  8707. memset(str, 0, ARRAY_SIZE(str));
  8708. // clear temp file
  8709. sprintf(str,"rm -f %s",temp);
  8710. system(str);
  8711. for(int k=0; k < ChargeProfileCount; k++)
  8712. {
  8713. memset(str, 0, ARRAY_SIZE(str));
  8714. //clear file in C
  8715. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8716. system(str);
  8717. }
  8718. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8719. goto end;
  8720. }
  8721. else if(connectorIsNULL == TRUE)
  8722. {
  8723. for(int k=0; k < ChargeProfileCount; k++)
  8724. {
  8725. fptr1 = fopen(chargingProfiles[k], "r");
  8726. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  8727. //Check Charging Profile Count
  8728. while(fscanf(fptr1, "%s", word) != EOF)
  8729. {
  8730. //DEBUG_INFO("word=%s\n",word);
  8731. if(strstr(word, "chargingProfileId")!= NULL)
  8732. {
  8733. //DEBUG_INFO("test chargingProfileId \n");
  8734. n_chargingProfile = n_chargingProfile + 1;
  8735. //DEBUG_INFO("chargingProfileId Found\n");
  8736. }
  8737. }
  8738. rewind(fptr1);
  8739. //search Charging Profile Element
  8740. //int i= 0;
  8741. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8742. {
  8743. json_object *tmpProfilee;
  8744. tmpProfilee = json_tokener_parse(sLineWord);
  8745. if(!is_error(tmpProfilee))
  8746. {
  8747. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8748. {
  8749. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8750. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8751. }
  8752. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8753. {
  8754. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8755. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8756. }
  8757. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8758. {
  8759. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8760. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8761. }
  8762. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8763. {
  8764. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8765. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8766. }
  8767. }
  8768. json_object_put(tmpProfilee);
  8769. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8770. {
  8771. //------- not write to fptr2-------//
  8772. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8773. //clearflag = TRUE;
  8774. }
  8775. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8776. {
  8777. //------- not write to fptr2-------//
  8778. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8779. }
  8780. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8781. {
  8782. //------- not write to fptr2-------//
  8783. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8784. }
  8785. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8786. {
  8787. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8788. }
  8789. else
  8790. {
  8791. fprintf(fptr2, sLineWord);//writing data into file
  8792. }
  8793. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8794. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8795. if(clearflag == TRUE)
  8796. {
  8797. fclose(fptr1);
  8798. fclose(fptr2);
  8799. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8800. system(str);
  8801. // clear temp file
  8802. sprintf(str,"rm -f %s",temp);
  8803. system(str);
  8804. }
  8805. else
  8806. {
  8807. fclose(fptr1);
  8808. fclose(fptr2);
  8809. memset(str, 0, ARRAY_SIZE(str));
  8810. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8811. system(str);
  8812. resultRename = rename(temp, chargingProfiles[k]);
  8813. if(resultRename == 0)
  8814. {
  8815. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8816. }
  8817. else
  8818. {
  8819. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8820. }
  8821. if(comfirmstr[0]== 0)
  8822. {
  8823. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8824. }
  8825. //Check chargingProfile is empty file
  8826. /*------ Read the file ----------------*/
  8827. fptr1=fopen(chargingProfiles[k],"r");
  8828. ch=fgetc(fptr1);
  8829. rewind(fptr1);
  8830. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8831. if(ch!=EOF)
  8832. {
  8833. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8834. {
  8835. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8836. if(sLineWord[0]=='\0')
  8837. {
  8838. isEmptyFile = TRUE;
  8839. break;
  8840. }
  8841. else
  8842. {
  8843. isEmptyFile = FALSE;
  8844. break;
  8845. }
  8846. }
  8847. }
  8848. else
  8849. isEmptyFile = TRUE;
  8850. fclose(fptr1);
  8851. if(isEmptyFile == TRUE)
  8852. {
  8853. memset(str, 0, ARRAY_SIZE(str));
  8854. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8855. system(str);
  8856. }
  8857. }
  8858. }// End of while(int k=0; k < ChargePointCount; k++)
  8859. }
  8860. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8861. {
  8862. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8863. for(int k=0; k < ChargeProfileCount; k++)
  8864. {
  8865. fptr1 = fopen(chargingProfiles[k], "r");
  8866. fptr2 = fopen(temp, "w+");
  8867. //Check Charging Profile Count
  8868. while(fscanf(fptr1, "%s", word) != EOF)
  8869. {
  8870. //DEBUG_INFO("word=%s\n",word);
  8871. if(strstr(word, "chargingProfileId")!= NULL)
  8872. {
  8873. n_chargingProfile = n_chargingProfile + 1;
  8874. }
  8875. }
  8876. rewind(fptr1);
  8877. //search Charging Profile Element
  8878. //int i= 0;
  8879. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8880. {
  8881. json_object *tmpProfilee;
  8882. tmpProfilee = json_tokener_parse(sLineWord);
  8883. if(!is_error(tmpProfilee))
  8884. {
  8885. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8886. {
  8887. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8888. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8889. }
  8890. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8891. {
  8892. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8893. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8894. }
  8895. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8896. {
  8897. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8898. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8899. }
  8900. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8901. {
  8902. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8903. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8904. }
  8905. }
  8906. json_object_put(tmpProfilee);
  8907. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8908. {
  8909. //------- not write to fptr2-------//
  8910. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8911. //clearflag = TRUE;
  8912. }
  8913. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8914. {
  8915. //------- not write to fptr2-------//
  8916. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8917. }
  8918. else if(stackLevelIsNULL == TRUE)
  8919. {
  8920. //Clear Whole File
  8921. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8922. clearflag = TRUE;
  8923. break;
  8924. }
  8925. else
  8926. {
  8927. fprintf(fptr2, sLineWord);//writing data into file
  8928. }
  8929. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8930. }
  8931. if(clearflag == TRUE)
  8932. {
  8933. fclose(fptr1);
  8934. fclose(fptr2);
  8935. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8936. system(str);
  8937. // clear temp file
  8938. sprintf(str,"rm -f %s",temp);
  8939. system(str);
  8940. }
  8941. else
  8942. {
  8943. fclose(fptr1);
  8944. fclose(fptr2);
  8945. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8946. system(str);
  8947. resultRename = rename(temp, chargingProfiles[k]);
  8948. if(resultRename == 0)
  8949. {
  8950. DEBUG_INFO("File ChargingProfile renamed successfully");
  8951. }
  8952. else
  8953. {
  8954. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8955. }
  8956. if(comfirmstr[0]== 0)
  8957. {
  8958. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8959. }
  8960. //Check chargingProfile is empty file
  8961. /*------ Read the file ----------------*/
  8962. fptr1=fopen(chargingProfiles[k],"r");
  8963. ch=fgetc(fptr1);
  8964. rewind(fptr1);
  8965. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8966. if(ch!=EOF)
  8967. {
  8968. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8969. {
  8970. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8971. if(sLineWord[0]=='\0')
  8972. {
  8973. isEmptyFile = TRUE;
  8974. break;
  8975. }
  8976. else
  8977. {
  8978. isEmptyFile = FALSE;
  8979. break;
  8980. }
  8981. }
  8982. }
  8983. else
  8984. isEmptyFile = TRUE;
  8985. fclose(fptr1);
  8986. if(isEmptyFile == TRUE)
  8987. {
  8988. memset(str, 0, ARRAY_SIZE(str));
  8989. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8990. system(str);
  8991. }
  8992. /*------- End of reading ---------------*/
  8993. }
  8994. } // while(int k=0; k < ChargeProfileCount; k++)
  8995. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8996. end:
  8997. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8998. {
  8999. if(connectorIdInt == 0)
  9000. {
  9001. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9002. {
  9003. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9004. }
  9005. }
  9006. else
  9007. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9008. }
  9009. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9010. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9011. return result;
  9012. }
  9013. void createFirmwareVersionByDataTransfer(void)
  9014. {
  9015. json_object *FirmwareDataTransfer = json_object_new_object();
  9016. // AC & DC model
  9017. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9018. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9019. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9020. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9021. // DC model
  9022. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9023. {
  9024. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9025. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9026. (gunType[3] != GUN_TYPE_UNKNOWN))
  9027. {
  9028. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9029. }
  9030. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9031. {
  9032. // DS DM DW
  9033. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9034. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9035. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9036. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9037. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9038. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9039. }
  9040. else
  9041. {
  9042. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9043. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9044. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9045. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9046. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9047. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9048. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9049. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9050. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9051. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9052. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9053. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9054. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9055. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9056. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9057. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9058. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9059. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9060. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9061. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9062. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9063. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9064. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9065. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9066. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9067. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9068. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9069. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9070. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9071. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9072. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9073. }
  9074. }
  9075. // 4G model
  9076. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9077. {
  9078. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9079. }
  9080. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9081. json_object_put(FirmwareDataTransfer);
  9082. }
  9083. int handleDataTransferRequest(char *uuid, char *payload)
  9084. {
  9085. mtrace();
  9086. json_object *response = json_object_new_object();
  9087. int result = FAIL;
  9088. char tempvendorId[255]={0};
  9089. char tempmessageId[50]={0};
  9090. char tempdata[512]={0};
  9091. char message[2048]={0};
  9092. DEBUG_INFO("handleDataTransferRequest...\n");
  9093. if((uuid != NULL) && (payload != NULL))
  9094. {
  9095. json_object *DataTransfer;
  9096. DataTransfer = json_tokener_parse(payload);
  9097. if(!is_error(DataTransfer))
  9098. {
  9099. // Required data
  9100. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9101. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9102. // Optional data
  9103. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9104. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9105. if(json_object_object_get(DataTransfer, "data") != NULL)
  9106. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9107. result = PASS;
  9108. }
  9109. json_object_put(DataTransfer);
  9110. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9111. {
  9112. // Send all moudle firmware version on EVSE
  9113. createFirmwareVersionByDataTransfer();
  9114. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9115. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9116. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9117. json_object_put(response);
  9118. }
  9119. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9120. {
  9121. system("/usr/bin/run_tmate_restart.sh &");
  9122. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9123. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9124. json_object_put(response);
  9125. }
  9126. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9127. {
  9128. json_object *data;
  9129. data = json_tokener_parse(tempdata);
  9130. if(!is_error(data))
  9131. {
  9132. 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))
  9133. {
  9134. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9135. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9136. if(json_object_object_get(data, "SOC") != NULL)
  9137. {
  9138. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9139. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9140. }
  9141. if(json_object_object_get(data, "Energy") != NULL)
  9142. {
  9143. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9144. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9145. }
  9146. if(json_object_object_get(data, "Duration") != NULL)
  9147. {
  9148. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9149. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9150. }
  9151. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9152. }
  9153. else
  9154. {
  9155. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9156. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9157. }
  9158. }
  9159. else
  9160. {
  9161. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9162. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9163. }
  9164. json_object_put(data);
  9165. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9166. json_object_put(response);
  9167. }
  9168. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9169. {
  9170. json_object *data;
  9171. data = json_tokener_parse(tempdata);
  9172. if(!is_error(data))
  9173. {
  9174. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9175. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9176. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9177. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9178. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9179. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9180. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9181. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9182. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9183. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9184. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9185. }
  9186. else
  9187. {
  9188. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9189. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9190. }
  9191. json_object_put(data);
  9192. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9193. json_object_put(response);
  9194. }
  9195. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9196. {
  9197. json_object *data;
  9198. data = json_tokener_parse(tempdata);
  9199. if(!is_error(data))
  9200. {
  9201. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9202. if(json_object_object_get(data, "idToken") != NULL)
  9203. {
  9204. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9205. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9206. }
  9207. if(json_object_object_get(data, "price") != NULL)
  9208. {
  9209. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9210. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9211. }
  9212. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9213. }
  9214. else
  9215. {
  9216. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9217. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9218. }
  9219. json_object_put(data);
  9220. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9221. json_object_put(response);
  9222. }
  9223. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9224. {
  9225. json_object *data;
  9226. data = json_tokener_parse(tempdata);
  9227. if(!is_error(data))
  9228. {
  9229. if(json_object_object_get(data, "txId") != NULL)
  9230. {
  9231. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9232. for(int idx = 0;idx<gunTotalNumber;idx++)
  9233. {
  9234. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9235. {
  9236. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9237. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9238. if(json_object_object_get(data, "description") != NULL)
  9239. {
  9240. // California pricing V1.0
  9241. DEBUG_INFO("California pricing V1.0\n");
  9242. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9243. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9244. }
  9245. else
  9246. {
  9247. // California pricing V1.1
  9248. DEBUG_INFO("California pricing V1.1\n");
  9249. if(json_object_object_get(data, "timestamp") != NULL)
  9250. {
  9251. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9252. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9253. }
  9254. if(json_object_object_get(data, "meterValue") != NULL)
  9255. {
  9256. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9257. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9258. }
  9259. if(json_object_object_get(data, "cost") != NULL)
  9260. {
  9261. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9262. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9263. }
  9264. if(json_object_object_get(data, "state") != NULL)
  9265. {
  9266. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9267. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9268. }
  9269. if(json_object_object_get(data, "chargingPrice") != NULL)
  9270. {
  9271. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9272. {
  9273. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9274. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9275. }
  9276. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9277. {
  9278. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9279. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9280. }
  9281. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9282. {
  9283. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9284. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9285. }
  9286. }
  9287. if(json_object_object_get(data, "idlePrice") != NULL)
  9288. {
  9289. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9290. {
  9291. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9292. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9293. }
  9294. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9295. {
  9296. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9297. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9298. }
  9299. }
  9300. if(json_object_object_get(data, "nextPeriod") != NULL)
  9301. {
  9302. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9303. {
  9304. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9305. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9306. }
  9307. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9308. {
  9309. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9310. {
  9311. 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")));
  9312. 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"));
  9313. }
  9314. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9315. {
  9316. 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")));
  9317. 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"));
  9318. }
  9319. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9320. {
  9321. 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")));
  9322. 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"));
  9323. }
  9324. }
  9325. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9326. {
  9327. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9328. {
  9329. 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")));
  9330. 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"));
  9331. }
  9332. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9333. {
  9334. 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")));
  9335. 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"));
  9336. }
  9337. }
  9338. }
  9339. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9340. {
  9341. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9342. {
  9343. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9344. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9345. }
  9346. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9347. {
  9348. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9349. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9350. }
  9351. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9352. {
  9353. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9354. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9355. }
  9356. }
  9357. }
  9358. }
  9359. }
  9360. }
  9361. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9362. }
  9363. else
  9364. {
  9365. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9366. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9367. }
  9368. json_object_put(data);
  9369. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9370. json_object_put(response);
  9371. }
  9372. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9373. {
  9374. json_object *data;
  9375. data = json_tokener_parse(tempdata);
  9376. if(!is_error(data))
  9377. {
  9378. if(json_object_object_get(data, "txId") != NULL)
  9379. {
  9380. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9381. for(int idx = 0;idx<gunTotalNumber;idx++)
  9382. {
  9383. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9384. {
  9385. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9386. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9387. if(json_object_object_get(data, "description") != NULL)
  9388. {
  9389. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9390. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9391. }
  9392. }
  9393. }
  9394. }
  9395. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9396. }
  9397. else
  9398. {
  9399. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9400. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9401. }
  9402. json_object_put(data);
  9403. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9404. json_object_put(response);
  9405. }
  9406. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9407. {
  9408. json_object *data;
  9409. data = json_tokener_parse(tempdata);
  9410. if(!is_error(data))
  9411. {
  9412. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9413. if(json_object_object_get(data, "Content_Type") != NULL)
  9414. {
  9415. 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))
  9416. {
  9417. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9418. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9419. {
  9420. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9421. }
  9422. }
  9423. else
  9424. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9425. }
  9426. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9427. }
  9428. else
  9429. {
  9430. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9431. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9432. }
  9433. json_object_put(data);
  9434. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9435. json_object_put(response);
  9436. }
  9437. else if(strstr(tempmessageId, "ID_DisplayLcdPage") != NULL)
  9438. {
  9439. json_object *data;
  9440. data = json_tokener_parse(tempdata);
  9441. if(!is_error(data))
  9442. {
  9443. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9444. if(json_object_object_get(data, "ConnectorId") != NULL)
  9445. {
  9446. ShmSysConfigAndInfo->SysConfig.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9447. }
  9448. if(json_object_object_get(data, "Page_Index") != NULL)
  9449. {
  9450. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9451. }
  9452. if(json_object_object_get(data, "Duration") != NULL)
  9453. {
  9454. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9455. }
  9456. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  9457. }
  9458. else
  9459. {
  9460. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9461. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9462. }
  9463. json_object_put(data);
  9464. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9465. json_object_put(response);
  9466. }
  9467. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9468. {
  9469. json_object *data;
  9470. data = json_tokener_parse(tempdata);
  9471. if(!is_error(data))
  9472. {
  9473. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9474. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9475. {
  9476. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9477. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9478. else
  9479. {
  9480. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9481. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9482. }
  9483. }
  9484. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9485. {
  9486. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9487. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9488. else
  9489. {
  9490. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9491. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9492. }
  9493. }
  9494. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9495. {
  9496. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9497. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9498. else
  9499. {
  9500. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9501. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9502. }
  9503. }
  9504. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9505. {
  9506. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9507. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9508. else
  9509. {
  9510. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9511. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9512. }
  9513. }
  9514. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9515. {
  9516. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9517. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9518. else
  9519. {
  9520. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9521. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9522. }
  9523. }
  9524. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9525. {
  9526. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9527. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9528. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9529. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9530. else
  9531. {
  9532. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9533. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9534. }
  9535. }
  9536. if(json_object_object_get(data, "isAuthentication") != NULL)
  9537. {
  9538. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9539. {
  9540. case 0:
  9541. case 1:
  9542. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9543. break;
  9544. default:
  9545. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9546. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9547. break;
  9548. }
  9549. }
  9550. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9551. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9552. }
  9553. else
  9554. {
  9555. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9556. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9557. }
  9558. json_object_put(data);
  9559. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9560. json_object_put(response);
  9561. }
  9562. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  9563. {
  9564. json_object *data;
  9565. data = json_tokener_parse(tempdata);
  9566. if(!is_error(data))
  9567. {
  9568. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9569. {
  9570. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  9571. {
  9572. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9573. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9574. }
  9575. else
  9576. {
  9577. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9578. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  9579. }
  9580. }
  9581. else
  9582. {
  9583. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9584. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9585. }
  9586. }
  9587. else
  9588. {
  9589. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9590. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9591. }
  9592. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9593. json_object_put(response);
  9594. }
  9595. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9596. {
  9597. json_object *data;
  9598. data = json_tokener_parse(tempdata);
  9599. if(!is_error(data))
  9600. {
  9601. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9602. if(json_object_object_get(data, "stationName") != NULL)
  9603. {
  9604. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9605. }
  9606. else
  9607. {
  9608. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9609. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9610. }
  9611. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9612. {
  9613. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  9614. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9615. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  9616. }
  9617. }
  9618. else
  9619. {
  9620. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9621. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9622. }
  9623. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9624. json_object_put(response);
  9625. }
  9626. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9627. {
  9628. json_object *data;
  9629. data = json_tokener_parse(tempdata);
  9630. if(!is_error(data))
  9631. {
  9632. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9633. if(json_object_object_get(data, "weatherId") != NULL)
  9634. {
  9635. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9636. }
  9637. else
  9638. {
  9639. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9640. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9641. }
  9642. if(json_object_object_get(data, "Temperature") != NULL)
  9643. {
  9644. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9645. }
  9646. else
  9647. {
  9648. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9649. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9650. }
  9651. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9652. {
  9653. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  9654. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9655. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  9656. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  9657. );
  9658. }
  9659. }
  9660. else
  9661. {
  9662. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9663. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9664. }
  9665. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9666. json_object_put(response);
  9667. }
  9668. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9669. {
  9670. json_object *data;
  9671. data = json_tokener_parse(tempdata);
  9672. if(!is_error(data))
  9673. {
  9674. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9675. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9676. {
  9677. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9678. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9679. }
  9680. else
  9681. {
  9682. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9683. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9684. }
  9685. }
  9686. else
  9687. {
  9688. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9689. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9690. }
  9691. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9692. json_object_put(response);
  9693. }
  9694. else
  9695. {
  9696. // Can not find valid message id
  9697. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9698. }
  9699. }
  9700. else
  9701. {
  9702. // Payload is null
  9703. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9704. }
  9705. LWS_Send(message);
  9706. return result;
  9707. }
  9708. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9709. {
  9710. mtrace();
  9711. int result = FAIL;
  9712. int connectorIdInt, durationInt;
  9713. char chargingRateUnitStr[4]={0};
  9714. char comfirmstr[20];
  9715. int confirmPeriods = 0;
  9716. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9717. json_object *GetCompositeSchedule;
  9718. GetCompositeSchedule = json_tokener_parse(payload);
  9719. if(!is_error(GetCompositeSchedule))
  9720. {
  9721. // Required data
  9722. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9723. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9724. else
  9725. connectorIdInt = -1;
  9726. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9727. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9728. else
  9729. durationInt = 86400;
  9730. // Optional data
  9731. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9732. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9733. }
  9734. json_object_put(GetCompositeSchedule);
  9735. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9736. if((connectorIdInt == 0) ||
  9737. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9738. {
  9739. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9740. struct StructChargingProfile tmpProfile[1];
  9741. if(strstr(chargingRateUnitStr, "W") != NULL)
  9742. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9743. else
  9744. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9745. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9746. {
  9747. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9748. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9749. }
  9750. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9751. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9752. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9753. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9754. {
  9755. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9756. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9757. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9758. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9759. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9760. {
  9761. confirmPeriods = idx;
  9762. break;
  9763. }
  9764. }
  9765. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9766. {
  9767. confirmPeriods += 1;
  9768. }
  9769. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9770. }
  9771. else
  9772. {
  9773. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9774. }
  9775. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9776. return result;
  9777. }
  9778. int handleGetConfigurationRequest(char *uuid, char *payload)
  9779. {
  9780. mtrace();
  9781. int result = FAIL;
  9782. int MaxKeySupported = 0;
  9783. int n_keys = 0;
  9784. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9785. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9786. json_object *GetConfiguration;
  9787. GetConfiguration = json_tokener_parse(payload);
  9788. if(!is_error(GetConfiguration))
  9789. {
  9790. // Optional data
  9791. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9792. {
  9793. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9794. {
  9795. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9796. n_keys = idx + 1;
  9797. }
  9798. }
  9799. }
  9800. json_object_put(GetConfiguration);
  9801. UnknownKeynum = 0;
  9802. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9803. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9804. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9805. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9806. if(n_keys != 0)
  9807. {
  9808. for(int i=0;i<n_keys;i++)
  9809. {
  9810. getKeyValue(requestKey[i]);
  9811. }
  9812. }
  9813. else
  9814. {
  9815. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9816. getKeyValue("");
  9817. }
  9818. processUnkownKey();
  9819. sendGetConfigurationConfirmation(uuid);
  9820. return result;
  9821. }
  9822. static char fnamePlusPath[100]={0};
  9823. static char fnamePWithNoPath[60]={0};
  9824. void checkUploadLog(void)
  9825. {
  9826. FILE *fp;
  9827. /* Open the command for reading. */
  9828. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9829. if (fp == NULL) {
  9830. DEBUG_WARN("Failed to run command\n" );
  9831. exit(1);
  9832. }
  9833. int ftppathlen = 0;
  9834. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9835. int i = 0;
  9836. /* Read the output a line at a time - output it. */
  9837. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9838. if(i==0)
  9839. {
  9840. ftppathlen = strlen(fnamePlusPath);
  9841. DEBUG_INFO("%s\n", fnamePlusPath);
  9842. fnamePlusPath[ftppathlen]='\0';
  9843. break;
  9844. }
  9845. i= i+1;
  9846. }
  9847. /* close */
  9848. pclose(fp);
  9849. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9850. {
  9851. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9852. {
  9853. fnamePlusPath[k]='\0';
  9854. }
  9855. }
  9856. i=1;
  9857. //char fname[60]={0};
  9858. while(i < ftppathlen)
  9859. {
  9860. int len=ftppathlen-i;
  9861. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9862. {
  9863. DEBUG_INFO("compare '/' all right\n");
  9864. break;
  9865. }
  9866. i=i+1;
  9867. }
  9868. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9869. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9870. fnamePWithNoPath[i+1] = '\0';
  9871. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9872. {
  9873. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9874. {
  9875. fnamePWithNoPath[j]='\0';
  9876. }
  9877. }
  9878. FILE* fp1 = fopen(fnamePlusPath, "r");
  9879. if (fp1)
  9880. {
  9881. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9882. // file exists
  9883. fclose(fp1);
  9884. }
  9885. else
  9886. {
  9887. // file doesn't exist
  9888. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9889. }
  9890. }
  9891. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9892. {
  9893. mtrace();
  9894. int result = FAIL;
  9895. time_t CurrentTime;
  9896. struct tm *tm;
  9897. pthread_t th_Status;
  9898. CurrentTime = time(NULL);
  9899. tm = localtime(&CurrentTime);
  9900. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  9901. 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);
  9902. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9903. if(!interLock.isGetDiagnosticGoing)
  9904. {
  9905. interLock.isGetDiagnosticGoing = 1;
  9906. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9907. sleep(1);
  9908. }
  9909. else
  9910. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9911. return result;
  9912. }
  9913. void* GetDiagnosticsProcess(void* data)
  9914. {
  9915. pthread_detach(pthread_self());
  9916. mtrace();
  9917. int retriesInt=0, retryIntervalInt=0;
  9918. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9919. 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};
  9920. int port=0;
  9921. int isSuccess = FALSE;
  9922. char cmdBuf[2048];
  9923. struct tm *tmNow;
  9924. time_t CurrentTime;
  9925. struct tm tmStart;
  9926. struct tm tmStop;
  9927. CurrentTime = time(NULL);
  9928. tmNow=localtime(&CurrentTime);
  9929. uint16_t targetYear, targetMonth;
  9930. json_object *GetDiagnostics;
  9931. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9932. GetDiagnostics = json_tokener_parse(data);
  9933. if(!is_error(GetDiagnostics))
  9934. {
  9935. // Required data
  9936. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9937. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9938. // Optional data
  9939. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9940. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9941. else
  9942. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9943. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9944. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9945. else
  9946. retryIntervalInt = 30;
  9947. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9948. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9949. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9950. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9951. }
  9952. json_object_put(GetDiagnostics);
  9953. // Pack log to compress file
  9954. 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) &&
  9955. (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))
  9956. {
  9957. // Pack system log
  9958. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9959. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9960. targetYear = tmStart.tm_year;
  9961. targetMonth = tmStart.tm_mon;
  9962. do
  9963. {
  9964. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9965. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9966. if(targetMonth+1>=13)
  9967. {
  9968. targetYear += 1;
  9969. targetMonth = 1;
  9970. }
  9971. else
  9972. {
  9973. targetMonth += 1;
  9974. }
  9975. }while((targetYear < (tmNow->tm_year+1900)) ||
  9976. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9977. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9978. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9979. system(cmdBuf);
  9980. // Pack charging & event log
  9981. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9982. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9983. targetYear = tmStart.tm_year;
  9984. targetMonth = tmStart.tm_mon;
  9985. do
  9986. {
  9987. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9988. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9989. if(targetMonth+1>=13)
  9990. {
  9991. targetYear += 1;
  9992. targetMonth = 1;
  9993. }
  9994. else
  9995. {
  9996. targetMonth += 1;
  9997. }
  9998. }while((targetYear < (tmNow->tm_year+1900)) ||
  9999. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10000. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10001. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10002. system(cmdBuf);
  10003. // Combine log file
  10004. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10005. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10006. }
  10007. else
  10008. {
  10009. system("exec /root/logPackTools 'log' 6");
  10010. }
  10011. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10012. system(cmdBuf);
  10013. checkUploadLog();
  10014. //****************location*******************/
  10015. if(strcmp(locationstr,"")==0)
  10016. {
  10017. DEBUG_INFO("location is <Empty>!\n");
  10018. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10019. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10020. goto end;
  10021. }
  10022. memset(protocol, 0, ARRAY_SIZE(protocol));
  10023. memset(user, 0, ARRAY_SIZE(user) );
  10024. memset(password, 0, ARRAY_SIZE(password));
  10025. memset(host, 0, ARRAY_SIZE(host));
  10026. memset(path, 0, ARRAY_SIZE(path));
  10027. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10028. memset(host1, 0, ARRAY_SIZE(host1));
  10029. memset(path1, 0, ARRAY_SIZE(path1));
  10030. /*location: ftp://user:password@host:port/path*/
  10031. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10032. if((access(fnamePlusPath,F_OK))!=-1)
  10033. {
  10034. DEBUG_INFO("fnamePlusPath exist.\n");
  10035. }
  10036. else
  10037. {
  10038. DEBUG_INFO("fnamePlusPath not exist!\n");
  10039. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10040. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10041. goto end;
  10042. }
  10043. if(strchr(locationstr,'@')==NULL)
  10044. {
  10045. sscanf(locationstr,
  10046. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10047. protocol, host, &port, path);
  10048. strcpy(user,"anonymous");
  10049. strcpy(password,"");
  10050. }
  10051. else
  10052. {
  10053. //DEBUG_INFO("pch=%s\n", pch);
  10054. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10055. protocol, user, password, host, &port, path);
  10056. }
  10057. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10058. {
  10059. DEBUG_INFO("protocol is not ftp/http ! \n");
  10060. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10061. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10062. goto end;
  10063. }
  10064. if(strncmp(locationstr,"http", 4) == 0)
  10065. {
  10066. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10067. sprintf(ftppath,"/%s", path);
  10068. do
  10069. {
  10070. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10071. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10072. sleep(3);
  10073. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10074. if(!isSuccess)
  10075. {
  10076. DEBUG_INFO("Diagnostics fail.\n");
  10077. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10078. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10079. sleep(retryIntervalInt);
  10080. }
  10081. else
  10082. {
  10083. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10084. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10085. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10086. }
  10087. retriesInt--;
  10088. }while((isSuccess == 0)&&(retriesInt >= 0));
  10089. }
  10090. else
  10091. {
  10092. sscanf(host,"%[^/]%s",host1, path1);
  10093. if(strlen(path) > 0)
  10094. sprintf(ftppath,"/%s", path);
  10095. else
  10096. sprintf(ftppath,"/%s", path1);
  10097. int ftppathlen=strlen(ftppath);
  10098. int i=1;
  10099. char filenametemp[50];
  10100. while(i < ftppathlen)
  10101. {
  10102. int len=ftppathlen-i;
  10103. if(ftppath[len]== 47) // '/' ascll code: 47
  10104. {
  10105. DEBUG_INFO("find '/' all right\n");
  10106. break;
  10107. }
  10108. i=i+1;
  10109. }
  10110. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10111. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10112. filenametemp[i+1] = 0;
  10113. if(port == 0)
  10114. port = 21;
  10115. do
  10116. {
  10117. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10118. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10119. sleep(3);
  10120. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10121. if(!isSuccess)
  10122. {
  10123. DEBUG_INFO("Diagnostics fail.\n");
  10124. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10125. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10126. sleep(retryIntervalInt);
  10127. }
  10128. else
  10129. {
  10130. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10131. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10132. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10133. }
  10134. retriesInt--;
  10135. }while((!isSuccess)&&(retriesInt >= 0));
  10136. }
  10137. end:
  10138. system("rm -f /mnt/*");
  10139. sleep(5);
  10140. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10141. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10142. interLock.isGetDiagnosticGoing = 0;
  10143. pthread_exit(NULL);
  10144. }
  10145. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10146. {
  10147. mtrace();
  10148. int result = FAIL;
  10149. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10150. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10151. {
  10152. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10153. locallistVersion = -1;
  10154. }
  10155. else
  10156. {
  10157. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10158. OCPP_getListVerion();
  10159. }
  10160. //from db.OCPP_getListVerion
  10161. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10162. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  10163. sendGetLocalListVersionConfirmation(uuid,"");
  10164. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  10165. return result;
  10166. }
  10167. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10168. {
  10169. mtrace();
  10170. int result = FAIL;
  10171. int connectorIdInt=-1;
  10172. int tempIndex = 0;
  10173. int connectorIdIsNULL, chargingProfileIsNULL;
  10174. char comfirmstr[20]={0};
  10175. char cmdBuf[512];
  10176. json_object *RemoteStartTransaction;
  10177. FILE *fp;
  10178. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10179. if(server_pending == TRUE)
  10180. {
  10181. return 0;
  10182. }
  10183. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10184. RemoteStartTransaction = json_tokener_parse(payload);
  10185. if(!is_error(RemoteStartTransaction))
  10186. {
  10187. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10188. {
  10189. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10190. }
  10191. else
  10192. {
  10193. connectorIdIsNULL = TRUE;
  10194. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10195. {
  10196. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10197. {
  10198. connectorIdIsNULL = FALSE;
  10199. connectorIdInt = (gun_index+1);
  10200. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10201. break;
  10202. }
  10203. }
  10204. }
  10205. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10206. {
  10207. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10208. // Required data
  10209. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10210. // Optional data
  10211. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10212. {
  10213. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10214. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10215. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10216. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10217. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10218. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10219. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10220. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10221. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10222. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10223. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10224. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10225. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10226. {
  10227. 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")));
  10228. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10229. 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"));
  10230. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10231. 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"));
  10232. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10233. 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")));
  10234. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10235. {
  10236. 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++)
  10237. {
  10238. 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"));
  10239. 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"));
  10240. 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)
  10241. 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"));
  10242. }
  10243. }
  10244. }
  10245. }
  10246. else
  10247. {
  10248. chargingProfileIsNULL = TRUE;
  10249. }
  10250. }
  10251. }
  10252. else
  10253. {
  10254. connectorIdIsNULL = TRUE;
  10255. }
  10256. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10257. {
  10258. DEBUG_WARN("Connector id is NULL\n.");
  10259. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10260. goto end;
  10261. }
  10262. /*
  10263. enum _SYSTEM_STATUS
  10264. {
  10265. S_BOOTING = 0,
  10266. S_IDLE, = 1
  10267. S_AUTHORIZING, = 2
  10268. S_REASSIGN_CHECK, = 3
  10269. S_REASSIGN, = 4
  10270. S_PRECHARGE, = 5
  10271. S_PREPARING_FOR_EV, = 6
  10272. S_PREPARING_FOR_EVSE, = 7
  10273. S_CHARGING, = 8
  10274. S_TERMINATING, = 9
  10275. S_COMPLETE, = 10
  10276. S_ALARM, = 11
  10277. S_FAULT = 12
  10278. }
  10279. */
  10280. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10281. {
  10282. //check Transaction active
  10283. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10284. {
  10285. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10286. {
  10287. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10288. }
  10289. else
  10290. {
  10291. tempIndex = connectorIdInt -1;
  10292. }
  10293. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10294. {
  10295. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10296. {
  10297. 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))
  10298. {
  10299. //Reserved
  10300. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10301. }
  10302. 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))
  10303. {
  10304. //Reserved
  10305. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10306. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10307. goto end;
  10308. }
  10309. else
  10310. {
  10311. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10312. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10313. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10314. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10315. {
  10316. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10317. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10318. goto end;
  10319. }
  10320. }//END FOR ELSE
  10321. }
  10322. }// END FOR CHAdeMO_QUANTITY
  10323. }
  10324. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10325. {
  10326. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10327. {
  10328. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10329. }
  10330. else
  10331. {
  10332. tempIndex = connectorIdInt -1;
  10333. }
  10334. for (int index = 0; index < CCS_QUANTITY; index++)
  10335. {
  10336. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10337. {
  10338. 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))
  10339. {
  10340. //Reserved
  10341. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10342. }
  10343. 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))
  10344. {
  10345. //Reserved
  10346. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10347. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10348. goto end;
  10349. }
  10350. else
  10351. {
  10352. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10353. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10354. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10355. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10356. {
  10357. DEBUG_WARN("CCS connector not allow start\n.");
  10358. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10359. goto end;
  10360. }
  10361. }// END FOR ELSE
  10362. }
  10363. }// END FOR CCS_QUANTITY
  10364. }
  10365. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10366. {
  10367. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10368. {
  10369. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10370. }
  10371. else
  10372. {
  10373. tempIndex = connectorIdInt -1;
  10374. }
  10375. for (int index = 0; index < GB_QUANTITY; index++)
  10376. {
  10377. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10378. {
  10379. 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))
  10380. {
  10381. //Reserved
  10382. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10383. }
  10384. 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))
  10385. {
  10386. //Reserved
  10387. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10388. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10389. goto end;
  10390. }
  10391. else
  10392. {
  10393. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10394. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10395. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10396. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10397. {
  10398. DEBUG_WARN("GB connector not allow start\n.");
  10399. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10400. goto end;
  10401. }
  10402. }// END FOR ELSE
  10403. }
  10404. } // END FOR GB_QUANTITY
  10405. }
  10406. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10407. {
  10408. tempIndex = connectorIdInt -1;
  10409. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10410. {
  10411. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10412. {
  10413. 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))
  10414. {
  10415. //Reserved
  10416. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10417. }
  10418. 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))
  10419. {
  10420. //Reserved
  10421. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10422. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10423. goto end;
  10424. }
  10425. else
  10426. {
  10427. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10428. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10429. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10430. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10431. {
  10432. DEBUG_WARN("GB connector not allow start\n.");
  10433. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10434. goto end;
  10435. }
  10436. }// END FOR ELSE
  10437. }
  10438. } // END FOR GB_QUANTITY
  10439. }
  10440. else
  10441. {
  10442. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10443. {
  10444. tempIndex = 2;
  10445. }
  10446. else
  10447. {
  10448. tempIndex = connectorIdInt -1;
  10449. }
  10450. for (int index = 0; index < AC_QUANTITY; index++)
  10451. {
  10452. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10453. {
  10454. 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))
  10455. {
  10456. //Reserved
  10457. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10458. }
  10459. 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))
  10460. {
  10461. //Reserved
  10462. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10463. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10464. goto end;
  10465. }
  10466. else
  10467. {
  10468. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10469. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10470. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10471. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10472. {
  10473. DEBUG_WARN("AC connector not allow start\n.");
  10474. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10475. goto end;
  10476. }
  10477. }//END FOR ELSE
  10478. }
  10479. }// END FOR AC_QUANTITY
  10480. }
  10481. if(chargingProfileIsNULL == FALSE)
  10482. {
  10483. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10484. {
  10485. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10486. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10487. //memset idTag
  10488. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10489. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10490. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10491. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10492. // Save profile to file
  10493. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10494. system(cmdBuf);
  10495. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10496. fp = fopen(cmdBuf, "w");
  10497. 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));
  10498. fclose(fp);
  10499. }
  10500. else
  10501. {
  10502. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10503. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10504. }
  10505. }
  10506. else
  10507. {
  10508. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10509. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10510. //memset idTag
  10511. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10512. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10513. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10514. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10515. }
  10516. }
  10517. else
  10518. {
  10519. DEBUG_WARN("Connector id over\n.");
  10520. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10521. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10522. }
  10523. end:
  10524. json_object_put(RemoteStartTransaction);
  10525. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10526. {
  10527. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10528. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10529. }
  10530. //OCPP send RemoteStartConfirmation by first.
  10531. sendRemoteStartConfirmation(uuid, comfirmstr);
  10532. return result;
  10533. }
  10534. int handleRemoteStartRequest(char *uuid, char *payload)
  10535. {
  10536. mtrace();
  10537. int result = PASS;
  10538. int connectorIdInt=-1;
  10539. int tempIndex = 0;
  10540. char comfirmstr[20]={0};
  10541. char cmdBuf[512];
  10542. json_object *RemoteStartTransaction;
  10543. FILE *fp;
  10544. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10545. if(server_pending == TRUE)
  10546. {
  10547. result = FAIL;
  10548. }
  10549. RemoteStartTransaction = json_tokener_parse(payload);
  10550. if(!is_error(RemoteStartTransaction))
  10551. {
  10552. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10553. {
  10554. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10555. }
  10556. else
  10557. {
  10558. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10559. {
  10560. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10561. {
  10562. connectorIdInt = (gun_index+1);
  10563. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10564. break;
  10565. }
  10566. }
  10567. }
  10568. if(connectorIdInt == 0)
  10569. {
  10570. DEBUG_WARN("Connector id shall not equal 0.\n");
  10571. result = FAIL;
  10572. }
  10573. else if(connectorIdInt == -1)
  10574. {
  10575. DEBUG_INFO("Connector id does not specific.\n");
  10576. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10577. {
  10578. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10579. // Required data
  10580. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10581. // Optional data
  10582. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10583. {
  10584. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10585. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10586. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10587. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10588. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10589. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10590. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10591. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10592. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10593. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10594. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10595. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10596. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10597. {
  10598. 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")));
  10599. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10600. 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"));
  10601. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10602. 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"));
  10603. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10604. 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")));
  10605. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10606. {
  10607. 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++)
  10608. {
  10609. 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"));
  10610. 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"));
  10611. 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)
  10612. 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"));
  10613. }
  10614. }
  10615. }
  10616. }
  10617. else
  10618. {
  10619. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10620. }
  10621. }
  10622. }
  10623. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10624. {
  10625. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10626. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10627. // Required data
  10628. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10629. // Optional data
  10630. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10631. {
  10632. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10633. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10634. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10635. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10636. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10637. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10638. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10639. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10640. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10641. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10642. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10643. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10644. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10645. {
  10646. 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")));
  10647. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10648. 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"));
  10649. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10650. 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"));
  10651. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10652. 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")));
  10653. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10654. {
  10655. 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++)
  10656. {
  10657. 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"));
  10658. 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"));
  10659. 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)
  10660. 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"));
  10661. }
  10662. }
  10663. }
  10664. }
  10665. else
  10666. {
  10667. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10668. }
  10669. }
  10670. else
  10671. {
  10672. DEBUG_WARN("Connector id is over maximun value.\n");
  10673. result = FAIL;
  10674. }
  10675. }
  10676. if(result == PASS)
  10677. {
  10678. if(connectorIdInt > 0)
  10679. {
  10680. //check Transaction active
  10681. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10682. {
  10683. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10684. {
  10685. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10686. }
  10687. else
  10688. {
  10689. tempIndex = connectorIdInt -1;
  10690. }
  10691. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10692. {
  10693. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10694. {
  10695. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10696. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10697. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10698. {
  10699. //Reserved
  10700. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10701. }
  10702. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10703. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10704. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10705. {
  10706. //Reserved
  10707. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10708. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10709. goto end;
  10710. }
  10711. else
  10712. {
  10713. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10714. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10715. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10716. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10717. {
  10718. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10719. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10720. goto end;
  10721. }
  10722. }//END FOR ELSE
  10723. }
  10724. }// END FOR CHAdeMO_QUANTITY
  10725. }
  10726. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10727. {
  10728. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10729. {
  10730. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10731. }
  10732. else
  10733. {
  10734. tempIndex = connectorIdInt -1;
  10735. }
  10736. for (int index = 0; index < CCS_QUANTITY; index++)
  10737. {
  10738. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10739. {
  10740. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10741. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10742. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10743. {
  10744. //Reserved
  10745. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10746. }
  10747. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10748. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10749. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10750. {
  10751. //Reserved
  10752. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10753. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10754. goto end;
  10755. }
  10756. else
  10757. {
  10758. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10759. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10760. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10761. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10762. {
  10763. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10764. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10765. goto end;
  10766. }
  10767. }// END FOR ELSE
  10768. }
  10769. }// END FOR CCS_QUANTITY
  10770. }
  10771. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10772. {
  10773. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10774. {
  10775. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10776. }
  10777. else
  10778. {
  10779. tempIndex = connectorIdInt -1;
  10780. }
  10781. for (int index = 0; index < GB_QUANTITY; index++)
  10782. {
  10783. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10784. {
  10785. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10786. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10787. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10788. {
  10789. //Reserved
  10790. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10791. }
  10792. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10793. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10794. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10795. {
  10796. //Reserved
  10797. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10798. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10799. goto end;
  10800. }
  10801. else
  10802. {
  10803. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10804. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10805. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10806. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10807. {
  10808. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10809. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10810. goto end;
  10811. }
  10812. }// END FOR ELSE
  10813. }
  10814. } // END FOR GB_QUANTITY
  10815. }
  10816. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10817. {
  10818. tempIndex = connectorIdInt -1;
  10819. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10820. {
  10821. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10822. {
  10823. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10824. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10825. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10826. {
  10827. //Reserved
  10828. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10829. }
  10830. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10831. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10832. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10833. {
  10834. //Reserved
  10835. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10836. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10837. goto end;
  10838. }
  10839. else
  10840. {
  10841. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10842. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10843. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10844. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10845. {
  10846. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10847. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10848. goto end;
  10849. }
  10850. }// END FOR ELSE
  10851. }
  10852. } // END FOR GB_QUANTITY
  10853. }
  10854. else
  10855. {
  10856. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10857. {
  10858. tempIndex = 2;
  10859. }
  10860. else
  10861. {
  10862. tempIndex = connectorIdInt -1;
  10863. }
  10864. for (int index = 0; index < AC_QUANTITY; index++)
  10865. {
  10866. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10867. {
  10868. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10869. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10870. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10871. {
  10872. //Reserved
  10873. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10874. }
  10875. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10876. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10877. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10878. {
  10879. //Reserved
  10880. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10881. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10882. goto end;
  10883. }
  10884. else
  10885. {
  10886. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10887. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10888. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10889. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10890. {
  10891. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10892. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10893. goto end;
  10894. }
  10895. }//END FOR ELSE
  10896. }
  10897. }// END FOR AC_QUANTITY
  10898. }
  10899. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10900. {
  10901. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10902. {
  10903. // Save profile to file
  10904. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10905. system(cmdBuf);
  10906. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10907. fp = fopen(cmdBuf, "w");
  10908. 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));
  10909. fclose(fp);
  10910. }
  10911. else
  10912. {
  10913. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10914. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10915. goto end;
  10916. }
  10917. }
  10918. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10919. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10920. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10921. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10922. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10923. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10924. }
  10925. else
  10926. {
  10927. uint8_t isHasIdleConnector = FALSE;
  10928. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10929. {
  10930. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10931. {
  10932. isHasIdleConnector = TRUE;
  10933. break;
  10934. }
  10935. }
  10936. if(isHasIdleConnector == TRUE)
  10937. {
  10938. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10939. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10940. {
  10941. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10942. {
  10943. // Save profile to file
  10944. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  10945. system(cmdBuf);
  10946. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  10947. fp = fopen(cmdBuf, "w");
  10948. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10949. fclose(fp);
  10950. refreshStartTimer(&clientTime.RemoteStartWait);
  10951. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  10952. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10953. }
  10954. else
  10955. {
  10956. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10957. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10958. }
  10959. }
  10960. else
  10961. {
  10962. refreshStartTimer(&clientTime.RemoteStartWait);
  10963. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  10964. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10965. }
  10966. }
  10967. else
  10968. {
  10969. DEBUG_INFO("There is not any connector is idle.\n");
  10970. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10971. }
  10972. }
  10973. }
  10974. else
  10975. {
  10976. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10977. }
  10978. end:
  10979. json_object_put(RemoteStartTransaction);
  10980. sendRemoteStartConfirmation(uuid, comfirmstr);
  10981. return result;
  10982. }
  10983. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10984. {
  10985. mtrace();
  10986. int result = FAIL;
  10987. int match = FALSE;
  10988. int GunNO = 0;
  10989. int tempIndex = 0;
  10990. int transactionIdInt=0;
  10991. int transactionIdIsNULL= TRUE;
  10992. char comfirmstr[20];
  10993. json_object *RemoteStopTransaction;
  10994. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10995. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10996. if(server_pending == TRUE)
  10997. {
  10998. return 0;
  10999. }
  11000. RemoteStopTransaction = json_tokener_parse(payload);
  11001. if(!is_error(RemoteStopTransaction))
  11002. {
  11003. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11004. {
  11005. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11006. transactionIdIsNULL = FALSE;
  11007. }
  11008. }
  11009. json_object_put(RemoteStopTransaction);
  11010. if(transactionIdIsNULL == FALSE)
  11011. {
  11012. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11013. {
  11014. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11015. {
  11016. //check Transaction active
  11017. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11018. {
  11019. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11020. {
  11021. tempIndex = ((gun_index==2) ? 1: 0);
  11022. }
  11023. else
  11024. {
  11025. tempIndex = gun_index;
  11026. }
  11027. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11028. {
  11029. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11030. {
  11031. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11032. {
  11033. match = TRUE;
  11034. GunNO = gun_index;
  11035. }
  11036. }
  11037. }// END FOR CHAdeMO_QUANTITY
  11038. }
  11039. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11040. {
  11041. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11042. {
  11043. tempIndex = ((gun_index==2) ? 1: 0);
  11044. }
  11045. else
  11046. {
  11047. tempIndex = gun_index;
  11048. }
  11049. for (int index = 0; index < CCS_QUANTITY; index++)
  11050. {
  11051. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11052. {
  11053. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11054. {
  11055. match = TRUE;
  11056. GunNO = gun_index;
  11057. }
  11058. }
  11059. }// END FOR CCS_QUANTITY
  11060. }
  11061. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11062. {
  11063. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11064. {
  11065. tempIndex = ((gun_index==2) ? 1: 0);
  11066. }
  11067. else
  11068. {
  11069. tempIndex = gun_index;
  11070. }
  11071. for (int index = 0; index < GB_QUANTITY; index++)
  11072. {
  11073. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11074. {
  11075. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11076. {
  11077. match = TRUE;
  11078. GunNO = gun_index;
  11079. }
  11080. }
  11081. }// END FOR GB_QUANTITY
  11082. }
  11083. else if(gunType[gun_index] == GUN_TYPE_DO)
  11084. {
  11085. tempIndex = gun_index;
  11086. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11087. {
  11088. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11089. {
  11090. 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
  11091. {
  11092. match = TRUE;
  11093. GunNO = gun_index;
  11094. }
  11095. }
  11096. }// END FOR GB_QUANTITY
  11097. }
  11098. else
  11099. {
  11100. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11101. {
  11102. tempIndex = 2;
  11103. }
  11104. else
  11105. {
  11106. tempIndex = gun_index;
  11107. }
  11108. for (int index = 0; index < AC_QUANTITY; index++)
  11109. {
  11110. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11111. {
  11112. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11113. {
  11114. match = TRUE;
  11115. GunNO = gun_index;
  11116. }
  11117. }
  11118. }// END FOR CHAdeMO_QUANTITY
  11119. } // END FOR AC ELSE
  11120. }// CHECK IF ResponseTransactionId == transactionIdInt
  11121. }//END FOR
  11122. if( match == TRUE)
  11123. {
  11124. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11125. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11126. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11127. }
  11128. else
  11129. {
  11130. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11131. }
  11132. }
  11133. else
  11134. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11135. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11136. return result;
  11137. }
  11138. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11139. {
  11140. mtrace();
  11141. int result = FAIL;
  11142. int connectorIdInt=0, reservationIdInt=0;
  11143. int tempIndex = 0;
  11144. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  11145. char comfirmstr[20]={0};
  11146. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11147. int c = 0;
  11148. char *loc;
  11149. //char *ptr;
  11150. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11151. strcpy(sstrtemp, stringtrimspace(payload));
  11152. //***(1)connectorId ****/
  11153. c=0;
  11154. loc = strstr(sstrtemp, "connectorId");
  11155. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11156. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11157. {
  11158. sstr[c] = loc[strlen("connectorId")+2+c];
  11159. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11160. c++;
  11161. }
  11162. sstr[c] = '\0';
  11163. connectorIdInt = atoi(sstr);
  11164. //***(2)expiryDate ****/
  11165. loc = strstr(sstrtemp, "expiryDate");
  11166. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11167. c = 0;
  11168. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11169. {
  11170. sstr[c] = loc[3+strlen("expiryDate")+c];
  11171. c++;
  11172. }
  11173. sstr[c] = '\0';
  11174. strcpy(expiryDatestr, sstr);
  11175. //***(3)idTag ****/
  11176. loc = strstr(sstrtemp, "idTag");
  11177. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11178. c = 0;
  11179. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11180. {
  11181. sstr[c] = loc[3+strlen("idTag")+c];
  11182. c++;
  11183. }
  11184. sstr[c] = '\0';
  11185. strcpy(idTagstr, sstr);
  11186. //***(4)parentIdTag ****/
  11187. loc = strstr(sstrtemp, "parentIdTag");
  11188. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11189. c = 0;
  11190. if(loc == NULL)
  11191. {
  11192. strcpy(parentIdTagstr, "");
  11193. }
  11194. else
  11195. {
  11196. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11197. {
  11198. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11199. c++;
  11200. }
  11201. sstr[c] = '\0';
  11202. strcpy(parentIdTagstr, sstr);
  11203. }
  11204. //***(5)reservationId ****/
  11205. c=0;
  11206. loc = strstr(sstrtemp, "reservationId");
  11207. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11208. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11209. {
  11210. sstr[c] = loc[strlen("reservationId")+2+c];
  11211. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11212. c++;
  11213. }
  11214. sstr[c] = '\0';
  11215. reservationIdInt = atoi(sstr);
  11216. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11217. /*
  11218. enum SYSTEM_STATUS
  11219. {
  11220. SYS_MODE_BOOTING = 0,
  11221. SYS_MODE_IDLE = 1,
  11222. SYS_MODE_AUTHORIZING = 2,
  11223. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11224. SYS_MODE_REASSIGN = 4,
  11225. SYS_MODE_PREPARING = 5,
  11226. SYS_MODE_PREPARE_FOR_EV = 6,
  11227. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11228. SYS_MODE_CHARGING = 8,
  11229. SYS_MODE_TERMINATING = 9,
  11230. SYS_MODE_COMPLETE = 10,
  11231. SYS_MODE_ALARM = 11,
  11232. SYS_MODE_FAULT = 12,
  11233. SYS_MODE_RESERVATION = 13,
  11234. SYS_MODE_BOOKING = 14,
  11235. SYS_MODE_MAINTAIN = 15,
  11236. SYS_MODE_DEBUG = 16,
  11237. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11238. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11239. SYS_MODE_UPDATE = 19
  11240. };
  11241. */
  11242. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11243. {
  11244. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11245. goto end;
  11246. }
  11247. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11248. {
  11249. //check Transaction active
  11250. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11251. {
  11252. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11253. {
  11254. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11255. }
  11256. else
  11257. {
  11258. tempIndex = connectorIdInt -1;
  11259. }
  11260. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11261. {
  11262. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11263. {
  11264. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11265. {
  11266. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11267. {
  11268. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11269. {
  11270. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11271. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11272. }
  11273. 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'))
  11274. {
  11275. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11276. }
  11277. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11278. {
  11279. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11280. }
  11281. else
  11282. {
  11283. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11284. }
  11285. }
  11286. 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
  11287. {
  11288. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11289. }
  11290. }
  11291. else
  11292. {
  11293. //replace reservation
  11294. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11295. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11296. }
  11297. }
  11298. } // END FOR CHAdeMO_QUANTITY
  11299. }
  11300. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11301. {
  11302. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11303. {
  11304. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11305. }
  11306. else
  11307. {
  11308. tempIndex = connectorIdInt -1;
  11309. }
  11310. for (int index = 0; index < CCS_QUANTITY; index++)
  11311. {
  11312. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11313. {
  11314. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11315. {
  11316. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11317. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11318. {
  11319. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11320. {
  11321. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11322. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11323. }
  11324. 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'))
  11325. {
  11326. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11327. }
  11328. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11329. {
  11330. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11331. }
  11332. else
  11333. {
  11334. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11335. }
  11336. }
  11337. 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
  11338. {
  11339. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11340. }
  11341. }
  11342. else
  11343. {
  11344. //replace reservation
  11345. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11346. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11347. }
  11348. }
  11349. } // END FOR CCS_QUANTITY
  11350. }
  11351. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11352. {
  11353. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11354. {
  11355. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11356. }
  11357. else
  11358. {
  11359. tempIndex = connectorIdInt -1;
  11360. }
  11361. for (int index = 0; index < GB_QUANTITY; index++)
  11362. {
  11363. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11364. {
  11365. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11366. {
  11367. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11368. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11369. {
  11370. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11371. {
  11372. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11373. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11374. }
  11375. 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'))
  11376. {
  11377. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11378. }
  11379. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11380. {
  11381. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11382. }
  11383. else
  11384. {
  11385. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11386. }
  11387. }
  11388. 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
  11389. {
  11390. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11391. }
  11392. }
  11393. else
  11394. {
  11395. //replace reservation
  11396. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11397. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11398. }
  11399. }
  11400. }// END FOR GB_QUANTITY
  11401. }
  11402. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11403. {
  11404. tempIndex = connectorIdInt -1;
  11405. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11406. {
  11407. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11408. {
  11409. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11410. {
  11411. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11412. 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
  11413. {
  11414. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11415. {
  11416. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11417. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11418. }
  11419. 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'))
  11420. {
  11421. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11422. }
  11423. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11424. {
  11425. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11426. }
  11427. else
  11428. {
  11429. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11430. }
  11431. }
  11432. 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
  11433. {
  11434. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11435. }
  11436. }
  11437. else
  11438. {
  11439. //replace reservation
  11440. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11441. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11442. }
  11443. }
  11444. }// END FOR GB_QUANTITY
  11445. }
  11446. else
  11447. {
  11448. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11449. {
  11450. tempIndex = 2;
  11451. }
  11452. else
  11453. {
  11454. tempIndex = (connectorIdInt -1);
  11455. }
  11456. for (int index = 0; index < AC_QUANTITY; index++)
  11457. {
  11458. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11459. {
  11460. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11461. {
  11462. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11463. {
  11464. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11465. {
  11466. 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))
  11467. {
  11468. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11469. }
  11470. else
  11471. {
  11472. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11473. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11474. }
  11475. }
  11476. 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'))
  11477. {
  11478. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11479. }
  11480. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11481. {
  11482. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11483. }
  11484. else
  11485. {
  11486. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11487. }
  11488. }
  11489. 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
  11490. {
  11491. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11492. }
  11493. }
  11494. else
  11495. {
  11496. //replace reservation
  11497. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11498. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11499. }
  11500. }
  11501. } // END FOR AC_QUANTITY
  11502. }
  11503. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11504. }
  11505. else if(connectorIdInt == 0)
  11506. {
  11507. //check Transaction active
  11508. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11509. {
  11510. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11511. {
  11512. 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'))
  11513. {
  11514. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11515. goto end;
  11516. }
  11517. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11518. {
  11519. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11520. goto end;
  11521. }
  11522. 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
  11523. {
  11524. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11525. goto end;
  11526. }
  11527. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11528. {
  11529. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11530. goto end;
  11531. }
  11532. }
  11533. }// END FOR CHAdeMO_QUANTITY
  11534. for (int index = 0; index < CCS_QUANTITY; index++)
  11535. {
  11536. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11537. {
  11538. 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'))
  11539. {
  11540. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11541. goto end;
  11542. }
  11543. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11544. {
  11545. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11546. goto end;
  11547. }
  11548. 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
  11549. {
  11550. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11551. goto end;
  11552. }
  11553. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11554. {
  11555. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11556. goto end;
  11557. }
  11558. }
  11559. } // END FOR CCS_QUANTITY
  11560. for (int index = 0; index < GB_QUANTITY; index++)
  11561. {
  11562. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11563. {
  11564. 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'))
  11565. {
  11566. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11567. goto end;
  11568. }
  11569. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11570. {
  11571. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11572. goto end;
  11573. }
  11574. 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
  11575. {
  11576. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11577. goto end;
  11578. }
  11579. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11580. {
  11581. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11582. goto end;
  11583. }
  11584. }
  11585. } // END FOR GB_QUANTITY
  11586. for (int index = 0; index < AC_QUANTITY; index++)
  11587. {
  11588. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11589. {
  11590. 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'))
  11591. {
  11592. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11593. goto end;
  11594. }
  11595. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11596. {
  11597. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11598. goto end;
  11599. }
  11600. 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
  11601. {
  11602. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11603. goto end;
  11604. }
  11605. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11606. {
  11607. 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))
  11608. {
  11609. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11610. goto end;
  11611. }
  11612. }
  11613. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11614. {
  11615. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11616. goto end;
  11617. }
  11618. }
  11619. }// END FOR AC_QUANTITY
  11620. //The connectorId is 0
  11621. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  11622. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11623. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11624. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  11625. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11626. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  11627. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11628. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  11629. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  11630. result = TRUE;
  11631. return result;
  11632. }
  11633. else
  11634. {
  11635. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11636. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11637. }
  11638. if(strcmp(comfirmstr,"Accepted") == 0)
  11639. {
  11640. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11641. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11642. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11643. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11644. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11645. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  11646. result = TRUE;
  11647. return result;
  11648. }
  11649. end:
  11650. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11651. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11652. return result;
  11653. }
  11654. int handleResetRequest(char *uuid, char *payload)
  11655. {
  11656. mtrace();
  11657. int result = FAIL;
  11658. char sstr[10]={0},sstrtemp[30]={ 0 };
  11659. char typestr[10]={0};
  11660. char comfirmstr[20]={0};
  11661. int c = 0;
  11662. char *loc;
  11663. DEBUG_INFO("handleResetRequest...\n");
  11664. strcpy(sstrtemp, stringtrimspace(payload));
  11665. loc = strstr(sstrtemp, "type");
  11666. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11667. c = 0;
  11668. while (loc[3+strlen("type")+c] != '\"')
  11669. {
  11670. sstr[c] = loc[3+strlen("type")+c];
  11671. c++;
  11672. }
  11673. sstr[c] = '\0';
  11674. strcpy(typestr,sstr);
  11675. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11676. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11677. {
  11678. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11679. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  11680. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11681. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11682. }
  11683. else
  11684. {
  11685. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11686. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11687. result = PASS;
  11688. }
  11689. sendResetConfirmation(uuid, comfirmstr);
  11690. return result;
  11691. }
  11692. int handleSendLocalListRequest(char *uuid, char *payload)
  11693. {
  11694. mtrace();
  11695. int result = FAIL;
  11696. char comfirmstr[20];
  11697. int checkState_Faulted = FALSE;
  11698. json_object *SendLocalList;
  11699. DEBUG_INFO("handleSendLocalListRequest...\n");
  11700. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11701. {
  11702. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11703. goto end;
  11704. }
  11705. //check Charge Point state
  11706. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11707. {
  11708. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11709. {
  11710. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11711. }
  11712. }
  11713. for (int index = 0; index < CCS_QUANTITY; index++)
  11714. {
  11715. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11716. {
  11717. checkState_Faulted = TRUE; //OCPP Status
  11718. }
  11719. }
  11720. for (int index = 0; index < GB_QUANTITY; index++)
  11721. {
  11722. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11723. {
  11724. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11725. }
  11726. }
  11727. //check Charge Point state
  11728. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11729. {
  11730. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11731. {
  11732. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11733. }
  11734. }
  11735. //check Charge Point state
  11736. for (int index = 0; index < AC_QUANTITY; index++)
  11737. {
  11738. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11739. {
  11740. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11741. }
  11742. }
  11743. if(checkState_Faulted == TRUE)
  11744. {
  11745. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11746. goto end;
  11747. }
  11748. // Parsing payload
  11749. SendLocalList = json_tokener_parse(payload);
  11750. if(!is_error(SendLocalList))
  11751. {
  11752. // Required data
  11753. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11754. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11755. // Optional data
  11756. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11757. {
  11758. //Check UpdateType
  11759. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11760. {
  11761. //Local list full update
  11762. DEBUG_INFO("Local list full update.\n");
  11763. OCPP_getListVerion();
  11764. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11765. {
  11766. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11767. goto end;
  11768. }
  11769. OCPP_cleanLocalList();
  11770. }
  11771. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11772. {
  11773. //Local list different update
  11774. DEBUG_INFO("Local list different update.\n");
  11775. OCPP_getListVerion();
  11776. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11777. {
  11778. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11779. goto end;
  11780. }
  11781. }
  11782. else
  11783. {
  11784. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11785. goto end;
  11786. }
  11787. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11788. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11789. {
  11790. 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")));
  11791. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11792. {
  11793. 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")));
  11794. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11795. 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")));
  11796. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11797. 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")));
  11798. }
  11799. // Add to db
  11800. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11801. {
  11802. //Local list full update
  11803. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11804. idx,
  11805. ShmOCPP16Data->SendLocalList.ListVersion,
  11806. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11807. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11808. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11809. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11810. // update list
  11811. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11812. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11813. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11814. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11815. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11816. }
  11817. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11818. {
  11819. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11820. idx,
  11821. ShmOCPP16Data->SendLocalList.ListVersion,
  11822. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11823. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11824. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11825. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11826. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11827. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11828. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11829. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11830. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11831. }
  11832. }
  11833. }
  11834. else
  11835. {
  11836. //Check UpdateType
  11837. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11838. {
  11839. //Local list full update
  11840. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11841. OCPP_cleanLocalList();
  11842. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11843. goto end;
  11844. }
  11845. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11846. {
  11847. //Local list different update
  11848. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11849. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11850. goto end;
  11851. }
  11852. }
  11853. result = PASS;
  11854. }
  11855. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11856. end:
  11857. json_object_put(SendLocalList);
  11858. sendSendLocalListConfirmation(uuid, comfirmstr);
  11859. return result;
  11860. }
  11861. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11862. {
  11863. mtrace();
  11864. int result = FAIL;
  11865. struct StructSetChargingProfile SetProfileReq = {0};
  11866. int tempchargingProfileIdInt;
  11867. int chargingSchedulePeriodCount = 0;
  11868. char comfirmstr[20]={0};
  11869. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  11870. char rmFileCmd[128]={0};
  11871. int profileQuantity = 0;
  11872. json_object *SetChargingProfile;
  11873. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11874. SetChargingProfile = json_tokener_parse(payload);
  11875. if(!is_error(SetChargingProfile))
  11876. {
  11877. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11878. {
  11879. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11880. }
  11881. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11882. {
  11883. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11884. {
  11885. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11886. }
  11887. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11888. {
  11889. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11890. }
  11891. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11892. {
  11893. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11894. }
  11895. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11896. {
  11897. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11898. }
  11899. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11900. {
  11901. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11902. }
  11903. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11904. {
  11905. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11906. }
  11907. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11908. {
  11909. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11910. }
  11911. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11912. {
  11913. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11914. }
  11915. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11916. {
  11917. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11918. {
  11919. 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")));
  11920. }
  11921. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11922. {
  11923. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11924. }
  11925. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11926. {
  11927. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11928. }
  11929. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11930. {
  11931. 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")));
  11932. }
  11933. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11934. {
  11935. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11936. if(chargingSchedulePeriodCount <= 10)
  11937. {
  11938. 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++)
  11939. {
  11940. 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)
  11941. {
  11942. 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"));
  11943. }
  11944. 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)
  11945. {
  11946. 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"));
  11947. }
  11948. 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)
  11949. {
  11950. 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"));
  11951. }
  11952. }
  11953. }
  11954. }
  11955. }
  11956. }
  11957. }
  11958. // Profile periods quantity check
  11959. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11960. {
  11961. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11962. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11963. goto end;
  11964. }
  11965. // Check invalid limit
  11966. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11967. {
  11968. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11969. {
  11970. 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)))) ||
  11971. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11972. {
  11973. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11974. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11975. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11976. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11977. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11978. goto end;
  11979. }
  11980. }
  11981. }
  11982. else
  11983. {
  11984. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11985. {
  11986. 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))
  11987. {
  11988. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11989. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11990. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11991. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11992. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11993. goto end;
  11994. }
  11995. }
  11996. }
  11997. // Profile purpose info check
  11998. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11999. {
  12000. FILE *fp;
  12001. char dataLine[4096]={0};
  12002. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12003. if(SetProfileReq.ConnectorId != 0)
  12004. {
  12005. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12006. DEBUG_WARN("Profile connector id is not 0.\n");
  12007. goto end;
  12008. }
  12009. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12010. if (!fp)
  12011. {
  12012. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12013. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12014. }
  12015. else
  12016. {
  12017. while(fscanf(fp, "%s", dataLine) != EOF)
  12018. {
  12019. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12020. {
  12021. profileQuantity += 1;
  12022. }
  12023. }
  12024. }
  12025. fclose(fp);
  12026. }
  12027. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12028. {
  12029. FILE *fp;
  12030. char dataLine[4096]={0};
  12031. char filename[128]={0};
  12032. int tmpProfileQuantity;
  12033. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12034. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12035. {
  12036. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12037. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12038. goto end;
  12039. }
  12040. if(SetProfileReq.ConnectorId == 0)
  12041. {
  12042. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12043. {
  12044. tmpProfileQuantity = 0;
  12045. memset(filename, 0, ARRAY_SIZE(filename));
  12046. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12047. fp = fopen(filename, "r");
  12048. if (!fp)
  12049. {
  12050. DEBUG_INFO("%s does not create.\n", filename);
  12051. fp = fopen(filename, "w+");
  12052. }
  12053. else
  12054. {
  12055. while(fscanf(fp, "%s", dataLine) != EOF)
  12056. {
  12057. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12058. {
  12059. tmpProfileQuantity += 1;
  12060. }
  12061. }
  12062. }
  12063. fclose(fp);
  12064. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12065. }
  12066. }
  12067. else
  12068. {
  12069. memset(filename, 0, ARRAY_SIZE(filename));
  12070. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12071. fp = fopen(filename, "r");
  12072. if (!fp)
  12073. {
  12074. DEBUG_INFO("%s does not create.\n", filename);
  12075. fp = fopen(filename, "w+");
  12076. }
  12077. else
  12078. {
  12079. while(fscanf(fp, "%s", dataLine) != EOF)
  12080. {
  12081. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12082. {
  12083. profileQuantity += 1;
  12084. }
  12085. }
  12086. }
  12087. fclose(fp);
  12088. }
  12089. }
  12090. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12091. {
  12092. int isMatchTransactiodId= FALSE;
  12093. FILE *fp;
  12094. char dataLine[4096]={0};
  12095. char filename[128]={0};
  12096. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12097. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12098. if(SetProfileReq.ConnectorId == 0)
  12099. {
  12100. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12101. DEBUG_WARN("Profile connector id is 0.\n");
  12102. goto end;
  12103. }
  12104. int tempIndex = 0;
  12105. //check Transaction active
  12106. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12107. {
  12108. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12109. {
  12110. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12111. }
  12112. else
  12113. {
  12114. tempIndex = SetProfileReq.ConnectorId -1;
  12115. }
  12116. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12117. {
  12118. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12119. {
  12120. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12121. {
  12122. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12123. {
  12124. isMatchTransactiodId = TRUE;
  12125. break;
  12126. }
  12127. }
  12128. }
  12129. }
  12130. }
  12131. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12132. {
  12133. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12134. {
  12135. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12136. }
  12137. else
  12138. {
  12139. tempIndex = SetProfileReq.ConnectorId -1;
  12140. }
  12141. for (int index = 0; index < CCS_QUANTITY; index++)
  12142. {
  12143. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12144. {
  12145. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12146. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12147. {
  12148. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12149. {
  12150. isMatchTransactiodId = TRUE;
  12151. break;
  12152. }
  12153. }
  12154. }
  12155. }
  12156. }
  12157. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12158. {
  12159. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12160. {
  12161. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12162. }
  12163. else
  12164. {
  12165. tempIndex = SetProfileReq.ConnectorId -1;
  12166. }
  12167. for (int index = 0; index < GB_QUANTITY; index++)
  12168. {
  12169. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12170. {
  12171. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12172. {
  12173. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12174. {
  12175. isMatchTransactiodId = TRUE;
  12176. break;
  12177. }
  12178. }
  12179. }
  12180. }
  12181. }
  12182. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12183. {
  12184. tempIndex = SetProfileReq.ConnectorId -1;
  12185. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12186. {
  12187. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12188. {
  12189. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12190. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12191. {
  12192. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12193. {
  12194. isMatchTransactiodId = TRUE;
  12195. break;
  12196. }
  12197. }
  12198. }
  12199. }
  12200. }
  12201. else
  12202. {
  12203. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12204. {
  12205. tempIndex = 2;
  12206. }
  12207. else
  12208. {
  12209. tempIndex = (SetProfileReq.ConnectorId -1);
  12210. }
  12211. for (int index = 0; index < AC_QUANTITY; index++)
  12212. {
  12213. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12214. {
  12215. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12216. {
  12217. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12218. {
  12219. isMatchTransactiodId = TRUE;
  12220. break;
  12221. }
  12222. }
  12223. }
  12224. }
  12225. }
  12226. //check Transaction active
  12227. if(isMatchTransactiodId == FALSE)
  12228. {
  12229. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12230. DEBUG_WARN("Tx profile transaction id is not match.\n");
  12231. goto end;
  12232. }
  12233. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12234. {
  12235. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12236. DEBUG_WARN("Connector id is over max gun number.\n");
  12237. goto end;
  12238. }
  12239. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12240. fp = fopen(filename, "r");
  12241. if (!fp)
  12242. {
  12243. DEBUG_INFO("%s does not create.\n", filename);
  12244. fp = fopen(filename, "w+");
  12245. }
  12246. else
  12247. {
  12248. //Check Charging Profile Count
  12249. while(fscanf(fp, "%s", dataLine) != EOF)
  12250. {
  12251. //DEBUG_INFO("word=%s\n",word);
  12252. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12253. {
  12254. profileQuantity += 1;
  12255. }
  12256. }
  12257. }
  12258. fclose(fp);
  12259. }
  12260. // Check ChargeProfileMaxStackLevel
  12261. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12262. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12263. {
  12264. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12265. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12266. goto end;
  12267. }
  12268. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12269. {
  12270. FILE *fp;
  12271. char dataLine[4096]={0};
  12272. char fnametemp[128]={0};
  12273. int tmpProfileQuantity;
  12274. //Check ChargePointMaxProfile.json exit
  12275. profileQuantity = 0;
  12276. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12277. {
  12278. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  12279. //Check Charging Profile Count
  12280. tmpProfileQuantity = 0;
  12281. while(fscanf(fp, "%s", dataLine) != EOF)
  12282. {
  12283. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12284. {
  12285. profileQuantity += 1;
  12286. tmpProfileQuantity += 1;
  12287. }
  12288. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12289. }
  12290. fclose(fp);
  12291. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12292. }
  12293. //Check TxDefaultProfile_%d.json
  12294. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12295. {
  12296. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12297. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12298. if((access(fnametemp,F_OK))!=-1)
  12299. {
  12300. fp = fopen(fnametemp, "r");
  12301. //Check Charging Profile Count
  12302. tmpProfileQuantity = 0;
  12303. while(fscanf(fp, "%s", dataLine) != EOF)
  12304. {
  12305. //DEBUG_INFO("word=%s\n",word);
  12306. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12307. {
  12308. profileQuantity += 1;
  12309. tmpProfileQuantity += 1;
  12310. }
  12311. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12312. }
  12313. fclose(fp);
  12314. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12315. }
  12316. }
  12317. //Check TxProfile_%d.json
  12318. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12319. {
  12320. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12321. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  12322. if((access(fnametemp,F_OK))!=-1)
  12323. {
  12324. fp = fopen(fnametemp, "r");
  12325. //Check Charging Profile Count
  12326. tmpProfileQuantity = 0;
  12327. while(fscanf(fp, "%s", dataLine) != EOF)
  12328. {
  12329. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12330. {
  12331. profileQuantity += 1;
  12332. tmpProfileQuantity += 1;
  12333. }
  12334. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12335. }
  12336. fclose(fp);
  12337. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12338. }
  12339. }
  12340. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12341. if(profileQuantity > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12342. {
  12343. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12344. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12345. goto end;
  12346. }
  12347. }
  12348. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12349. //**********************************Write to File********************************************************/
  12350. {
  12351. FILE *infile;
  12352. FILE *outfile;
  12353. char dataLine[4096]={0};
  12354. char filename[128]={0};
  12355. int chkChar=0;
  12356. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12357. {
  12358. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12359. {
  12360. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12361. }
  12362. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12363. {
  12364. if(SetProfileReq.ConnectorId==0)
  12365. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12366. else
  12367. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12368. }
  12369. else
  12370. {
  12371. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12372. }
  12373. infile = fopen (filename, "r");
  12374. outfile = fopen (tempfile, "w");
  12375. chkChar = fgetc(infile);
  12376. rewind(infile);
  12377. if(chkChar == EOF)
  12378. {
  12379. // Profile is empty
  12380. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12381. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12382. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12383. fclose(infile);
  12384. fclose(outfile);
  12385. sprintf(rmFileCmd,"rm -f %s",filename);
  12386. system(rmFileCmd);
  12387. rename(tempfile, filename);
  12388. }
  12389. else
  12390. {
  12391. // Profile is not empty
  12392. int ChargingProfileAdded = FALSE;
  12393. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12394. {
  12395. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12396. json_object *tmpChargingProfile;
  12397. tmpChargingProfile = json_tokener_parse(dataLine);
  12398. if(!is_error(SetChargingProfile))
  12399. {
  12400. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12401. {
  12402. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12403. {
  12404. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12405. }
  12406. }
  12407. }
  12408. json_object_put(tmpChargingProfile);
  12409. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12410. {
  12411. if(ChargingProfileAdded == FALSE)
  12412. {
  12413. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12414. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12415. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12416. ChargingProfileAdded = TRUE;
  12417. }
  12418. }
  12419. else
  12420. {
  12421. fprintf(outfile,"%s\n",dataLine);
  12422. if(ChargingProfileAdded == FALSE)
  12423. {
  12424. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12425. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12426. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12427. ChargingProfileAdded = TRUE;
  12428. }
  12429. }
  12430. } // end of while loop
  12431. fclose(infile);
  12432. fclose(outfile);
  12433. sprintf(rmFileCmd,"rm -f %s",filename);
  12434. system(rmFileCmd);
  12435. rename(tempfile, filename);
  12436. }
  12437. }
  12438. sleep(1);
  12439. result = TRUE;
  12440. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12441. }
  12442. end:
  12443. json_object_put(SetChargingProfile);
  12444. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12445. {
  12446. if(SetProfileReq.ConnectorId == 0)
  12447. {
  12448. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12449. {
  12450. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  12451. }
  12452. }
  12453. else
  12454. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12455. }
  12456. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12457. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12458. return result;
  12459. }
  12460. int handleTriggerMessageRequest(char *uuid, char *payload)
  12461. {
  12462. mtrace();
  12463. int result = FAIL;
  12464. int connectorIdIsNULL = FALSE;
  12465. int connectorIdInt =0;
  12466. char sstr[40]={0},sstrtemp[100]={ 0 };
  12467. char requestedMessagestr[40]={0};
  12468. char comfirmstr[20]={0};
  12469. int c = 0;
  12470. char *loc;
  12471. DEBUG_INFO("handleTriggerMessageRequest\n");
  12472. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12473. strcpy(sstrtemp, stringtrimspace(payload));
  12474. c = 0;
  12475. loc = strstr(sstrtemp, "requestedMessage");
  12476. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12477. {
  12478. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12479. c++;
  12480. }
  12481. sstr[c] = '\0';
  12482. strcpy(requestedMessagestr, sstr);
  12483. c = 0;
  12484. loc = strstr(sstrtemp, "connectorId");
  12485. if(loc == NULL)
  12486. {
  12487. connectorIdIsNULL = TRUE;
  12488. }
  12489. else
  12490. {
  12491. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12492. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12493. {
  12494. sstr[c] = loc[strlen("connectorId")+2+c];
  12495. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12496. c++;
  12497. }
  12498. sstr[c] = '\0';
  12499. connectorIdInt = atoi(sstr);
  12500. }
  12501. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12502. {
  12503. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12504. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12505. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12506. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12507. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12508. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12509. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12510. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12511. {
  12512. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12513. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12514. return TRUE;
  12515. }
  12516. else
  12517. {
  12518. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12519. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12520. }
  12521. }
  12522. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12523. {
  12524. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12525. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12526. return TRUE;
  12527. }
  12528. //==========================
  12529. // Trigger message
  12530. //==========================
  12531. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12532. {
  12533. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12534. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12535. {
  12536. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12537. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12538. }
  12539. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12540. }
  12541. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12542. {
  12543. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  12544. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12545. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12546. }
  12547. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12548. {
  12549. //sendBootNotificationRequest();
  12550. server_sign = FALSE;
  12551. }
  12552. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12553. {
  12554. refreshStartTimer(&clientTime.Heartbeat);
  12555. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  12556. }
  12557. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12558. {
  12559. if(connectorIdIsNULL == FALSE)
  12560. {
  12561. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12562. {
  12563. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12564. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12565. }
  12566. }
  12567. else
  12568. {
  12569. for(int idx=0;idx< gunTotalNumber;idx++)
  12570. {
  12571. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12572. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12573. }
  12574. }
  12575. }
  12576. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12577. {
  12578. if(connectorIdIsNULL == FALSE)
  12579. {
  12580. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  12581. {
  12582. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12583. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  12584. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12585. }
  12586. }
  12587. else
  12588. {
  12589. for(int idx=0;idx< gunTotalNumber;idx++)
  12590. {
  12591. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  12592. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12593. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12594. }
  12595. }
  12596. }
  12597. return result;
  12598. }
  12599. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12600. {
  12601. mtrace();
  12602. int result = FAIL;
  12603. int connectorIdInt =0;
  12604. char comfirmstr[20]={0};
  12605. int tempIndex = 0;
  12606. json_object *UnlockConnector;
  12607. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12608. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12609. UnlockConnector = json_tokener_parse(payload);
  12610. if(!is_error(UnlockConnector))
  12611. {
  12612. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12613. {
  12614. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12615. }
  12616. }
  12617. json_object_put(UnlockConnector);
  12618. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12619. if(gunTotalNumber == 0)
  12620. {
  12621. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12622. goto end;
  12623. }
  12624. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12625. {
  12626. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12627. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12628. goto end;
  12629. }
  12630. else
  12631. {
  12632. //check Transaction active
  12633. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12634. {
  12635. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12636. {
  12637. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12638. }
  12639. else
  12640. {
  12641. tempIndex = connectorIdInt -1;
  12642. }
  12643. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12644. {
  12645. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12646. {
  12647. //stop Transaction
  12648. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12649. }
  12650. }
  12651. }
  12652. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12653. {
  12654. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12655. {
  12656. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12657. }
  12658. else
  12659. {
  12660. tempIndex = connectorIdInt -1;
  12661. }
  12662. for (int index = 0; index < CCS_QUANTITY; index++)
  12663. {
  12664. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12665. {
  12666. //stop Transaction
  12667. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12668. }
  12669. }
  12670. }
  12671. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12672. {
  12673. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12674. {
  12675. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12676. }
  12677. else
  12678. {
  12679. tempIndex = connectorIdInt -1;
  12680. }
  12681. for (int index = 0; index < GB_QUANTITY; index++)
  12682. {
  12683. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12684. {
  12685. //stop Transaction
  12686. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12687. }
  12688. }
  12689. }
  12690. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12691. {
  12692. tempIndex = connectorIdInt -1;
  12693. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12694. {
  12695. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12696. {
  12697. //stop Transaction
  12698. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12699. }
  12700. }
  12701. }
  12702. else
  12703. {
  12704. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12705. {
  12706. tempIndex = 2;
  12707. }
  12708. else
  12709. {
  12710. tempIndex = connectorIdInt-1;
  12711. }
  12712. for (int index = 0; index < AC_QUANTITY; index++)
  12713. {
  12714. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12715. {
  12716. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12717. }
  12718. }
  12719. }
  12720. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12721. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  12722. result = TRUE;
  12723. return result;
  12724. }
  12725. end:
  12726. //json_object_put(obj); --- remove temporally
  12727. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12728. return result;
  12729. }
  12730. static char UpdateFirmwarepayloadData[300]={0};
  12731. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12732. {
  12733. mtrace();
  12734. int result = FAIL;
  12735. pthread_t t;
  12736. sendUpdateFirmwareConfirmation(uuid);
  12737. memset(UpdateFirmwarepayloadData, 0, 300);
  12738. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12739. if(!interLock.isUpdateFirmwareGoing)
  12740. {
  12741. interLock.isUpdateFirmwareGoing = 1;
  12742. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12743. sleep(1);
  12744. }
  12745. else
  12746. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12747. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  12748. return result;
  12749. }
  12750. void *UpdateFirmwareProcess(void *data)
  12751. {
  12752. pthread_detach(pthread_self());
  12753. mtrace();
  12754. int retriesInt =0, retryIntervalInt=0;
  12755. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  12756. int port=0;
  12757. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  12758. int isSuccess = 0;
  12759. char ftpbuf[1024];
  12760. char temp[1024];
  12761. char * pch;
  12762. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12763. json_object *UpdateFirmware;
  12764. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12765. if(!is_error(UpdateFirmware))
  12766. {
  12767. // Required data
  12768. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12769. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12770. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12771. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12772. // Optional data
  12773. if(json_object_object_get(UpdateFirmware, "retries"))
  12774. {
  12775. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12776. }
  12777. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12778. {
  12779. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12780. }
  12781. }
  12782. json_object_put(UpdateFirmware);
  12783. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12784. memset(path, 0, ARRAY_SIZE(path));
  12785. // Wait retrieveData
  12786. if(strlen(retrieveDatestr) > 10)
  12787. {
  12788. do
  12789. {
  12790. sleep(1);
  12791. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12792. }
  12793. // Ready to download
  12794. system("rm -f /mnt/*");
  12795. if(strncmp(locationstr,"http", 4) == 0)
  12796. {
  12797. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12798. sprintf(ftppath,"/%s", path);
  12799. DEBUG_INFO("locationstr: %s\n", locationstr);
  12800. DEBUG_INFO("protocol: %s\n",protocol);
  12801. DEBUG_INFO("host: %s\n",host);
  12802. DEBUG_INFO("path: %s\n",path);
  12803. DEBUG_INFO("ftppath: %s\n",ftppath);
  12804. int ftppathlen=strlen(ftppath);
  12805. int i=1;
  12806. char filenametemp[50];
  12807. while(i < ftppathlen)
  12808. {
  12809. int len=ftppathlen-i;
  12810. if(ftppath[len]== 47) // '/' ascll code: 47
  12811. {
  12812. DEBUG_INFO("compare '/' all right\n");
  12813. break;
  12814. }
  12815. i=i+1;
  12816. }
  12817. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12818. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12819. filenametemp[i+1] = 0;
  12820. do
  12821. {
  12822. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12823. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12824. sleep(1);
  12825. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12826. if(!isSuccess)
  12827. {
  12828. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12829. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12830. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12831. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12832. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12833. }
  12834. else
  12835. {
  12836. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12837. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12838. }
  12839. retriesInt--;
  12840. }while((isSuccess == 0)&&(retriesInt >= 0));
  12841. }
  12842. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12843. {
  12844. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12845. memset(temp, 0, ARRAY_SIZE(temp));
  12846. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12847. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12848. int ftppathlen=strlen(ftpbuf);
  12849. int i=1;
  12850. char filenametemp[50];
  12851. while(i < ftppathlen)
  12852. {
  12853. int len=ftppathlen-i;
  12854. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12855. {
  12856. DEBUG_INFO(" compare '/' all right\n");
  12857. break;
  12858. }
  12859. i=i+1;
  12860. }
  12861. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12862. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12863. filenametemp[i+1] = 0;
  12864. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12865. pch=strchr(temp,'@');
  12866. if(pch==NULL)
  12867. {
  12868. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12869. protocol, host, &port, path);
  12870. strcpy(user,"anonymous");
  12871. strcpy(password,"");
  12872. }
  12873. else
  12874. {
  12875. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12876. protocol, user, password, host, &port, path);
  12877. }
  12878. sscanf(host,"%[^/]%s",host1, path1);
  12879. sprintf(ftppath,"%s", path1);
  12880. //DEBUG_INFO("protocol =%s\n",protocol);
  12881. //DEBUG_INFO("user =%s\n",user);
  12882. //DEBUG_INFO("password =%s\n",password);
  12883. //DEBUG_INFO("host1 =%s\n",host1);
  12884. //DEBUG_INFO("port =%d\n",port);
  12885. //DEBUG_INFO("path1 =%s\n",path1);
  12886. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12887. //ftpFile(host, user, password, port, ftppath, fname);
  12888. //download firmware pthred
  12889. if(port == 0)
  12890. {
  12891. port = 21;
  12892. }
  12893. do
  12894. {
  12895. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12896. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12897. sleep(1);
  12898. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12899. if(!isSuccess)
  12900. {
  12901. //BulldogUtil.sleepMs(interval*1000);
  12902. DEBUG_INFO("Update firmware request and download file fail.\n");
  12903. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12904. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12905. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12906. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12907. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12908. }
  12909. else
  12910. {
  12911. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12912. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12913. }
  12914. retriesInt--;
  12915. }while((!isSuccess)&&(retriesInt >= 0));
  12916. }
  12917. else
  12918. {
  12919. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12920. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12921. sleep(1);
  12922. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12923. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12924. }
  12925. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12926. interLock.isUpdateFirmwareGoing = 0;
  12927. pthread_exit(NULL);
  12928. }
  12929. int handleCertificateSignedRequest(char *uuid, char *payload)
  12930. {
  12931. mtrace();
  12932. int result = PASS;
  12933. json_object *CertificateSigned;
  12934. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12935. CertificateSigned = json_tokener_parse(payload);
  12936. if(!is_error(CertificateSigned))
  12937. {
  12938. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  12939. }
  12940. json_object_put(CertificateSigned);
  12941. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  12942. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  12943. fclose(fp);
  12944. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12945. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  12946. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  12947. sendCertificateSignedConfirmation(uuid);
  12948. return result;
  12949. }
  12950. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12951. {
  12952. mtrace();
  12953. int result = PASS;
  12954. json_object *DeleteCertificate;
  12955. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12956. DeleteCertificate = json_tokener_parse(payload);
  12957. if(!is_error(DeleteCertificate))
  12958. {
  12959. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12960. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12961. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12962. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12963. }
  12964. json_object_put(DeleteCertificate);
  12965. /*
  12966. * TODO: Delete certificateSigned process
  12967. */
  12968. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  12969. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  12970. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  12971. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  12972. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  12973. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  12974. sendDeleteCertificateConfirmation(uuid);
  12975. return result;
  12976. }
  12977. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12978. {
  12979. mtrace();
  12980. int result = PASS;
  12981. json_object *ExtendedTriggerMessage;
  12982. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12983. ExtendedTriggerMessage = json_tokener_parse(payload);
  12984. if(!is_error(ExtendedTriggerMessage))
  12985. {
  12986. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12987. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12988. {
  12989. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12990. }
  12991. else
  12992. {
  12993. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  12994. }
  12995. }
  12996. json_object_put(ExtendedTriggerMessage);
  12997. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  12998. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  12999. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13000. {
  13001. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13002. }
  13003. else
  13004. {
  13005. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13006. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13007. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13008. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13009. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13010. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13011. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13012. {
  13013. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13014. }
  13015. else
  13016. {
  13017. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13018. }
  13019. }
  13020. sendExtendedTriggerMessageConfirmation(uuid);
  13021. //==========================
  13022. // Trigger message
  13023. //==========================
  13024. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13025. {
  13026. //sendBootNotificationRequest();
  13027. server_sign = FALSE;
  13028. }
  13029. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13030. {
  13031. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13032. }
  13033. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13034. {
  13035. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13036. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13037. {
  13038. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13039. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13040. }
  13041. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13042. }
  13043. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13044. {
  13045. refreshStartTimer(&clientTime.Heartbeat);
  13046. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13047. }
  13048. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13049. {
  13050. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13051. {
  13052. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13053. }
  13054. else
  13055. {
  13056. for(int idx=0;idx< gunTotalNumber;idx++)
  13057. {
  13058. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13059. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13060. }
  13061. }
  13062. }
  13063. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13064. {
  13065. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  13066. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13067. {
  13068. 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\" &");
  13069. }
  13070. }
  13071. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13072. {
  13073. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13074. {
  13075. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13076. }
  13077. else
  13078. {
  13079. for(int idx=0;idx< gunTotalNumber;idx++)
  13080. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13081. }
  13082. }
  13083. return result;
  13084. }
  13085. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13086. {
  13087. mtrace();
  13088. int result = PASS;
  13089. json_object *GetInstalledCertificateIds;
  13090. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13091. GetInstalledCertificateIds = json_tokener_parse(payload);
  13092. if(!is_error(GetInstalledCertificateIds))
  13093. {
  13094. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13095. }
  13096. json_object_put(GetInstalledCertificateIds);
  13097. /*
  13098. * TODO: Return installed certificate process
  13099. */
  13100. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13101. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  13102. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13103. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13104. sendGetInstalledCertificateIdsConfirmation(uuid);
  13105. return result;
  13106. }
  13107. int handleGetLogRequest(char *uuid, char *payload)
  13108. {
  13109. mtrace();
  13110. int result = PASS;
  13111. json_object *GetLog;
  13112. DEBUG_INFO("handleGetLogRequest...\n");
  13113. GetLog = json_tokener_parse(payload);
  13114. if(!is_error(GetLog))
  13115. {
  13116. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13117. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13118. if(json_object_object_get(GetLog, "retries") != NULL)
  13119. {
  13120. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13121. }
  13122. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13123. {
  13124. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13125. }
  13126. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13127. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13128. {
  13129. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13130. }
  13131. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13132. {
  13133. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13134. }
  13135. }
  13136. json_object_put(GetLog);
  13137. /*
  13138. * TODO: Upload log process
  13139. */
  13140. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  13141. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  13142. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  13143. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  13144. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  13145. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  13146. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  13147. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  13148. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  13149. sendGetLogConfirmation(uuid);
  13150. return result;
  13151. }
  13152. int handleInstallCertificateRequest(char *uuid, char *payload)
  13153. {
  13154. mtrace();
  13155. int result = PASS;
  13156. json_object *InstallCertificate;
  13157. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13158. InstallCertificate = json_tokener_parse(payload);
  13159. if(!is_error(InstallCertificate))
  13160. {
  13161. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13162. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13163. /*
  13164. * TODO: Install certificate process
  13165. */
  13166. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  13167. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  13168. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  13169. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  13170. sendInstallCertificateConfirmation(uuid);
  13171. }
  13172. json_object_put(InstallCertificate);
  13173. return result;
  13174. }
  13175. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13176. {
  13177. mtrace();
  13178. int result = PASS;
  13179. json_object *SignedUpdateFirmware;
  13180. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13181. SignedUpdateFirmware = json_tokener_parse(payload);
  13182. if(!is_error(SignedUpdateFirmware))
  13183. {
  13184. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13185. {
  13186. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13187. }
  13188. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13189. {
  13190. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13191. }
  13192. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13193. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13194. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13195. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13196. {
  13197. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13198. }
  13199. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13200. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13201. }
  13202. json_object_put(SignedUpdateFirmware);
  13203. /*
  13204. * TODO: Upgrade firmware process
  13205. */
  13206. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13207. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  13208. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  13209. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  13210. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  13211. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  13212. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  13213. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  13214. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  13215. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  13216. sendInstallCertificateConfirmation(uuid);
  13217. return result;
  13218. }
  13219. int handleUnknownRequest(char *uuid, char *payload)
  13220. {
  13221. mtrace();
  13222. int result = PASS;
  13223. DEBUG_INFO("handleUnknownRequest...\n");
  13224. sendUnknownConfirmation(uuid);
  13225. result = PASS;
  13226. return result;
  13227. }
  13228. //==========================================
  13229. // Handle server response routine
  13230. //==========================================
  13231. void handleAuthorizeResponse(char *payload, int gun_index)
  13232. {
  13233. mtrace();
  13234. char expiryDatestr[30]={0};
  13235. char parentIdTagstr[20]={0};
  13236. char statusstr[20]={0};
  13237. int expiryDateISNULL=FALSE;
  13238. int parentIdTagISNULL=FALSE;
  13239. DEBUG_INFO("handleAuthorizeResponse...\n");
  13240. json_object *Authorize;
  13241. Authorize = json_tokener_parse(payload);
  13242. if(!is_error(Authorize))
  13243. {
  13244. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13245. {
  13246. // Required data
  13247. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13248. // Optional data
  13249. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13250. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13251. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13252. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13253. }
  13254. }
  13255. json_object_put(Authorize);
  13256. if(expiryDateISNULL == FALSE)
  13257. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13258. if(parentIdTagISNULL == FALSE)
  13259. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13260. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  13261. //Update idTag information to authorization cache if supproted
  13262. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13263. {
  13264. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13265. }
  13266. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  13267. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13268. authorizeRetryTimes = 0;
  13269. }
  13270. void handleBootNotificationResponse(char *payload, int gun_index)
  13271. {
  13272. mtrace();
  13273. char statusStr[12]={0};
  13274. char currentTimeStr[30]={0};
  13275. int intervalInt = 0;
  13276. DEBUG_INFO("handleBootNotificationResponse...\n");
  13277. json_object *BootNotification;
  13278. BootNotification = json_tokener_parse(payload);
  13279. if(!is_error(BootNotification))
  13280. {
  13281. // Required data
  13282. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13283. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13284. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13285. }
  13286. json_object_put(BootNotification);
  13287. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13288. BootNotificationInterval = intervalInt;
  13289. //write back to ShmOCPP16Data->BootNotification
  13290. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  13291. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13292. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  13293. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13294. {
  13295. if((intervalInt == 0) || (intervalInt >= 10))
  13296. {
  13297. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13298. HeartBeatWaitTime = intervalInt;
  13299. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13300. }
  13301. server_sign = TRUE;
  13302. server_pending =FALSE;
  13303. }
  13304. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13305. {
  13306. server_pending = TRUE;
  13307. }
  13308. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  13309. srand(time(NULL));
  13310. refreshStartTimer(&clientTime.Heartbeat);
  13311. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13312. SetOcppConnStatus(TRUE);
  13313. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  13314. }
  13315. void handleDataTransferResponse(char *payload, int gun_index)
  13316. {
  13317. json_object *DataTransfer = json_tokener_parse(payload);
  13318. if(!is_error(DataTransfer))
  13319. {
  13320. // Required data
  13321. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13322. // Optional data
  13323. if(json_object_object_get(DataTransfer, "data") != NULL)
  13324. {
  13325. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13326. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13327. if(!is_error(Data))
  13328. {
  13329. if(json_object_object_get(Data, "msgId") != NULL)
  13330. {
  13331. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13332. {
  13333. 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")));
  13334. }
  13335. }
  13336. }
  13337. json_object_put(Data);
  13338. }
  13339. }
  13340. json_object_put(DataTransfer);
  13341. }
  13342. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13343. {
  13344. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13345. //struct json_object *obj;
  13346. // obj = json_tokener_parse(payload);
  13347. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13348. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13349. //No fields are defined.
  13350. }
  13351. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13352. {
  13353. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13354. //struct json_object *obj;
  13355. // obj = json_tokener_parse(payload);
  13356. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13357. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13358. //No fields are defined.
  13359. }
  13360. void handleHeartbeatResponse(char *payload, int gun_index)
  13361. {
  13362. mtrace();
  13363. DEBUG_INFO("handleHeartbeatResponse...\n");
  13364. json_object *Heartbeat;
  13365. Heartbeat = json_tokener_parse(payload);
  13366. if(!is_error(Heartbeat))
  13367. {
  13368. // Required data
  13369. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13370. }
  13371. json_object_put(Heartbeat);
  13372. if(FirstHeartBeat == 0)
  13373. {
  13374. FirstHeartBeat = 1;
  13375. DEBUG_INFO("FirstHeartBeat \n");
  13376. }
  13377. HeartBeatWithNOResponse = 0;
  13378. refreshStartTimer(&clientTime.Heartbeat);
  13379. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  13380. }
  13381. void handleMeterValuesResponse(char *payload, int gun_index)
  13382. {
  13383. mtrace();
  13384. DEBUG_INFO("handleMeterValuesResponse...\n");
  13385. isQueueSendable = 1;
  13386. }
  13387. void handleStartTransactionResponse(char *payload, int gun_index)
  13388. {
  13389. mtrace();
  13390. //int transactionIdInt = 0;
  13391. FILE *outfile;
  13392. char data[100]={0};
  13393. DEBUG_INFO("handleStartTransactionResponse...\n");
  13394. json_object *StartTransaction;
  13395. StartTransaction = json_tokener_parse(payload);
  13396. if(!is_error(StartTransaction))
  13397. {
  13398. // Required data
  13399. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13400. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13401. // Optional data
  13402. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13403. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13404. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13405. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13406. }
  13407. json_object_put(StartTransaction);
  13408. isQueueSendable = 1;
  13409. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13410. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13411. //-----------Start : write to the Queue TransactionId file -----------------//
  13412. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  13413. {}
  13414. else
  13415. {
  13416. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  13417. if(log == NULL)
  13418. {
  13419. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13420. return ;
  13421. }
  13422. else
  13423. {
  13424. fclose(log);
  13425. }
  13426. }
  13427. // open file for writing
  13428. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13429. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  13430. {
  13431. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  13432. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13433. fputs(data, outfile);
  13434. fclose (outfile);
  13435. }
  13436. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13437. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13438. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13439. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  13440. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13441. }
  13442. void handleStatusNotificationResponse(char *payload, int gun_index)
  13443. {
  13444. mtrace();
  13445. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13446. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13447. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13448. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13449. }
  13450. void handleStopTransactionnResponse(char *payload, int gun_index)
  13451. {
  13452. mtrace();
  13453. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13454. json_object *StopTransaction;
  13455. StopTransaction = json_tokener_parse(payload);
  13456. if(!is_error(StopTransaction))
  13457. {
  13458. // Optional data
  13459. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13460. {
  13461. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13462. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13463. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13464. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13465. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13466. }
  13467. }
  13468. json_object_put(StopTransaction);
  13469. isQueueSendable = 1;
  13470. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13471. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13472. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13473. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13474. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13475. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13476. }
  13477. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13478. {
  13479. mtrace();
  13480. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13481. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  13482. }
  13483. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13484. {
  13485. mtrace();
  13486. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13487. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  13488. }
  13489. void handleSignCertificateResponse(char *payload, int gun_index)
  13490. {
  13491. mtrace();
  13492. DEBUG_INFO("handleSignCertificateResponse...\n");
  13493. json_object *SignCertificate;
  13494. SignCertificate = json_tokener_parse(payload);
  13495. if(!is_error(SignCertificate))
  13496. {
  13497. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13498. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  13499. }
  13500. json_object_put(SignCertificate);
  13501. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  13502. }
  13503. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13504. {
  13505. mtrace();
  13506. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13507. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13508. }
  13509. //==========================================
  13510. // Handle Error routine
  13511. //==========================================
  13512. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13513. {
  13514. mtrace();
  13515. #ifdef SystemLogMessage
  13516. DEBUG_INFO("errorCode: %s\n", errorCode);
  13517. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13518. DEBUG_INFO("errorDetails: %s\n", payload);
  13519. #endif
  13520. }
  13521. //===============================================
  13522. // Common routine
  13523. //===============================================
  13524. int initialConfigurationTable(void)
  13525. {
  13526. //clock_t start_t, end_t, total_t;
  13527. FILE *fp;
  13528. FILE *outfile;
  13529. char str[512]={0};
  13530. char sstr[256]={0};
  13531. int c = 0;
  13532. char *loc;
  13533. int confVersion = 12;
  13534. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13535. //start_t = clock();
  13536. //printf("Starting of the program, start_t = %ld\n", start_t);
  13537. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13538. // Check configuration file size is correct
  13539. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  13540. {
  13541. struct stat st;
  13542. stat("/Storage/OCPP/OCPPConfiguration", &st);
  13543. if(st.st_size < 3100)
  13544. {
  13545. system("rm -f /Storage/OCPP/OCPPConfiguration");
  13546. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13547. }
  13548. }
  13549. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  13550. {
  13551. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13552. if(outfile == NULL)
  13553. {
  13554. DEBUG_INFO("Error opening file\n");
  13555. return FALSE;
  13556. }
  13557. /*Core Profile*/
  13558. //AllowOfflineTxForUnknownId
  13559. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13562. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13563. //AuthorizationCacheEnabled
  13564. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13565. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13567. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13568. //AuthorizeRemoteTxRequests
  13569. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13572. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13573. //BlinkRepeat
  13574. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13577. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13578. //ClockAlignedDataInterval
  13579. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13580. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13582. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13583. //ConnectionTimeOut
  13584. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13586. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13587. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13588. //GetConfigurationMaxKeys
  13589. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13591. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13592. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13593. // HeartbeatInterval
  13594. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13597. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13598. // LightIntensity
  13599. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13600. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13602. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13603. // LocalAuthorizeOffline
  13604. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13607. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13608. // LocalPreAuthorize
  13609. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13612. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13613. // MaxEnergyOnInvalidId
  13614. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13617. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13618. // MeterValuesAlignedData
  13619. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13621. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13622. 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" );
  13623. else
  13624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13625. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13626. // MeterValuesAlignedDataMaxLength
  13627. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13628. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13629. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13631. else
  13632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13633. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13634. // MeterValuesSampledData
  13635. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13637. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13638. 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" );
  13639. else
  13640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13641. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13642. // MeterValuesSampledDataMaxLength
  13643. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13645. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13647. else
  13648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13649. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13650. // MeterValueSampleInterval
  13651. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13654. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13655. // MinimumStatusDuration
  13656. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13659. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13660. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13661. // NumberOfConnectors
  13662. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13663. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13664. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13665. {
  13666. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13667. }
  13668. else
  13669. {
  13670. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13671. }
  13672. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13673. // ResetRetries
  13674. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13677. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13678. // ConnectorPhaseRotation
  13679. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13682. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13683. // ConnectorPhaseRotationMaxLength
  13684. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13687. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13688. // StopTransactionOnEVSideDisconnect
  13689. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13692. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13693. // StopTransactionOnInvalidId
  13694. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13697. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13698. // StopTxnAlignedData
  13699. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13702. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13703. // StopTxnAlignedDataMaxLength
  13704. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13705. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13707. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13708. // StopTxnSampledData
  13709. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13711. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13713. else
  13714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13715. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13716. // StopTxnSampledDataMaxLength
  13717. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13719. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13720. {
  13721. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13722. }
  13723. else
  13724. {
  13725. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13726. }
  13727. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13728. // SupportedFeatureProfiles
  13729. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13732. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13733. // SupportedFeatureProfilesMaxLength
  13734. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13737. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13738. // TransactionMessageAttempts
  13739. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13742. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13743. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13744. // TransactionMessageRetryInterval
  13745. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13748. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13749. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13750. // UnlockConnectorOnEVSideDisconnect
  13751. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13754. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13755. // WebSocketPingInterval
  13756. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13759. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13760. // QueueOffLineMeterValues
  13761. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13762. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13764. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13765. // AuthorizationKey
  13766. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  13769. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13770. // SecurityProfile
  13771. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13773. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  13774. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13775. // DefaultPrice
  13776. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13779. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13780. // CustomDisplayCostAndPrice
  13781. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13785. // CustomIdleFeeAfterStop
  13786. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13790. // TimeOffset
  13791. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  13794. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13795. // NextTimeOffsetTransitionDateTime
  13796. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  13799. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13800. // TimeOffsetNextTransition
  13801. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  13804. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13805. // SystemUptimeSec
  13806. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13809. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13810. // FreeVend
  13811. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "Free-FreeVend");
  13813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13814. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13815. // OcppServer
  13816. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13818. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13820. // MaintainServer
  13821. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13823. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13825. // StatusNotificationPeriodically
  13826. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13829. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13830. // StatusNotificationInterval
  13831. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13835. // Configuration Version
  13836. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13838. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13840. //* Local Auth List Management Profile*/
  13841. #if 0
  13842. //For OCTT Test Case
  13843. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13846. #endif
  13847. #if 1
  13848. //LocalAuthListEnabled
  13849. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13852. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13853. #endif
  13854. //LocalAuthListMaxLength
  13855. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  13858. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13859. //SendLocalListMaxLength
  13860. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13863. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13864. //ReserveConnectorZeroSupported
  13865. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13869. //* Smart Charging Profile */
  13870. //ChargeProfileMaxStackLevel
  13871. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13874. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13875. // ChargingScheduleAllowedChargingRateUnit
  13876. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13879. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13880. // ChargingScheduleMaxPeriods
  13881. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13884. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13885. // ConnectorSwitch3to1PhaseSupported
  13886. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13890. // MaxChargingProfilesInstalled
  13891. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13894. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13895. fclose(outfile);
  13896. }
  13897. else
  13898. {
  13899. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  13900. char keystr[60]={0};
  13901. char readonlystr[10]={0};
  13902. char valuestr[256]={0};
  13903. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  13904. if(fp == NULL) {
  13905. DEBUG_INFO("Error opening file");
  13906. return FALSE;
  13907. }
  13908. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13909. {
  13910. //DEBUG_INFO("Get Configuration \n");
  13911. if(strlen(str) > 0)
  13912. {
  13913. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13914. //*************************key*********************************/
  13915. if(strstr(str, "key") != NULL)
  13916. {
  13917. loc = strstr(str, "key");
  13918. c = 0;
  13919. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13920. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13921. {
  13922. sstr[c] = loc[strlen("key")+3+c];
  13923. c++;
  13924. }
  13925. sstr[c] = '\0';
  13926. strcpy(keystr,sstr);
  13927. }
  13928. //*************************readonly*********************************/
  13929. if(strstr(str, "readonly") != NULL)
  13930. {
  13931. loc = strstr(str, "readonly");
  13932. c = 0;
  13933. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13934. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13935. {
  13936. sstr[c] = loc[strlen("readonly")+2+c];
  13937. c++;
  13938. }
  13939. sstr[c] = '\0';
  13940. strcpy(readonlystr,sstr);
  13941. }
  13942. //*************************value*********************************/
  13943. if(strstr(str, "value") != NULL)
  13944. {
  13945. loc = strstr(str, "value");
  13946. c = 0;
  13947. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13948. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13949. {
  13950. sstr[c] = loc[strlen("value")+3+c];
  13951. c++;
  13952. }
  13953. sstr[c] = '\0';
  13954. strcpy(valuestr,sstr);
  13955. }
  13956. // DEBUG_INFO("keystr=%s\n",keystr);
  13957. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13958. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13959. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13960. {
  13961. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13962. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13963. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13964. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13965. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13966. }
  13967. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13968. {
  13969. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13970. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13971. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13972. }
  13973. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13974. {
  13975. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13976. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13977. }
  13978. if(strcmp(keystr, "BlinkRepeat") == 0)
  13979. {
  13980. //Charger.BlinkRepeat = Integer.parseInt(value);
  13981. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13982. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13983. }
  13984. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13985. {
  13986. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13987. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13988. }
  13989. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13990. {
  13991. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13992. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13993. }
  13994. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13995. {
  13996. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13997. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13998. }
  13999. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14000. {
  14001. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14002. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14003. HeartBeatWaitTime = atoi(valuestr);
  14004. }
  14005. if(strcmp(keystr, "LightIntensity") == 0)
  14006. {
  14007. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14008. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14009. }
  14010. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14011. {
  14012. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14013. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14014. }
  14015. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14016. {
  14017. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14019. }
  14020. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14021. {
  14022. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14023. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14024. }
  14025. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14026. {
  14027. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14028. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14029. }
  14030. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14031. {
  14032. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14033. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14034. }
  14035. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14036. {
  14037. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14038. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14039. }
  14040. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14041. {
  14042. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14043. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14044. }
  14045. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14046. {
  14047. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14048. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14049. }
  14050. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14051. {
  14052. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14053. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14054. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14055. }
  14056. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14057. {
  14058. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14059. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14060. }
  14061. if(strcmp(keystr, "ResetRetries") == 0)
  14062. {
  14063. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14064. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14065. }
  14066. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14067. {
  14068. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14069. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14070. }
  14071. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14072. {
  14073. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14074. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14075. }
  14076. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14077. {
  14078. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14079. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14080. }
  14081. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14082. {
  14083. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14084. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14085. }
  14086. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14087. {
  14088. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14089. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14090. }
  14091. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14092. {
  14093. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14094. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14095. }
  14096. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14097. {
  14098. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14099. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14100. }
  14101. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14102. {
  14103. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14104. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14105. }
  14106. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14107. {
  14108. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14109. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14110. }
  14111. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14112. {
  14113. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14114. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14115. }
  14116. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14117. {
  14118. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14119. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14120. TransactionMessageAttemptsValue = atoi(valuestr);
  14121. }
  14122. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14123. {
  14124. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14125. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14126. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14127. }
  14128. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14129. {
  14130. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14131. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14132. }
  14133. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14134. {
  14135. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14136. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14137. }
  14138. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14139. {
  14140. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14141. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14142. }
  14143. if(strcmp(keystr, "AuthorizationKey") == 0)
  14144. {
  14145. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14146. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14147. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14148. }
  14149. if(strcmp(keystr, "SecurityProfile") == 0)
  14150. {
  14151. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14152. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14153. }
  14154. if(strcmp(keystr, "DefaultPrice") == 0)
  14155. {
  14156. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14157. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14158. }
  14159. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14160. {
  14161. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14162. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14163. }
  14164. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14165. {
  14166. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14167. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14168. }
  14169. if(strcmp(keystr, "TimeOffset") == 0)
  14170. {
  14171. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14172. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  14173. }
  14174. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  14175. {
  14176. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14177. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  14178. }
  14179. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  14180. {
  14181. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14182. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  14183. }
  14184. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14185. {
  14186. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14187. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  14188. }
  14189. if(strcmp(keystr, "FreeVend") == 0)
  14190. {
  14191. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14192. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14193. }
  14194. if(strcmp(keystr, "OcppServer") == 0)
  14195. {
  14196. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14197. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14198. }
  14199. if(strcmp(keystr, "MaintainServer") == 0)
  14200. {
  14201. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14202. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14203. }
  14204. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14205. {
  14206. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14207. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14208. }
  14209. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14210. {
  14211. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14212. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14213. }
  14214. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14215. {
  14216. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14217. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14218. }
  14219. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14220. {
  14221. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14222. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14223. }
  14224. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14225. {
  14226. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14227. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14228. }
  14229. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14230. {
  14231. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14232. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14233. }
  14234. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14235. {
  14236. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14237. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14238. }
  14239. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14240. {
  14241. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14242. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14243. }
  14244. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14245. {
  14246. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14247. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14248. }
  14249. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14250. {
  14251. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14252. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14253. }
  14254. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14255. {
  14256. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14257. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14258. }
  14259. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14260. {
  14261. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14262. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14263. }
  14264. }
  14265. }
  14266. fclose(fp);
  14267. }
  14268. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14269. {
  14270. return PASS;
  14271. }
  14272. else
  14273. {
  14274. return FAIL;
  14275. }
  14276. }
  14277. void StoreConfigurationTable(void)
  14278. {
  14279. FILE *outfile;
  14280. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14281. if(outfile == NULL)
  14282. {
  14283. DEBUG_INFO("Error opening file");
  14284. return ;
  14285. }
  14286. /*Core Profile*/
  14287. //AllowOfflineTxForUnknownId
  14288. /*
  14289. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14290. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14293. */
  14294. //DEBUG_INFO("data=%s\n",data);
  14295. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14296. //AuthorizationCacheEnabled
  14297. /*
  14298. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14301. */
  14302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14303. //AuthorizeRemoteTxRequests
  14304. /*
  14305. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14308. */
  14309. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14310. //BlinkRepeat
  14311. /*
  14312. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14313. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14315. */
  14316. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14317. //ClockAlignedDataInterval
  14318. /*
  14319. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14322. */
  14323. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14324. //ConnectionTimeOut
  14325. /*
  14326. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14329. */
  14330. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14331. //GetConfigurationMaxKeys
  14332. /*
  14333. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14336. */
  14337. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14338. // HeartbeatInterval
  14339. /*
  14340. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14341. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14343. */
  14344. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14345. // LightIntensity
  14346. /*
  14347. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14350. */
  14351. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14352. // LocalAuthorizeOffline
  14353. /*
  14354. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14357. */
  14358. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14359. // LocalPreAuthorize
  14360. /*
  14361. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14364. */
  14365. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14366. // MaxEnergyOnInvalidId
  14367. /*
  14368. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14369. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14371. */
  14372. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14373. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14374. // MeterValuesAlignedData
  14375. /*
  14376. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14379. */
  14380. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14381. // MeterValuesAlignedDataMaxLength
  14382. /*
  14383. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14386. */
  14387. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14388. // MeterValuesSampledData
  14389. /*
  14390. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14393. */
  14394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14395. // MeterValuesSampledDataMaxLength
  14396. /*
  14397. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14400. */
  14401. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14402. // MeterValueSampleInterval
  14403. /*
  14404. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14407. */
  14408. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14409. // MinimumStatusDuration
  14410. /*
  14411. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14413. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14414. */
  14415. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14416. // NumberOfConnectors
  14417. /*
  14418. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14420. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14421. {
  14422. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14423. }
  14424. else
  14425. {
  14426. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14427. }
  14428. */
  14429. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14430. // ResetRetries
  14431. /*
  14432. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14435. */
  14436. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14437. // ConnectorPhaseRotation
  14438. /*
  14439. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14442. */
  14443. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14444. // ConnectorPhaseRotationMaxLength
  14445. /*
  14446. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14449. */
  14450. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14451. // StopTransactionOnEVSideDisconnect
  14452. /*
  14453. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14456. */
  14457. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14458. // StopTransactionOnInvalidId
  14459. /*
  14460. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14461. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14463. */
  14464. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14465. // StopTxnAlignedData
  14466. /*
  14467. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14469. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14470. */
  14471. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14472. // StopTxnAlignedDataMaxLength
  14473. /*
  14474. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14475. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14477. */
  14478. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14479. // StopTxnSampledData
  14480. /*
  14481. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14484. */
  14485. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14486. // StopTxnSampledDataMaxLength
  14487. /*
  14488. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14489. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14491. */
  14492. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14493. // SupportedFeatureProfiles
  14494. /*
  14495. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14498. */
  14499. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14500. // SupportedFeatureProfilesMaxLength
  14501. /*
  14502. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14505. */
  14506. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14507. // TransactionMessageAttempts
  14508. /*
  14509. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14512. */
  14513. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14514. // TransactionMessageRetryInterval
  14515. /*
  14516. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14519. */
  14520. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14521. // UnlockConnectorOnEVSideDisconnect
  14522. /*
  14523. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14524. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14526. */
  14527. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14528. // WebSocketPingInterval
  14529. /*
  14530. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14533. */
  14534. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14535. // QueueOffLineMeterValues
  14536. /*
  14537. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14538. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14540. */
  14541. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14542. // AuthorizationKey
  14543. /*
  14544. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14545. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14547. */
  14548. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14549. // SecurityProfile
  14550. /*
  14551. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14554. */
  14555. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14556. // DefaultPrice
  14557. /*
  14558. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14561. */
  14562. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14563. // CustomDisplayCostAndPrice
  14564. /*
  14565. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14568. */
  14569. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14570. // CustomIdleFeeAfterStop
  14571. /*
  14572. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14575. */
  14576. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14577. // TimeOffset
  14578. /*
  14579. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14580. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  14582. */
  14583. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14584. // NextTimeOffsetTransitionDateTime
  14585. /*
  14586. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  14589. */
  14590. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14591. // TimeOffsetNextTransition
  14592. /*
  14593. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  14596. */
  14597. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14598. // SystemUptimeSec
  14599. /*
  14600. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14603. */
  14604. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14605. // FreeVend
  14606. /*
  14607. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14608. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14610. */
  14611. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14612. // OcppServer
  14613. /*
  14614. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14617. */
  14618. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14619. // MaintainServer
  14620. /*
  14621. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14624. */
  14625. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14626. // StatusNotificationPeriodically
  14627. /*
  14628. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14629. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14631. */
  14632. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14633. // StatusNotificationInterval
  14634. /*
  14635. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14638. */
  14639. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14640. // ConfigurationVersion
  14641. /*
  14642. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14645. */
  14646. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14647. //* Local Auth List Management Profile*/
  14648. //LocalAuthListEnabled
  14649. /*
  14650. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14653. */
  14654. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14655. //LocalAuthListMaxLength
  14656. /*
  14657. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14660. */
  14661. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14662. //SendLocalListMaxLength
  14663. /*
  14664. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14667. */
  14668. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14669. //ReserveConnectorZeroSupported
  14670. /*
  14671. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14674. */
  14675. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14676. //* Smart Charging Profile */
  14677. //ChargeProfileMaxStackLevel
  14678. /*
  14679. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14682. */
  14683. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14684. // ChargingScheduleAllowedChargingRateUnit
  14685. /*
  14686. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14687. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14689. */
  14690. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14691. // ChargingScheduleMaxPeriods
  14692. /*
  14693. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14696. */
  14697. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14698. // ConnectorSwitch3to1PhaseSupported
  14699. /*
  14700. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14703. */
  14704. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14705. // MaxChargingProfilesInstalled
  14706. /*
  14707. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14710. */
  14711. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14712. fclose(outfile);
  14713. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14714. }
  14715. void getKeyValue(char *keyReq)
  14716. {
  14717. int isEmpty = FALSE;
  14718. int isKnowKey = FALSE;
  14719. DEBUG_INFO("keyReq = %s\n", keyReq);
  14720. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14721. isEmpty = TRUE;
  14722. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14723. {
  14724. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14726. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14727. {
  14728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14729. }
  14730. else
  14731. {
  14732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14733. }
  14734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14735. isKnowKey = TRUE;
  14736. }
  14737. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14738. {
  14739. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14741. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14742. {
  14743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14744. }
  14745. else
  14746. {
  14747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14748. }
  14749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14750. isKnowKey = TRUE;
  14751. }
  14752. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14753. {
  14754. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14756. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14757. {
  14758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14759. }
  14760. else
  14761. {
  14762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14763. }
  14764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14765. isKnowKey = TRUE;
  14766. }
  14767. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14768. {
  14769. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14771. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14772. {
  14773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14774. }
  14775. else
  14776. {
  14777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14778. }
  14779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14780. isKnowKey = TRUE;
  14781. }
  14782. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14783. {
  14784. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14785. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14786. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14787. {
  14788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14789. }
  14790. else
  14791. {
  14792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14793. }
  14794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14795. isKnowKey = TRUE;
  14796. }
  14797. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14798. {
  14799. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14800. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14801. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14802. {
  14803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14804. }
  14805. else
  14806. {
  14807. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14808. }
  14809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14810. isKnowKey = TRUE;
  14811. }
  14812. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14813. {
  14814. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14815. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14816. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14817. {
  14818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14819. }
  14820. else
  14821. {
  14822. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14823. }
  14824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14825. isKnowKey = TRUE;
  14826. }
  14827. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14828. {
  14829. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14830. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14831. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14832. {
  14833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14834. }
  14835. else
  14836. {
  14837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14838. }
  14839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14840. isKnowKey = TRUE;
  14841. }
  14842. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14843. {
  14844. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14845. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14846. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14847. {
  14848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14849. }
  14850. else
  14851. {
  14852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14853. }
  14854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14855. isKnowKey = TRUE;
  14856. }
  14857. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14858. {
  14859. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14861. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14862. {
  14863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14864. }
  14865. else
  14866. {
  14867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14868. }
  14869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14870. isKnowKey = TRUE;
  14871. }
  14872. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14873. {
  14874. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14875. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14876. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14877. {
  14878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14879. }
  14880. else
  14881. {
  14882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14883. }
  14884. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14885. isKnowKey = TRUE;
  14886. }
  14887. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14888. {
  14889. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14891. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14892. {
  14893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14894. }
  14895. else
  14896. {
  14897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14898. }
  14899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14900. isKnowKey = TRUE;
  14901. }
  14902. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14903. {
  14904. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14906. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14907. {
  14908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14909. }
  14910. else
  14911. {
  14912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14913. }
  14914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14915. isKnowKey = TRUE;
  14916. }
  14917. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14918. {
  14919. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14921. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14922. {
  14923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14924. }
  14925. else
  14926. {
  14927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14928. }
  14929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14930. isKnowKey = TRUE;
  14931. }
  14932. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14933. {
  14934. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14936. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14937. {
  14938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14939. }
  14940. else
  14941. {
  14942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14943. }
  14944. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14945. isKnowKey = TRUE;
  14946. }
  14947. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14948. {
  14949. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14951. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14952. {
  14953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14954. }
  14955. else
  14956. {
  14957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14958. }
  14959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14960. isKnowKey = TRUE;
  14961. }
  14962. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14963. {
  14964. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14966. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14967. {
  14968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14969. }
  14970. else
  14971. {
  14972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14973. }
  14974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14975. isKnowKey = TRUE;
  14976. }
  14977. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14978. {
  14979. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14981. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14982. {
  14983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14984. }
  14985. else
  14986. {
  14987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14988. }
  14989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  14990. isKnowKey = TRUE;
  14991. }
  14992. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14993. {
  14994. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14996. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14997. {
  14998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14999. }
  15000. else
  15001. {
  15002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15003. }
  15004. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15006. isKnowKey = TRUE;
  15007. }
  15008. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15009. {
  15010. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15012. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15013. {
  15014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15015. }
  15016. else
  15017. {
  15018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15019. }
  15020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15021. isKnowKey = TRUE;
  15022. }
  15023. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15024. {
  15025. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15027. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15028. {
  15029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15030. }
  15031. else
  15032. {
  15033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15034. }
  15035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15036. isKnowKey = TRUE;
  15037. }
  15038. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15039. {
  15040. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15042. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15043. {
  15044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15045. }
  15046. else
  15047. {
  15048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15049. }
  15050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15051. isKnowKey = TRUE;
  15052. }
  15053. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15054. {
  15055. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15057. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15058. {
  15059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15060. }
  15061. else
  15062. {
  15063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15064. }
  15065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15066. isKnowKey = TRUE;
  15067. }
  15068. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15069. {
  15070. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15072. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15073. {
  15074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15075. }
  15076. else
  15077. {
  15078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15079. }
  15080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15081. isKnowKey = TRUE;
  15082. }
  15083. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15084. {
  15085. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15087. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15088. {
  15089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15090. }
  15091. else
  15092. {
  15093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15094. }
  15095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15096. isKnowKey = TRUE;
  15097. }
  15098. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15099. {
  15100. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15102. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15103. {
  15104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15105. }
  15106. else
  15107. {
  15108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15109. }
  15110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15111. isKnowKey = TRUE;
  15112. }
  15113. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15114. {
  15115. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15117. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15118. {
  15119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15120. }
  15121. else
  15122. {
  15123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15124. }
  15125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15126. isKnowKey = TRUE;
  15127. }
  15128. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15129. {
  15130. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15132. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15133. {
  15134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15135. }
  15136. else
  15137. {
  15138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15139. }
  15140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15141. isKnowKey = TRUE;
  15142. }
  15143. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15144. {
  15145. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15147. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15148. {
  15149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15150. }
  15151. else
  15152. {
  15153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15154. }
  15155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15156. isKnowKey = TRUE;
  15157. }
  15158. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15159. {
  15160. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15162. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15163. {
  15164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15165. }
  15166. else
  15167. {
  15168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15169. }
  15170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15171. isKnowKey = TRUE;
  15172. }
  15173. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15174. {
  15175. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15177. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15178. {
  15179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15180. }
  15181. else
  15182. {
  15183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15184. }
  15185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15186. isKnowKey = TRUE;
  15187. }
  15188. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15189. {
  15190. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15192. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15193. {
  15194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15195. }
  15196. else
  15197. {
  15198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15199. }
  15200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15201. isKnowKey = TRUE;
  15202. }
  15203. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15204. {
  15205. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15207. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15208. {
  15209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15210. }
  15211. else
  15212. {
  15213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15214. }
  15215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15216. isKnowKey = TRUE;
  15217. }
  15218. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15219. {
  15220. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15222. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15223. {
  15224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15225. }
  15226. else
  15227. {
  15228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15229. }
  15230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15231. isKnowKey = TRUE;
  15232. }
  15233. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15234. {
  15235. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15237. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15238. {
  15239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15240. }
  15241. else
  15242. {
  15243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15244. }
  15245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15246. isKnowKey = TRUE;
  15247. }
  15248. /*
  15249. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15250. {
  15251. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15253. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15254. {
  15255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15256. }
  15257. else
  15258. {
  15259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15260. }
  15261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15262. isKnowKey = TRUE;
  15263. }*/
  15264. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15265. {
  15266. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15268. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15269. {
  15270. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15271. }
  15272. else
  15273. {
  15274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15275. }
  15276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15277. isKnowKey = TRUE;
  15278. }
  15279. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15280. {
  15281. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15283. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15284. {
  15285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15286. }
  15287. else
  15288. {
  15289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15290. }
  15291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15292. isKnowKey = TRUE;
  15293. }
  15294. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15295. {
  15296. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15298. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15299. {
  15300. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15301. }
  15302. else
  15303. {
  15304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15305. }
  15306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15307. isKnowKey = TRUE;
  15308. }
  15309. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15310. {
  15311. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15313. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15314. {
  15315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15316. }
  15317. else
  15318. {
  15319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15320. }
  15321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15322. isKnowKey = TRUE;
  15323. }
  15324. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  15325. {
  15326. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  15327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  15328. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15329. {
  15330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  15331. }
  15332. else
  15333. {
  15334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  15335. }
  15336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  15337. isKnowKey = TRUE;
  15338. }
  15339. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  15340. {
  15341. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  15342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  15343. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15344. {
  15345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  15346. }
  15347. else
  15348. {
  15349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  15350. }
  15351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  15352. isKnowKey = TRUE;
  15353. }
  15354. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  15355. {
  15356. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  15357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  15358. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15359. {
  15360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  15361. }
  15362. else
  15363. {
  15364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  15365. }
  15366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  15367. isKnowKey = TRUE;
  15368. }
  15369. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15370. {
  15371. struct sysinfo s_info;
  15372. int error = sysinfo(&s_info);
  15373. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15375. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15376. {
  15377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15378. }
  15379. else
  15380. {
  15381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15382. }
  15383. if(error != 0)
  15384. {
  15385. DEBUG_WARN("System uptime get error: %d\n", error);
  15386. }
  15387. else
  15388. {
  15389. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15390. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15391. }
  15392. isKnowKey = TRUE;
  15393. }
  15394. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15395. {
  15396. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15398. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15399. {
  15400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15401. }
  15402. else
  15403. {
  15404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15405. }
  15406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  15407. isKnowKey = TRUE;
  15408. }
  15409. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15410. {
  15411. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15413. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15414. {
  15415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15416. }
  15417. else
  15418. {
  15419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15420. }
  15421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15422. isKnowKey = TRUE;
  15423. }
  15424. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15425. {
  15426. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15428. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15429. {
  15430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15431. }
  15432. else
  15433. {
  15434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15435. }
  15436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15437. isKnowKey = TRUE;
  15438. }
  15439. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15440. {
  15441. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15443. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15444. {
  15445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15446. }
  15447. else
  15448. {
  15449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15450. }
  15451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15452. isKnowKey = TRUE;
  15453. }
  15454. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15455. {
  15456. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15458. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15459. {
  15460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15461. }
  15462. else
  15463. {
  15464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15465. }
  15466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15467. isKnowKey = TRUE;
  15468. }
  15469. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15470. {
  15471. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15473. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15474. {
  15475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15476. }
  15477. else
  15478. {
  15479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15480. }
  15481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15482. isKnowKey = TRUE;
  15483. }
  15484. #if 1
  15485. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15486. {
  15487. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15489. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15490. {
  15491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15492. }
  15493. else
  15494. {
  15495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15496. }
  15497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15498. isKnowKey = TRUE;
  15499. }
  15500. #endif
  15501. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15502. {
  15503. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15505. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15506. {
  15507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15508. }
  15509. else
  15510. {
  15511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15512. }
  15513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15514. isKnowKey = TRUE;
  15515. }
  15516. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15517. {
  15518. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15520. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15521. {
  15522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15523. }
  15524. else
  15525. {
  15526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15527. }
  15528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15529. isKnowKey = TRUE;
  15530. }
  15531. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15532. {
  15533. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15535. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15536. {
  15537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15538. }
  15539. else
  15540. {
  15541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15542. }
  15543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15544. isKnowKey = TRUE;
  15545. }
  15546. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15547. {
  15548. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15550. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15551. {
  15552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15553. }
  15554. else
  15555. {
  15556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15557. }
  15558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15559. isKnowKey = TRUE;
  15560. }
  15561. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15562. {
  15563. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15565. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15566. {
  15567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15568. }
  15569. else
  15570. {
  15571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15572. }
  15573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15574. isKnowKey = TRUE;
  15575. }
  15576. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15577. {
  15578. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15580. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15581. {
  15582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15583. }
  15584. else
  15585. {
  15586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15587. }
  15588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15589. isKnowKey = TRUE;
  15590. }
  15591. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15592. {
  15593. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15595. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15596. {
  15597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15598. }
  15599. else
  15600. {
  15601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15602. }
  15603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15604. isKnowKey = TRUE;
  15605. }
  15606. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15607. {
  15608. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15610. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15611. {
  15612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15613. }
  15614. else
  15615. {
  15616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15617. }
  15618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15619. isKnowKey = TRUE;
  15620. }
  15621. //=========================================================
  15622. if(!isEmpty && !isKnowKey)
  15623. {
  15624. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15625. strcpy(unknownkey[UnknownKeynum], keyReq);
  15626. UnknownKeynum = UnknownKeynum + 1;
  15627. }
  15628. }
  15629. void processUnkownKey(void)
  15630. {
  15631. DEBUG_INFO("processUnkownKey...\n");
  15632. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15633. for(int index=0; index < UnknownKeynum; index++)
  15634. {
  15635. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15636. {
  15637. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15638. }
  15639. }
  15640. }
  15641. int setKeyValue(char *key, char *value)
  15642. {
  15643. int isSuccess = NotSupported;
  15644. int check_ascii=0;
  15645. char str[501]={0};
  15646. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15647. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15648. {
  15649. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15650. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15651. {
  15652. strcpy(str, (const char*)value);
  15653. for(int i = 0; str[i]; i++){
  15654. str[i] = tolower(str[i]);
  15655. }
  15656. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15657. isSuccess = ConfigurationStatus_Accepted;
  15658. }
  15659. else
  15660. {
  15661. isSuccess = ConfigurationStatus_Rejected;
  15662. }
  15663. }
  15664. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15665. {
  15666. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15667. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15668. {
  15669. strcpy(str, (const char*)value);
  15670. for(int i = 0; str[i]; i++){
  15671. str[i] = tolower(str[i]);
  15672. }
  15673. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15674. isSuccess = ConfigurationStatus_Accepted;
  15675. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  15676. }
  15677. else
  15678. {
  15679. isSuccess = ConfigurationStatus_Rejected;
  15680. }
  15681. }
  15682. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15683. {
  15684. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15685. {
  15686. strcpy(str, (const char*)value);
  15687. for(int i = 0; str[i]; i++)
  15688. {
  15689. str[i] = tolower(str[i]);
  15690. }
  15691. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15692. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15693. isSuccess = ConfigurationStatus_Accepted;
  15694. }
  15695. else
  15696. {
  15697. isSuccess = ConfigurationStatus_Rejected;
  15698. }
  15699. }
  15700. if(strcmp(key, "BlinkRepeat") == 0)
  15701. {
  15702. //Charger.BlinkRepeat = Integer.parseInt(value);
  15703. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15704. {
  15705. check_ascii = value[0];
  15706. if( (check_ascii < 48) || (check_ascii > 57) )
  15707. {
  15708. isSuccess = ConfigurationStatus_Rejected;
  15709. }
  15710. else
  15711. {
  15712. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15713. isSuccess = ConfigurationStatus_Accepted;
  15714. }
  15715. }
  15716. else
  15717. {
  15718. isSuccess = ConfigurationStatus_Rejected;
  15719. }
  15720. }
  15721. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15722. {
  15723. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15724. {
  15725. check_ascii = value[0];
  15726. if( (check_ascii < 48) || (check_ascii > 57) )
  15727. {
  15728. isSuccess = ConfigurationStatus_Rejected;
  15729. }
  15730. else
  15731. {
  15732. if((atoi(value) == 0) || (atoi(value) >= 5))
  15733. {
  15734. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15735. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15736. isSuccess = ConfigurationStatus_Accepted;
  15737. }
  15738. else
  15739. isSuccess = ConfigurationStatus_Rejected;
  15740. }
  15741. }
  15742. else
  15743. {
  15744. isSuccess = ConfigurationStatus_Rejected;
  15745. }
  15746. }
  15747. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15748. {
  15749. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15750. {
  15751. check_ascii = value[0];
  15752. if( (check_ascii < 48) || (check_ascii > 57) )
  15753. {
  15754. isSuccess = ConfigurationStatus_Rejected;
  15755. }
  15756. else
  15757. {
  15758. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15759. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15760. isSuccess = ConfigurationStatus_Accepted;
  15761. }
  15762. }
  15763. else
  15764. {
  15765. isSuccess = ConfigurationStatus_Rejected;
  15766. }
  15767. }
  15768. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15769. {
  15770. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15771. {
  15772. check_ascii = value[0];
  15773. if( (check_ascii < 48) || (check_ascii > 57) )
  15774. {
  15775. isSuccess = ConfigurationStatus_Rejected;
  15776. }
  15777. else
  15778. {
  15779. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15780. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15781. isSuccess = ConfigurationStatus_Accepted;
  15782. }
  15783. }
  15784. else
  15785. {
  15786. isSuccess = ConfigurationStatus_Rejected;
  15787. }
  15788. }
  15789. if(strcmp(key, "HeartbeatInterval") == 0)
  15790. {
  15791. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15792. {
  15793. check_ascii = value[0];
  15794. if( (check_ascii < 48) || (check_ascii > 57) )
  15795. {
  15796. isSuccess = ConfigurationStatus_Rejected;
  15797. }
  15798. else
  15799. {
  15800. if((atoi(value) == 0) || (atoi(value) >= 10))
  15801. {
  15802. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15803. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15804. HeartBeatWaitTime = atoi(value);
  15805. isSuccess = ConfigurationStatus_Accepted;
  15806. }
  15807. else
  15808. {
  15809. isSuccess = ConfigurationStatus_Rejected;
  15810. }
  15811. }
  15812. }
  15813. else
  15814. {
  15815. isSuccess = ConfigurationStatus_Rejected;
  15816. }
  15817. }
  15818. if(strcmp(key, "LightIntensity") == 0)
  15819. {
  15820. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15821. {
  15822. check_ascii = value[0];
  15823. if( (check_ascii < 48) || (check_ascii > 57) )
  15824. {
  15825. isSuccess = ConfigurationStatus_Rejected;
  15826. }
  15827. else
  15828. {
  15829. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15830. isSuccess = ConfigurationStatus_Accepted;
  15831. }
  15832. }
  15833. else
  15834. {
  15835. isSuccess = ConfigurationStatus_Rejected;
  15836. }
  15837. }
  15838. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15839. {
  15840. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15841. {
  15842. strcpy(str, (const char*)value);
  15843. for(int i = 0; str[i]; i++)
  15844. {
  15845. str[i] = tolower(str[i]);
  15846. }
  15847. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15848. isSuccess = ConfigurationStatus_Accepted;
  15849. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15850. }
  15851. else
  15852. {
  15853. isSuccess = ConfigurationStatus_Rejected;
  15854. }
  15855. }
  15856. if(strcmp(key, "LocalPreAuthorize") == 0)
  15857. {
  15858. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15859. {
  15860. strcpy(str, (const char*)value);
  15861. for(int i = 0; str[i]; i++)
  15862. {
  15863. str[i] = tolower(str[i]);
  15864. }
  15865. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15866. isSuccess = ConfigurationStatus_Accepted;
  15867. }
  15868. else
  15869. {
  15870. isSuccess = ConfigurationStatus_Rejected;
  15871. }
  15872. }
  15873. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15874. {
  15875. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15876. {
  15877. check_ascii = value[0];
  15878. if( (check_ascii < 48) || (check_ascii > 57) )
  15879. {
  15880. isSuccess = ConfigurationStatus_Rejected;
  15881. }
  15882. else
  15883. {
  15884. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15885. isSuccess = ConfigurationStatus_Accepted;
  15886. }
  15887. }
  15888. else
  15889. {
  15890. isSuccess = ConfigurationStatus_Rejected;
  15891. }
  15892. }
  15893. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15894. {
  15895. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15896. {
  15897. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15898. isSuccess = ConfigurationStatus_Accepted;
  15899. }
  15900. else
  15901. {
  15902. isSuccess = ConfigurationStatus_Rejected;
  15903. }
  15904. }
  15905. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15906. {
  15907. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15908. {
  15909. check_ascii = value[0];
  15910. if( (check_ascii < 48) || (check_ascii > 57) )
  15911. {
  15912. isSuccess = ConfigurationStatus_Rejected;
  15913. }
  15914. else
  15915. {
  15916. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15917. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15918. isSuccess = ConfigurationStatus_Accepted;
  15919. }
  15920. }
  15921. else
  15922. {
  15923. isSuccess = ConfigurationStatus_Rejected;
  15924. }
  15925. }
  15926. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15927. {
  15928. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15929. {
  15930. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15931. isSuccess = ConfigurationStatus_Accepted;
  15932. }
  15933. else
  15934. {
  15935. isSuccess = ConfigurationStatus_Rejected;
  15936. }
  15937. }
  15938. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15939. {
  15940. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15941. {
  15942. check_ascii = value[0];
  15943. if( (check_ascii < 48) || (check_ascii > 57) )
  15944. {
  15945. isSuccess = ConfigurationStatus_Rejected;
  15946. }
  15947. else
  15948. {
  15949. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15950. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15951. isSuccess = ConfigurationStatus_Accepted;
  15952. }
  15953. }
  15954. else
  15955. {
  15956. isSuccess = ConfigurationStatus_Rejected;
  15957. }
  15958. }
  15959. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15960. {
  15961. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15962. {
  15963. check_ascii = value[0];
  15964. if( (check_ascii < 48) || (check_ascii > 57) )
  15965. {
  15966. isSuccess = ConfigurationStatus_Rejected;
  15967. }
  15968. else
  15969. {
  15970. if((atoi(value) == 0) || (atoi(value) >= 3))
  15971. {
  15972. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15973. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15974. isSuccess = ConfigurationStatus_Accepted;
  15975. }
  15976. else
  15977. {
  15978. isSuccess = ConfigurationStatus_Rejected;
  15979. }
  15980. }
  15981. }
  15982. else
  15983. {
  15984. isSuccess = ConfigurationStatus_Rejected;
  15985. }
  15986. }
  15987. if(strcmp(key, "MinimumStatusDuration") == 0)
  15988. {
  15989. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15990. {
  15991. check_ascii = value[0];
  15992. if( (check_ascii < 48) || (check_ascii > 57) )
  15993. {
  15994. isSuccess = ConfigurationStatus_Rejected;
  15995. }
  15996. else
  15997. {
  15998. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15999. {
  16000. isSuccess = ConfigurationStatus_Rejected;
  16001. }
  16002. else
  16003. {
  16004. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16005. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16006. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16007. isSuccess = ConfigurationStatus_Accepted;
  16008. }
  16009. }
  16010. }
  16011. else
  16012. {
  16013. isSuccess = ConfigurationStatus_Rejected;
  16014. }
  16015. }
  16016. if(strcmp(key, "NumberOfConnectors") == 0)
  16017. {
  16018. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16019. {
  16020. check_ascii = value[0];
  16021. if( (check_ascii < 48) || (check_ascii > 57) )
  16022. {
  16023. isSuccess = ConfigurationStatus_Rejected;
  16024. }
  16025. else
  16026. {
  16027. //Charger.ResetRetries = Integer.parseInt(value);
  16028. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16029. isSuccess = ConfigurationStatus_Accepted;
  16030. }
  16031. }
  16032. else
  16033. {
  16034. isSuccess = ConfigurationStatus_Rejected;
  16035. }
  16036. }
  16037. if(strcmp(key, "ResetRetries") == 0)
  16038. {
  16039. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16040. {
  16041. check_ascii = value[0];
  16042. if( (check_ascii < 48) || (check_ascii > 57) )
  16043. {
  16044. isSuccess = ConfigurationStatus_Rejected;
  16045. }
  16046. else
  16047. {
  16048. //Charger.ResetRetries = Integer.parseInt(value);
  16049. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16050. isSuccess = ConfigurationStatus_Accepted;
  16051. }
  16052. }
  16053. else
  16054. {
  16055. isSuccess = ConfigurationStatus_Rejected;
  16056. }
  16057. }
  16058. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16059. {
  16060. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16061. {
  16062. strcpy(str, (const char*)value);
  16063. for(int i = 0; str[i]; i++)
  16064. {
  16065. str[i] = tolower(str[i]);
  16066. }
  16067. if(strcmp(str, "notapplicable")== 0)
  16068. {
  16069. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16070. isSuccess = ConfigurationStatus_Accepted;
  16071. }
  16072. else if(strcmp(str, "unknown")== 0)
  16073. {
  16074. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16075. isSuccess = ConfigurationStatus_Accepted;
  16076. }
  16077. else if(strcmp(str, "rst")== 0)
  16078. {
  16079. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16080. isSuccess = ConfigurationStatus_Accepted;
  16081. }
  16082. else if(strcmp(str, "rts")== 0)
  16083. {
  16084. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16085. isSuccess = ConfigurationStatus_Accepted;
  16086. }
  16087. else if(strcmp(str, "srt")== 0)
  16088. {
  16089. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16090. isSuccess = ConfigurationStatus_Accepted;
  16091. }
  16092. else if(strcmp(str, "str")== 0)
  16093. {
  16094. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16095. isSuccess = ConfigurationStatus_Accepted;
  16096. }
  16097. else if(strcmp(str, "trs")== 0)
  16098. {
  16099. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16100. isSuccess = ConfigurationStatus_Accepted;
  16101. }
  16102. else if(strcmp(str, "tsr")== 0)
  16103. {
  16104. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16105. isSuccess = ConfigurationStatus_Accepted;
  16106. }
  16107. else
  16108. {
  16109. isSuccess = ConfigurationStatus_Rejected;
  16110. }
  16111. }
  16112. else
  16113. {
  16114. isSuccess = ConfigurationStatus_Rejected;
  16115. }
  16116. }
  16117. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16118. {
  16119. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16120. {
  16121. check_ascii = value[0];
  16122. if( (check_ascii < 48) || (check_ascii > 57) )
  16123. {
  16124. isSuccess = ConfigurationStatus_Rejected;
  16125. }
  16126. else
  16127. {
  16128. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16129. isSuccess = ConfigurationStatus_Accepted;
  16130. }
  16131. }
  16132. else
  16133. {
  16134. isSuccess = ConfigurationStatus_Rejected;
  16135. }
  16136. }
  16137. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16138. {
  16139. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16140. {
  16141. strcpy(str, (const char*)value);
  16142. for(int i = 0; str[i]; i++)
  16143. {
  16144. str[i] = tolower(str[i]);
  16145. }
  16146. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16147. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16148. isSuccess = ConfigurationStatus_Accepted;
  16149. }
  16150. else
  16151. {
  16152. isSuccess = ConfigurationStatus_Rejected;
  16153. }
  16154. }
  16155. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16156. {
  16157. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16158. {
  16159. strcpy(str, (const char*)value);
  16160. for(int i = 0; str[i]; i++)
  16161. {
  16162. str[i] = tolower(str[i]);
  16163. }
  16164. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16165. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16166. isSuccess = ConfigurationStatus_Accepted;
  16167. }
  16168. else
  16169. {
  16170. isSuccess = ConfigurationStatus_Rejected;
  16171. }
  16172. }
  16173. if(strcmp(key, "StopTxnAlignedData") == 0)
  16174. {
  16175. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16176. {
  16177. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16178. isSuccess = ConfigurationStatus_Accepted;
  16179. }
  16180. else
  16181. {
  16182. isSuccess = ConfigurationStatus_Rejected;
  16183. }
  16184. }
  16185. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16186. {
  16187. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16188. {
  16189. check_ascii = value[0];
  16190. if( (check_ascii < 48) || (check_ascii > 57) )
  16191. {
  16192. isSuccess = ConfigurationStatus_Rejected;
  16193. }
  16194. else
  16195. {
  16196. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16197. isSuccess = ConfigurationStatus_Accepted;
  16198. }
  16199. }
  16200. else
  16201. {
  16202. isSuccess = ConfigurationStatus_Rejected;
  16203. }
  16204. }
  16205. if(strcmp(key, "StopTxnSampledData") == 0)
  16206. {
  16207. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16208. {
  16209. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16210. isSuccess = ConfigurationStatus_Accepted;
  16211. }
  16212. else
  16213. {
  16214. isSuccess = ConfigurationStatus_Rejected;
  16215. }
  16216. }
  16217. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16218. {
  16219. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16220. {
  16221. check_ascii = value[0];
  16222. if( (check_ascii < 48) || (check_ascii > 57) )
  16223. {
  16224. isSuccess = ConfigurationStatus_Rejected;
  16225. }
  16226. else
  16227. {
  16228. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16229. isSuccess = ConfigurationStatus_Accepted;
  16230. }
  16231. }
  16232. else
  16233. {
  16234. isSuccess = ConfigurationStatus_Rejected;
  16235. }
  16236. }
  16237. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16238. {
  16239. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16240. {
  16241. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16242. isSuccess = ConfigurationStatus_Accepted;
  16243. }
  16244. else
  16245. {
  16246. isSuccess = ConfigurationStatus_Rejected;
  16247. }
  16248. }
  16249. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16250. {
  16251. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16252. {
  16253. check_ascii = value[0];
  16254. if( (check_ascii < 48) || (check_ascii > 57) )
  16255. {
  16256. isSuccess = ConfigurationStatus_Rejected;
  16257. }
  16258. else
  16259. {
  16260. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16261. isSuccess = ConfigurationStatus_Accepted;
  16262. }
  16263. }
  16264. else
  16265. {
  16266. isSuccess = ConfigurationStatus_Rejected;
  16267. }
  16268. }
  16269. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16270. {
  16271. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16272. {
  16273. check_ascii = value[0];
  16274. if( (check_ascii < 48) || (check_ascii > 57) )
  16275. {
  16276. isSuccess = ConfigurationStatus_Rejected;
  16277. }
  16278. else
  16279. {
  16280. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16281. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16282. TransactionMessageAttemptsValue = atoi(value);
  16283. isSuccess = ConfigurationStatus_Accepted;
  16284. }
  16285. }
  16286. else
  16287. {
  16288. isSuccess = ConfigurationStatus_Rejected;
  16289. }
  16290. }
  16291. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16292. {
  16293. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16294. {
  16295. check_ascii = value[0];
  16296. if( (check_ascii < 48) || (check_ascii > 57) )
  16297. {
  16298. isSuccess = ConfigurationStatus_Rejected;
  16299. }
  16300. else
  16301. {
  16302. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16303. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16304. TransactionMessageRetryIntervalValue = atoi(value);
  16305. isSuccess = ConfigurationStatus_Accepted;
  16306. }
  16307. }
  16308. else
  16309. {
  16310. isSuccess = ConfigurationStatus_Rejected;
  16311. }
  16312. }
  16313. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16314. {
  16315. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16316. {
  16317. strcpy(str, (const char*)value);
  16318. for(int i = 0; str[i]; i++)
  16319. {
  16320. str[i] = tolower(str[i]);
  16321. }
  16322. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16323. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16324. isSuccess = ConfigurationStatus_Accepted;
  16325. }
  16326. else
  16327. {
  16328. isSuccess = ConfigurationStatus_Rejected;
  16329. }
  16330. }
  16331. if(strcmp(key, "WebSocketPingInterval") == 0)
  16332. {
  16333. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16334. {
  16335. check_ascii = value[0];
  16336. if( (check_ascii < 48) || (check_ascii > 57) )
  16337. {
  16338. isSuccess = ConfigurationStatus_Rejected;
  16339. }
  16340. else
  16341. {
  16342. if((atoi(value) == 0) || (atoi(value) >= 10))
  16343. {
  16344. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16345. isSuccess = ConfigurationStatus_Accepted;
  16346. }
  16347. else
  16348. isSuccess = ConfigurationStatus_Rejected;
  16349. }
  16350. }
  16351. else
  16352. {
  16353. isSuccess = ConfigurationStatus_Rejected;
  16354. }
  16355. }
  16356. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16357. {
  16358. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16359. {
  16360. strcpy(str, (const char*)value);
  16361. for(int i = 0; str[i]; i++)
  16362. {
  16363. str[i] = tolower(str[i]);
  16364. }
  16365. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16366. isSuccess = ConfigurationStatus_Accepted;
  16367. }
  16368. else
  16369. {
  16370. isSuccess = ConfigurationStatus_Rejected;
  16371. }
  16372. }
  16373. if(strcmp(key, "AuthorizationKey") == 0)
  16374. {
  16375. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16376. {
  16377. strcpy(str, (const char*)value);
  16378. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16379. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16380. isSuccess = ConfigurationStatus_Accepted;
  16381. }
  16382. else
  16383. {
  16384. isSuccess = ConfigurationStatus_Rejected;
  16385. }
  16386. }
  16387. if(strcmp(key, "SecurityProfile") == 0)
  16388. {
  16389. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16390. {
  16391. check_ascii = value[0];
  16392. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16393. {
  16394. isSuccess = ConfigurationStatus_Rejected;
  16395. }
  16396. else if(check_ascii == 0x33)
  16397. {
  16398. isSuccess = NotSupported;
  16399. }
  16400. else
  16401. {
  16402. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16403. {
  16404. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16405. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  16406. isSuccess = ConfigurationStatus_Accepted;
  16407. }
  16408. else
  16409. isSuccess = ConfigurationStatus_Rejected;
  16410. }
  16411. }
  16412. else
  16413. {
  16414. isSuccess = ConfigurationStatus_Rejected;
  16415. }
  16416. }
  16417. if(strcmp(key, "DefaultPrice") == 0)
  16418. {
  16419. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16420. {
  16421. strcpy(str, (const char*)value);
  16422. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16423. isSuccess = ConfigurationStatus_Accepted;
  16424. }
  16425. else
  16426. {
  16427. isSuccess = ConfigurationStatus_Rejected;
  16428. }
  16429. }
  16430. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16431. {
  16432. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16433. {
  16434. strcpy(str, (const char*)value);
  16435. for(int i = 0; str[i]; i++)
  16436. {
  16437. str[i] = tolower(str[i]);
  16438. }
  16439. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16440. isSuccess = ConfigurationStatus_Accepted;
  16441. }
  16442. else
  16443. {
  16444. isSuccess = ConfigurationStatus_Rejected;
  16445. }
  16446. }
  16447. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16448. {
  16449. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16450. {
  16451. strcpy(str, (const char*)value);
  16452. for(int i = 0; str[i]; i++)
  16453. {
  16454. str[i] = tolower(str[i]);
  16455. }
  16456. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16457. isSuccess = ConfigurationStatus_Accepted;
  16458. }
  16459. else
  16460. {
  16461. isSuccess = ConfigurationStatus_Rejected;
  16462. }
  16463. }
  16464. if(strcmp(key, "TimeOffset") == 0)
  16465. {
  16466. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16467. {
  16468. strcpy(str, (const char*)value);
  16469. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  16470. isSuccess = ConfigurationStatus_Accepted;
  16471. }
  16472. else
  16473. {
  16474. isSuccess = ConfigurationStatus_Rejected;
  16475. }
  16476. }
  16477. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  16478. {
  16479. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  16480. {
  16481. strcpy(str, (const char*)value);
  16482. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  16483. isSuccess = ConfigurationStatus_Accepted;
  16484. }
  16485. else
  16486. {
  16487. isSuccess = ConfigurationStatus_Rejected;
  16488. }
  16489. }
  16490. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  16491. {
  16492. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  16493. {
  16494. strcpy(str, (const char*)value);
  16495. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  16496. isSuccess = ConfigurationStatus_Accepted;
  16497. }
  16498. else
  16499. {
  16500. isSuccess = ConfigurationStatus_Rejected;
  16501. }
  16502. }
  16503. if(strcmp(key, "SystemUptimeSec") == 0)
  16504. {
  16505. isSuccess = NotSupported;
  16506. }
  16507. if(strcmp(key, "FreeVend") == 0)
  16508. {
  16509. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16510. {
  16511. strcpy(str, (const char*)value);
  16512. for(int i = 0; str[i]; i++)
  16513. {
  16514. str[i] = tolower(str[i]);
  16515. }
  16516. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16517. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16518. isSuccess = ConfigurationStatus_Accepted;
  16519. }
  16520. else
  16521. {
  16522. isSuccess = ConfigurationStatus_Rejected;
  16523. }
  16524. }
  16525. if(strcmp(key, "OcppServer") == 0)
  16526. {
  16527. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16528. {
  16529. strcpy(str, (const char*)value);
  16530. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16531. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16532. isSuccess = ConfigurationStatus_Accepted;
  16533. }
  16534. else
  16535. {
  16536. isSuccess = ConfigurationStatus_Rejected;
  16537. }
  16538. }
  16539. if(strcmp(key, "MaintainServer") == 0)
  16540. {
  16541. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16542. {
  16543. strcpy(str, (const char*)value);
  16544. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16545. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16546. isSuccess = ConfigurationStatus_Accepted;
  16547. }
  16548. else
  16549. {
  16550. isSuccess = ConfigurationStatus_Rejected;
  16551. }
  16552. }
  16553. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16554. {
  16555. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16556. {
  16557. strcpy(str, (const char*)value);
  16558. for(int i = 0; str[i]; i++)
  16559. {
  16560. str[i] = tolower(str[i]);
  16561. }
  16562. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16563. isSuccess = ConfigurationStatus_Accepted;
  16564. }
  16565. else
  16566. {
  16567. isSuccess = ConfigurationStatus_Rejected;
  16568. }
  16569. }
  16570. if(strcmp(key, "StatusNotificationInterval") == 0)
  16571. {
  16572. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16573. {
  16574. check_ascii = value[0];
  16575. if( (check_ascii < 48) || (check_ascii > 57) )
  16576. {
  16577. isSuccess = ConfigurationStatus_Rejected;
  16578. }
  16579. else
  16580. {
  16581. if((atoi(value) == 0) || (atoi(value) >= 10))
  16582. {
  16583. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16584. isSuccess = ConfigurationStatus_Accepted;
  16585. }
  16586. else
  16587. isSuccess = ConfigurationStatus_Rejected;
  16588. }
  16589. }
  16590. else
  16591. {
  16592. isSuccess = ConfigurationStatus_Rejected;
  16593. }
  16594. }
  16595. #if 0
  16596. //For OCPP Test Case
  16597. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16598. {
  16599. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16600. {
  16601. strcpy(str, (const char*)value);
  16602. for(int i = 0; str[i]; i++)
  16603. {
  16604. str[i] = tolower(str[i]);
  16605. }
  16606. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16607. isSuccess = ConfigurationStatus_Accepted;
  16608. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16609. }
  16610. else
  16611. {
  16612. isSuccess = ConfigurationStatus_Rejected;
  16613. }
  16614. }
  16615. #endif
  16616. #if 1
  16617. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16618. {
  16619. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16620. {
  16621. strcpy(str, (const char*)value);
  16622. for(int i = 0; str[i]; i++)
  16623. {
  16624. str[i] = tolower(str[i]);
  16625. }
  16626. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16627. isSuccess = ConfigurationStatus_Accepted;
  16628. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16629. }
  16630. else
  16631. {
  16632. isSuccess = ConfigurationStatus_Rejected;
  16633. }
  16634. }
  16635. #endif
  16636. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16637. {
  16638. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16639. {
  16640. check_ascii = value[0];
  16641. if( (check_ascii < 48) || (check_ascii > 57) )
  16642. {
  16643. isSuccess = ConfigurationStatus_Rejected;
  16644. }
  16645. else
  16646. {
  16647. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16648. isSuccess = ConfigurationStatus_Accepted;
  16649. }
  16650. }
  16651. else
  16652. {
  16653. isSuccess = ConfigurationStatus_Rejected;
  16654. }
  16655. }
  16656. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16657. {
  16658. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16659. {
  16660. check_ascii = value[0];
  16661. if( (check_ascii < 48) || (check_ascii > 57) )
  16662. {
  16663. isSuccess = ConfigurationStatus_Rejected;
  16664. }
  16665. else
  16666. {
  16667. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16668. isSuccess = ConfigurationStatus_Accepted;
  16669. }
  16670. }
  16671. else
  16672. {
  16673. isSuccess = ConfigurationStatus_Rejected;
  16674. }
  16675. }
  16676. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16677. {
  16678. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16679. {
  16680. strcpy(str, (const char*)value);
  16681. for(int i = 0; str[i]; i++)
  16682. {
  16683. str[i] = tolower(str[i]);
  16684. }
  16685. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16686. isSuccess = ConfigurationStatus_Accepted;
  16687. }
  16688. else
  16689. {
  16690. isSuccess = ConfigurationStatus_Rejected;
  16691. }
  16692. }
  16693. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16694. {
  16695. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16696. {
  16697. check_ascii = value[0];
  16698. if( (check_ascii < 48) || (check_ascii > 57) )
  16699. {
  16700. isSuccess = ConfigurationStatus_Rejected;
  16701. }
  16702. else
  16703. {
  16704. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16705. isSuccess = ConfigurationStatus_Accepted;
  16706. }
  16707. }
  16708. else
  16709. {
  16710. isSuccess = ConfigurationStatus_Rejected;
  16711. }
  16712. }
  16713. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16714. {
  16715. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16716. {
  16717. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16718. isSuccess = ConfigurationStatus_Accepted;
  16719. }
  16720. else
  16721. {
  16722. isSuccess = ConfigurationStatus_Rejected;
  16723. }
  16724. }
  16725. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16726. {
  16727. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16728. {
  16729. check_ascii = value[0];
  16730. if( (check_ascii < 48) || (check_ascii > 57) )
  16731. {
  16732. isSuccess = ConfigurationStatus_Rejected;
  16733. }
  16734. else
  16735. {
  16736. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16737. isSuccess = ConfigurationStatus_Accepted;
  16738. }
  16739. }
  16740. else
  16741. {
  16742. isSuccess = ConfigurationStatus_Rejected;
  16743. }
  16744. }
  16745. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16746. {
  16747. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16748. {
  16749. strcpy(str, (const char*)value);
  16750. for(int i = 0; str[i]; i++)
  16751. {
  16752. str[i] = tolower(str[i]);
  16753. }
  16754. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16755. isSuccess = ConfigurationStatus_Accepted;
  16756. }
  16757. else
  16758. {
  16759. isSuccess = ConfigurationStatus_Rejected;
  16760. }
  16761. }
  16762. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16763. {
  16764. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16765. {
  16766. check_ascii = value[0];
  16767. if( (check_ascii < 48) || (check_ascii > 57) )
  16768. {
  16769. isSuccess = ConfigurationStatus_Rejected;
  16770. }
  16771. else
  16772. {
  16773. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16774. isSuccess = ConfigurationStatus_Accepted;
  16775. }
  16776. }
  16777. else
  16778. {
  16779. isSuccess = ConfigurationStatus_Rejected;
  16780. }
  16781. }
  16782. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16783. return isSuccess;
  16784. }
  16785. int TransactionMessageAttemptsGet(void)
  16786. {
  16787. return TransactionMessageAttemptsValue;
  16788. }
  16789. int FirstHeartBeatResponse(void)
  16790. {
  16791. return FirstHeartBeat;
  16792. }
  16793. int TransactionMessageRetryIntervalGet(void)
  16794. {
  16795. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16796. }
  16797. int ReadHttpStatus(int sock)
  16798. {
  16799. //char c;
  16800. char buff[1024]="",*ptr=buff+1;
  16801. int bytes_received, status;
  16802. DEBUG_INFO("Begin Response ..\n");
  16803. while((bytes_received = recv(sock, ptr, 1, 0))){
  16804. if(bytes_received==-1){
  16805. perror("ReadHttpStatus");
  16806. exit(1);
  16807. }
  16808. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16809. ptr++;
  16810. }
  16811. *ptr=0;
  16812. ptr=buff+1;
  16813. sscanf(ptr,"%*s %d ", &status);
  16814. DEBUG_INFO("%s\n",ptr);
  16815. DEBUG_INFO("status=%d\n",status);
  16816. DEBUG_INFO("End Response ..\n");
  16817. return (bytes_received>0)?status:0;
  16818. }
  16819. //the only filed that it parsed is 'Content-Length'
  16820. int ParseHeader(int sock)
  16821. {
  16822. //char c;
  16823. char buff[1024]="",*ptr=buff+4;
  16824. int bytes_received;
  16825. DEBUG_INFO("Begin HEADER ..\n");
  16826. while((bytes_received = recv(sock, ptr, 1, 0))){
  16827. if(bytes_received==-1){
  16828. perror("Parse Header");
  16829. exit(1);
  16830. }
  16831. if(
  16832. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16833. (ptr[-1]=='\r') && (*ptr=='\n' )
  16834. ) break;
  16835. ptr++;
  16836. }
  16837. *ptr=0;
  16838. ptr=buff+4;
  16839. //printf("%s",ptr);
  16840. if(bytes_received){
  16841. ptr=strstr(ptr,"Content-Length:");
  16842. if(ptr){
  16843. sscanf(ptr,"%*s %d",&bytes_received);
  16844. }else
  16845. bytes_received=-1; //unknown size
  16846. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16847. }
  16848. DEBUG_INFO("End HEADER ..\n");
  16849. return bytes_received ;
  16850. }
  16851. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16852. {
  16853. int result = TRUE;
  16854. char rmFileCmd[100]={0};
  16855. char FilePath[100]={0};
  16856. char ftpbuf[200];
  16857. int systemresult;
  16858. sprintf(FilePath,"/mnt/%s",filename);
  16859. system("ping 8.8.8.8 &");
  16860. if((access(FilePath,F_OK))!=-1)
  16861. {
  16862. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16863. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16864. system(rmFileCmd);
  16865. }
  16866. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16867. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16868. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16869. systemresult = system(ftpbuf);
  16870. if(systemresult != 0)
  16871. {
  16872. DEBUG_INFO("http DownLoad error!\n");
  16873. result = FALSE;
  16874. }
  16875. system("pkill ping");
  16876. return result;
  16877. }
  16878. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16879. {
  16880. int result = TRUE;
  16881. char rmFileCmd[100]={0};
  16882. char FilePath[100]={0};
  16883. char ftpbuf[200];
  16884. int systemresult;
  16885. sprintf(FilePath,"/mnt/%s",filename);
  16886. system("ping 8.8.8.8 &");
  16887. if((access(FilePath,F_OK))!=-1)
  16888. {
  16889. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16890. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16891. system(rmFileCmd);
  16892. }
  16893. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16894. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16895. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16896. systemresult = system(ftpbuf);
  16897. if(systemresult != 0)
  16898. {
  16899. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16900. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16901. systemresult = system(ftpbuf);
  16902. if(systemresult != 0)
  16903. {
  16904. DEBUG_WARN("wget error!\n");
  16905. result = FALSE;
  16906. }
  16907. }
  16908. system("pkill ping");
  16909. return result;
  16910. }
  16911. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16912. {
  16913. char rmFileCmd[100]={0};
  16914. char FilePath[100]={0};
  16915. char buf[512];
  16916. int systemresult = 0;
  16917. //DEBUG_INFO("filename=%s\n",filename);
  16918. //DEBUG_INFO("url=%s\n",url);
  16919. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16920. if((access(FilePath,F_OK))!=-1)
  16921. {
  16922. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16923. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16924. system(rmFileCmd);
  16925. }
  16926. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16927. if(fp == NULL)
  16928. {
  16929. DEBUG_INFO("log is NULL\n");
  16930. return FALSE;
  16931. }
  16932. else
  16933. {
  16934. fprintf(fp, "%s\n", url);
  16935. fprintf(fp, "%s\n", filename);
  16936. fclose(fp);
  16937. }
  16938. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16939. if(phpFP == NULL)
  16940. {
  16941. DEBUG_INFO("PHP upload fail.\n");
  16942. return FALSE;
  16943. }
  16944. else
  16945. {
  16946. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16947. {
  16948. if(strstr(buf, "result") != NULL)
  16949. {
  16950. sscanf(buf, "result: %d", &systemresult);
  16951. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16952. }
  16953. }
  16954. pclose(phpFP);
  16955. }
  16956. if(systemresult != 1)
  16957. {
  16958. DEBUG_INFO("HTTP upload error!\n");
  16959. return FALSE;
  16960. }
  16961. return TRUE;
  16962. }
  16963. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16964. {
  16965. int result = FALSE;
  16966. char ftpbuf[200];
  16967. int systemresult;
  16968. /*
  16969. // Domaind name transfer to IP address
  16970. struct hostent* server;
  16971. char *IPbuffer;
  16972. server = gethostbyname(location);
  16973. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16974. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16975. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16976. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16977. systemresult = system(ftpbuf);
  16978. if(systemresult != 0)
  16979. {
  16980. DEBUG_INFO("ftpput error!\n");
  16981. }
  16982. else
  16983. {
  16984. result = TRUE;
  16985. DEBUG_INFO("ftpput OK!\n");
  16986. }
  16987. return result;
  16988. }
  16989. int GetOcppServerURL()
  16990. {
  16991. int result = FALSE;
  16992. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16993. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16994. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16995. struct yuarel url;
  16996. char urlStr[512];
  16997. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  16998. {
  16999. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  17000. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17001. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17002. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  17003. if(yuarel_parse(&url, urlStr) != -1)
  17004. {
  17005. sprintf(OcppProtocol, "%s", url.scheme);
  17006. sprintf(OcppHost, "%s", url.host);
  17007. if(url.path == NULL)
  17008. OcppTempPath[0] = '\0';
  17009. else
  17010. {
  17011. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  17012. {
  17013. sprintf(OcppTempPath, "%s/", url.path);
  17014. }
  17015. else
  17016. {
  17017. sprintf(OcppTempPath, "%s", url.path);
  17018. }
  17019. }
  17020. if(url.port == 0)
  17021. {
  17022. if(strcmp(OcppProtocol, "wss") == 0)
  17023. OcppPort = 443;
  17024. else
  17025. OcppPort = 80;
  17026. }
  17027. else
  17028. OcppPort = url.port;
  17029. result = TRUE;
  17030. }
  17031. }
  17032. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  17033. {
  17034. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  17035. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17036. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17037. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  17038. if(yuarel_parse(&url, urlStr) != -1)
  17039. {
  17040. sprintf(OcppProtocol, "%s", url.scheme);
  17041. sprintf(OcppHost, "%s", url.host);
  17042. if(url.path == NULL)
  17043. OcppTempPath[0] = '\0';
  17044. else
  17045. sprintf(OcppTempPath, "%s", url.path);
  17046. if(url.port == 0)
  17047. {
  17048. if(strcmp(OcppProtocol, "wss") == 0)
  17049. OcppPort = 443;
  17050. else
  17051. OcppPort = 80;
  17052. }
  17053. else
  17054. OcppPort = url.port;
  17055. result = TRUE;
  17056. }
  17057. }
  17058. else
  17059. {
  17060. strcpy(OcppHost,"");
  17061. }
  17062. return result;
  17063. }
  17064. int GetOcppPath()
  17065. {
  17066. int result = FALSE;
  17067. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  17068. {
  17069. if(OcppTempPath == NULL)
  17070. {
  17071. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17072. }
  17073. else
  17074. {
  17075. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17076. }
  17077. result = TRUE;
  17078. goto End;
  17079. }
  17080. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  17081. {
  17082. if(OcppTempPath == NULL)
  17083. {
  17084. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  17085. }
  17086. else
  17087. {
  17088. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  17089. }
  17090. result = TRUE;
  17091. goto End;
  17092. }
  17093. else
  17094. {
  17095. strcpy(OcppPath,"");
  17096. }
  17097. End:
  17098. return result;
  17099. }
  17100. int GetOcppPort()
  17101. {
  17102. return OcppPort;
  17103. }
  17104. int GetOcppConnStatus(void)
  17105. {
  17106. return ShmOCPP16Data->OcppConnStatus;
  17107. }
  17108. void SetOcppConnStatus(uint8_t status)
  17109. {
  17110. ShmOCPP16Data->OcppConnStatus = status;
  17111. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  17112. }
  17113. int GetHeartBeatWithNOResponse(void)
  17114. {
  17115. return HeartBeatWithNOResponse;
  17116. }
  17117. void SetHeartBeatWithNOResponse(void)
  17118. {
  17119. HeartBeatWithNOResponse = 0;
  17120. }
  17121. void GetStartTransactionIdTag(int gun_index)
  17122. {
  17123. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17124. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17125. }
  17126. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17127. {
  17128. char ch;
  17129. FILE *fptr1;
  17130. int temptransactionId;
  17131. char str[100]={0};
  17132. temptransactionId = 0;
  17133. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17134. {
  17135. DEBUG_INFO("IdTag is empty.\n");
  17136. return temptransactionId;
  17137. }
  17138. /*------ Read the file ----------------*/
  17139. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  17140. if (!fptr1)
  17141. {
  17142. DEBUG_INFO("QueueTransactionId file open error.\n");
  17143. //printf(" File not found or unable to open the input file!!\n");
  17144. return temptransactionId;
  17145. }
  17146. ch=fgetc(fptr1);
  17147. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  17148. rewind(fptr1);
  17149. if(ch!=EOF)
  17150. {
  17151. // printf("%c",ch);
  17152. while (fgets(str, 100, fptr1) != NULL)
  17153. {
  17154. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17155. if(str[0]=='\0')
  17156. {
  17157. break;
  17158. }
  17159. char *revbuf[8] = {0}; // Variable store string split
  17160. int num = 0;// Quantity after string split
  17161. DEBUG_INFO("Transaction queue data= %s\n", str);
  17162. splitstring(str,",",revbuf,&num); // String split
  17163. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17164. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17165. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17166. DEBUG_INFO("------------------------------\n");
  17167. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17168. {
  17169. if(isStopTransaction)
  17170. {
  17171. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17172. {
  17173. temptransactionId = atoi(revbuf[2]);
  17174. //break;
  17175. }
  17176. }
  17177. else
  17178. {
  17179. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17180. {
  17181. temptransactionId = atoi(revbuf[2]);
  17182. //break;
  17183. }
  17184. }
  17185. }
  17186. }
  17187. }
  17188. else
  17189. DEBUG_INFO("EOF\n");
  17190. fclose(fptr1);
  17191. /*------- End of reading ---------------*/
  17192. return temptransactionId;
  17193. }
  17194. void SetTransactionIdZero(int transactionId)
  17195. {
  17196. char ch;
  17197. FILE *fptr1, *fptr2;
  17198. int temptransactionId = 0;
  17199. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  17200. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  17201. if (!fptr1)
  17202. {
  17203. //printf(" File not found or unable to open the input file!!\n");
  17204. return ;
  17205. }
  17206. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17207. if (!fptr2)
  17208. {
  17209. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17210. fclose(fptr1);
  17211. return ;
  17212. }
  17213. ch=fgetc(fptr1);
  17214. rewind(fptr1);
  17215. if(ch!=EOF)
  17216. {
  17217. // copy all contents to the temporary file except the specific line
  17218. while (fgets(str, 100, fptr1) != NULL)
  17219. {
  17220. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17221. if(str[0]=='\0')
  17222. {
  17223. break;
  17224. }
  17225. char *revbuf[8] = {0};
  17226. int num = 0;
  17227. strcpy(strtemp, str);
  17228. splitstring(str,",",revbuf,&num);
  17229. if(revbuf[2][0] != '\0')
  17230. {
  17231. temptransactionId = atoi(revbuf[2]);
  17232. if(transactionId != temptransactionId)
  17233. {
  17234. fprintf(fptr2, "%s\n", strtemp);
  17235. }
  17236. }
  17237. }
  17238. }
  17239. fclose(fptr1);
  17240. fclose(fptr2);
  17241. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  17242. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  17243. /*------ Read the file ----------------*/
  17244. }
  17245. int InternetDisconnect(void)
  17246. {
  17247. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17248. }
  17249. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17250. void storeTempStopTransaction(int gun_index)
  17251. {
  17252. char guid[37]={0};
  17253. int tempIndex = 0;
  17254. char TempStopTransaction[256];
  17255. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  17256. DEBUG_INFO("storeTempStopTransaction...\n");
  17257. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17258. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  17259. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17260. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17261. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17262. {
  17263. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17264. {
  17265. tempIndex = ((gun_index==2) ? 1: 0);
  17266. }
  17267. else
  17268. {
  17269. tempIndex = gun_index;
  17270. }
  17271. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17272. {
  17273. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17274. {
  17275. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17276. }
  17277. }// END OF CHAdeMO_QUANTITY
  17278. }
  17279. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17280. {
  17281. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17282. {
  17283. tempIndex = ((gun_index==2) ? 1: 0);
  17284. }
  17285. else
  17286. {
  17287. tempIndex = gun_index;
  17288. }
  17289. for (int index = 0; index < CCS_QUANTITY; index++)
  17290. {
  17291. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17292. {
  17293. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17294. }
  17295. }// END OF CCS_QUANTITY
  17296. }
  17297. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17298. {
  17299. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17300. {
  17301. tempIndex = ((gun_index==2) ? 1: 0);
  17302. }
  17303. else
  17304. {
  17305. tempIndex = gun_index;
  17306. }
  17307. for (int index = 0; index < GB_QUANTITY; index++)
  17308. {
  17309. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17310. {
  17311. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17312. }
  17313. }// END OF GB_QUANTITY
  17314. }
  17315. else if(gunType[gun_index] == GUN_TYPE_DO)
  17316. {
  17317. tempIndex = gun_index;
  17318. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17319. {
  17320. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17321. {
  17322. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17323. }
  17324. }
  17325. }
  17326. else
  17327. {
  17328. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17329. {
  17330. tempIndex = 2;
  17331. }
  17332. else
  17333. {
  17334. tempIndex = gun_index;
  17335. }
  17336. for (int index = 0; index < AC_QUANTITY; index++)
  17337. {
  17338. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17339. {
  17340. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17341. }
  17342. }// END OF AC_QUANTITY
  17343. }
  17344. //Stop Transaction Time
  17345. struct timeval tmnow;
  17346. struct tm *tm;
  17347. char buf[28];//, usec_buf[6];
  17348. gettimeofday(&tmnow, NULL);
  17349. time_t t;
  17350. t = time(NULL);
  17351. /*UTC time and date*/
  17352. tm = gmtime(&t);
  17353. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17354. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  17355. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  17356. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17357. random_uuid(guid);
  17358. /***********************************transactionData******************************************************/
  17359. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17360. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17361. //=================================
  17362. //1. Transaction_Begin
  17363. //=================================
  17364. //============================== Energy.Active.Import.Interval ===========================================
  17365. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17366. {
  17367. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  17368. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17369. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  17370. 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*/]);
  17371. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17372. 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))
  17373. {
  17374. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  17375. }
  17376. else
  17377. {
  17378. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  17379. }
  17380. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  17381. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17382. }
  17383. //=================================
  17384. //2. Transaction_End
  17385. //=================================
  17386. //2.1====================================== Current.Import L1 ==============================================
  17387. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17388. {
  17389. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17390. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17391. {
  17392. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17393. {
  17394. tempIndex = ((gun_index==2) ? 1: 0);
  17395. }
  17396. else
  17397. {
  17398. tempIndex = gun_index;
  17399. }
  17400. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17401. {
  17402. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17403. {
  17404. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17405. }
  17406. }// End of for CHAdeMO_QUANTITY
  17407. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17408. }
  17409. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17410. {
  17411. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17412. {
  17413. tempIndex = ((gun_index==2) ? 1: 0);
  17414. }
  17415. else
  17416. {
  17417. tempIndex = gun_index;
  17418. }
  17419. for (int index = 0; index < CCS_QUANTITY; index++)
  17420. {
  17421. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17422. {
  17423. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17424. }
  17425. }// End of for CCS_QUANTITY
  17426. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17427. }
  17428. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17429. {
  17430. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17431. {
  17432. tempIndex = ((gun_index==2) ? 1: 0);
  17433. }
  17434. else
  17435. {
  17436. tempIndex = gun_index;
  17437. }
  17438. for (int index = 0; index < GB_QUANTITY; index++)
  17439. {
  17440. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17441. {
  17442. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17443. }
  17444. }// End of for GB_QUANTITY
  17445. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17446. }
  17447. else if(gunType[gun_index] == GUN_TYPE_DO)
  17448. {
  17449. tempIndex = gun_index;
  17450. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17451. {
  17452. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17453. {
  17454. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17455. }
  17456. }
  17457. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17458. }
  17459. else
  17460. {
  17461. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17462. {
  17463. tempIndex = 2;
  17464. }
  17465. else
  17466. {
  17467. tempIndex = gun_index;
  17468. }
  17469. for (int index = 0; index < AC_QUANTITY; index++)
  17470. {
  17471. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17472. {
  17473. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17474. }
  17475. }// End of for AC_QUANTITY
  17476. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17477. }
  17478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17479. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17480. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17481. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17482. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17483. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17484. }
  17485. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17486. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17487. {
  17488. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17489. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17490. {
  17491. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17492. {
  17493. tempIndex = ((gun_index==2) ? 1: 0);
  17494. }
  17495. else
  17496. {
  17497. tempIndex = gun_index;
  17498. }
  17499. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17500. {
  17501. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17502. {
  17503. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17504. }
  17505. }// END OF CHAdeMO_QUANTITY
  17506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17507. }
  17508. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17509. {
  17510. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17511. {
  17512. tempIndex = ((gun_index==2) ? 1: 0);
  17513. }
  17514. else
  17515. {
  17516. tempIndex = gun_index;
  17517. }
  17518. for (int index = 0; index < CCS_QUANTITY; index++)
  17519. {
  17520. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17521. {
  17522. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17523. }
  17524. }// END OF CCS_QUANTITY
  17525. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17526. }
  17527. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17528. {
  17529. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17530. {
  17531. tempIndex = ((gun_index==2) ? 1: 0);
  17532. }
  17533. else
  17534. {
  17535. tempIndex = gun_index;
  17536. }
  17537. for (int index = 0; index < GB_QUANTITY; index++)
  17538. {
  17539. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17540. {
  17541. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17542. }
  17543. }// END OF GB_QUANTITY
  17544. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17545. }
  17546. else if(gunType[gun_index] == GUN_TYPE_DO)
  17547. {
  17548. tempIndex = gun_index;
  17549. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17550. {
  17551. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17552. {
  17553. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17554. }
  17555. }
  17556. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17557. }
  17558. else
  17559. {
  17560. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17561. {
  17562. tempIndex = 2;
  17563. }
  17564. else
  17565. {
  17566. tempIndex = gun_index;
  17567. }
  17568. for (int index = 0; index < AC_QUANTITY; index++)
  17569. {
  17570. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17571. {
  17572. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17573. }
  17574. }// END OF AC_QUANTITY
  17575. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17576. }
  17577. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17578. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17579. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17580. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17581. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17582. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17583. }
  17584. //2.3====================================== Power.Active.Import =========================================
  17585. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17586. {
  17587. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17588. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17589. {
  17590. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17591. {
  17592. tempIndex = ((gun_index==2) ? 1: 0);
  17593. }
  17594. else
  17595. {
  17596. tempIndex = gun_index;
  17597. }
  17598. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17599. {
  17600. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17601. {
  17602. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17603. }
  17604. } // End for CHAdeMO_QUANTITY
  17605. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17606. }
  17607. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17608. {
  17609. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17610. {
  17611. tempIndex = ((gun_index==2) ? 1: 0);
  17612. }
  17613. else
  17614. {
  17615. tempIndex = gun_index;
  17616. }
  17617. for (int index = 0; index < CCS_QUANTITY; index++)
  17618. {
  17619. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17620. {
  17621. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17622. }
  17623. } // END for CCS_QUANTITY
  17624. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17625. }
  17626. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17627. {
  17628. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17629. {
  17630. tempIndex = ((gun_index==2) ? 1: 0);
  17631. }
  17632. else
  17633. {
  17634. tempIndex = gun_index;
  17635. }
  17636. for (int index = 0; index < GB_QUANTITY; index++)
  17637. {
  17638. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17639. {
  17640. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17641. }
  17642. }// END for GB_QUANTITY
  17643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17644. }
  17645. else if(gunType[gun_index] == GUN_TYPE_DO)
  17646. {
  17647. tempIndex = gun_index;
  17648. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17649. {
  17650. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17651. {
  17652. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17653. }
  17654. }
  17655. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17656. }
  17657. else
  17658. {
  17659. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17660. {
  17661. tempIndex = 2;
  17662. }
  17663. else
  17664. {
  17665. tempIndex = gun_index;
  17666. }
  17667. for (int index = 0; index < AC_QUANTITY; index++)
  17668. {
  17669. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17670. {
  17671. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17672. }
  17673. } // END for AC_QUANTITY
  17674. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17675. }
  17676. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17677. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17678. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17679. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17680. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17681. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17682. }
  17683. //2.4====================================== Voltage L1 ====================================================
  17684. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17685. {
  17686. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17687. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17688. {
  17689. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17690. {
  17691. tempIndex = ((gun_index==2) ? 1: 0);
  17692. }
  17693. else
  17694. {
  17695. tempIndex = gun_index;
  17696. }
  17697. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17698. {
  17699. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17700. {
  17701. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17702. }
  17703. } // END OF FOR CHAdeMO_QUANTITY
  17704. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17705. }
  17706. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17707. {
  17708. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17709. {
  17710. tempIndex = ((gun_index==2) ? 1: 0);
  17711. }
  17712. else
  17713. {
  17714. tempIndex = gun_index;
  17715. }
  17716. for (int index = 0; index < CCS_QUANTITY; index++)
  17717. {
  17718. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17719. {
  17720. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17721. }
  17722. } // END OF FOR CCS_QUANTITY
  17723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17724. }
  17725. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17726. {
  17727. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17728. {
  17729. tempIndex = ((gun_index==2) ? 1: 0);
  17730. }
  17731. else
  17732. {
  17733. tempIndex = gun_index;
  17734. }
  17735. for (int index = 0; index < GB_QUANTITY; index++)
  17736. {
  17737. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17738. {
  17739. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17740. }
  17741. } // END OF FOR GB_QUANTITY
  17742. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17743. }
  17744. else if(gunType[gun_index] == GUN_TYPE_DO)
  17745. {
  17746. tempIndex = gun_index;
  17747. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17748. {
  17749. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17750. {
  17751. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17752. }
  17753. }
  17754. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17755. }
  17756. else
  17757. {
  17758. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17759. {
  17760. tempIndex = 2;
  17761. }
  17762. else
  17763. {
  17764. tempIndex = gun_index;
  17765. }
  17766. for (int index = 0; index < AC_QUANTITY; index++)
  17767. {
  17768. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17769. {
  17770. 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
  17771. }
  17772. } // END OF FOR AC_QUANTITY
  17773. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17774. }
  17775. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17776. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17777. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17778. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17779. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17780. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17781. }
  17782. //2.5============================================== End SoC =========================================================
  17783. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17784. {
  17785. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17786. 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))
  17787. {
  17788. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17789. {
  17790. tempIndex = ((gun_index==2) ? 1: 0);
  17791. }
  17792. else
  17793. {
  17794. tempIndex = gun_index;
  17795. }
  17796. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17797. {
  17798. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17799. {
  17800. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17801. {
  17802. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17803. }
  17804. }
  17805. }
  17806. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17807. {
  17808. for (int index = 0; index < CCS_QUANTITY; index++)
  17809. {
  17810. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17811. {
  17812. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17813. }
  17814. }
  17815. }
  17816. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17817. {
  17818. for (int index = 0; index < GB_QUANTITY; index++)
  17819. {
  17820. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17821. {
  17822. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17823. }
  17824. }
  17825. }
  17826. else if(gunType[gun_index] == GUN_TYPE_DO)
  17827. {
  17828. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17829. {
  17830. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17831. {
  17832. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17833. }
  17834. }
  17835. }
  17836. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17837. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17838. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17839. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17840. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17841. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17842. } // END FOR DC CASE
  17843. }
  17844. //2.6====================================== Current.Import L2 ==============================================
  17845. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17846. {
  17847. // AC 3 phase L2 current
  17848. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17849. {
  17850. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17851. {
  17852. tempIndex = 2;
  17853. }
  17854. else
  17855. {
  17856. tempIndex = gun_index;
  17857. }
  17858. for (int index = 0; index < AC_QUANTITY; index++)
  17859. {
  17860. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17861. {
  17862. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17863. }
  17864. }// End of for AC_QUANTITY
  17865. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17866. }
  17867. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17868. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17869. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17870. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17871. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17872. }
  17873. //2.7====================================== Current.Import L3 ==============================================
  17874. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17875. {
  17876. // AC 3 phase L3 current
  17877. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17878. {
  17879. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17880. {
  17881. tempIndex = 2;
  17882. }
  17883. else
  17884. {
  17885. tempIndex = gun_index;
  17886. }
  17887. for (int index = 0; index < AC_QUANTITY; index++)
  17888. {
  17889. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17890. {
  17891. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17892. }
  17893. }// End of for AC_QUANTITY
  17894. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17895. }
  17896. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17897. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17898. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17899. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17900. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17901. }
  17902. //2.9====================================== Voltage L2 ====================================================
  17903. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17904. {
  17905. // AC 3 phase L2 volatge
  17906. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17907. {
  17908. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17909. {
  17910. tempIndex = 2;
  17911. }
  17912. else
  17913. {
  17914. tempIndex = gun_index;
  17915. }
  17916. for (int index = 0; index < AC_QUANTITY; index++)
  17917. {
  17918. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17919. {
  17920. 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
  17921. }
  17922. } // END OF FOR AC_QUANTITY
  17923. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  17924. }
  17925. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17926. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17927. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17928. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17929. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17930. }
  17931. //2.10====================================== Voltage L3 ====================================================
  17932. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17933. {
  17934. // AC 3 phase L3 volatge
  17935. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17936. {
  17937. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17938. {
  17939. tempIndex = 2;
  17940. }
  17941. else
  17942. {
  17943. tempIndex = gun_index;
  17944. }
  17945. for (int index = 0; index < AC_QUANTITY; index++)
  17946. {
  17947. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17948. {
  17949. 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
  17950. }
  17951. } // END OF FOR AC_QUANTITY
  17952. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  17953. }
  17954. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17955. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  17956. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  17957. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  17958. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17959. }
  17960. //====================== Start SoC ================================
  17961. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17962. {
  17963. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17964. 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))
  17965. {
  17966. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17967. {
  17968. tempIndex = ((gun_index==2) ? 1: 0);
  17969. }
  17970. else
  17971. {
  17972. tempIndex = gun_index;
  17973. }
  17974. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17975. {
  17976. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17977. {
  17978. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17979. {
  17980. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  17981. }
  17982. }
  17983. }
  17984. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17985. {
  17986. for (int index = 0; index < CCS_QUANTITY; index++)
  17987. {
  17988. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17989. {
  17990. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  17991. }
  17992. }
  17993. }
  17994. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17995. {
  17996. for (int index = 0; index < GB_QUANTITY; index++)
  17997. {
  17998. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17999. {
  18000. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18001. }
  18002. }
  18003. }
  18004. else if(gunType[gun_index] == GUN_TYPE_DO)
  18005. {
  18006. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18007. {
  18008. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18009. {
  18010. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18011. }
  18012. }
  18013. }
  18014. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18015. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18016. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18017. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18018. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18019. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18020. } // END FOR DC CASE
  18021. }
  18022. //======================================== Message create ==============================================
  18023. json_object *StopTransaction = json_object_new_object();
  18024. json_object *transactionDatas = json_object_new_array();
  18025. json_object *sampledValues = json_object_new_array();
  18026. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  18027. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  18028. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  18029. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  18030. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  18031. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18032. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  18033. {
  18034. json_object *transactionData = json_object_new_object();
  18035. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18036. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18037. {
  18038. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18039. {
  18040. json_object *sampledValue = json_object_new_object();
  18041. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18042. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18043. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18044. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18045. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18046. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18047. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18048. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18049. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18050. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18051. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18052. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18053. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18054. json_object_array_add(sampledValues, sampledValue);
  18055. }
  18056. }
  18057. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18058. json_object_array_add(transactionDatas, transactionData);
  18059. }
  18060. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18061. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18062. ,MESSAGE_TYPE_CALL
  18063. ,guid
  18064. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18065. json_object_put(StopTransaction);
  18066. // Check File "TempStopTransaction" Exist
  18067. if((access(TempStopTransaction,F_OK))!=-1)
  18068. {
  18069. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18070. fclose(fopen(TempStopTransaction, "w"));
  18071. }
  18072. else
  18073. {
  18074. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18075. FILE *log = fopen(TempStopTransaction, "w+");
  18076. if(log == NULL)
  18077. {
  18078. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18079. return ;
  18080. }
  18081. else
  18082. {
  18083. fclose(log);
  18084. }
  18085. }
  18086. //Add TempStopTransaction | Update TempStopTransaction
  18087. // open file for writing
  18088. FILE *outfile;
  18089. outfile = fopen (TempStopTransaction, "a");
  18090. //DEBUG_INFO("data = %s\n", queuedata);
  18091. fputs(queuedata, outfile);
  18092. fputs("\n", outfile);
  18093. fclose (outfile);
  18094. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18095. OCPP_updatePeriodEnergy(gun_index);
  18096. }
  18097. void checkTempStopTransaction(int gun_index)
  18098. {
  18099. FILE *fptr1;
  18100. char ch;
  18101. char str[QUEUE_MESSAGE_LENGTH]={0};
  18102. char guid[37]={0};
  18103. char tempdata[65]={0};
  18104. char connectorStr[2]={0};
  18105. char TempStopTransaction[256];
  18106. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18107. fptr1 = fopen(TempStopTransaction, "r");
  18108. //TempStopTransaction格式: 槍號,StopTransaction封包
  18109. if (!fptr1)
  18110. {
  18111. //printf(" File not found or unable to open the input file!!\n");
  18112. return ;
  18113. }
  18114. ch=fgetc(fptr1);
  18115. //printf(" Now the content of the file %s is : \n",fname);
  18116. rewind(fptr1);
  18117. if(ch!=EOF)
  18118. {
  18119. // copy all contents to the temporary file except the specific line
  18120. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18121. {
  18122. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18123. if(str[0]=='\0')
  18124. {
  18125. break;
  18126. }
  18127. //TempStopTransaction格式: 槍號,StopTransaction封包
  18128. strncpy(connectorStr, str, 1);
  18129. if(atoi(connectorStr) != (gun_index+1))
  18130. {
  18131. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18132. fclose(fptr1);
  18133. return ;
  18134. }
  18135. //random_uuid(guid);
  18136. strncpy(guid, str+6, 36); //copy guid
  18137. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18138. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18139. {
  18140. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18141. }
  18142. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18143. OCPP_insert_transaction_msg(NO, str);
  18144. memset(str,0,ARRAY_SIZE(str));
  18145. }
  18146. }
  18147. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18148. fclose(fptr1);
  18149. remove(TempStopTransaction); // remove the original file
  18150. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18151. }
  18152. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18153. {
  18154. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18155. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18156. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18157. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18158. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18159. }
  18160. int GetWebSocketPingInterval(void)
  18161. {
  18162. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18163. }
  18164. int GetServerSign(void)
  18165. {
  18166. return server_sign;
  18167. }
  18168. uint8_t GetOcppSecurityProfile()
  18169. {
  18170. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18171. }
  18172. void GetOcppChargerBoxId(uint8_t *data)
  18173. {
  18174. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18175. }
  18176. void GetOcppSecurityPassword(uint8_t *data)
  18177. {
  18178. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18179. }
  18180. void SetOcppVersion(uint8_t *version)
  18181. {
  18182. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18183. DEBUG_INFO("ocpp version: %s\n", version);
  18184. if(strstr((char*)version, "ocpp1.6") != NULL)
  18185. {
  18186. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18187. }
  18188. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18189. {
  18190. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18191. system("pkill OcppBackend");
  18192. }
  18193. }
  18194. void SetServerSign(int value)
  18195. {
  18196. server_sign = value;
  18197. }
  18198. int GetBootNotificationInterval(void)
  18199. {
  18200. return BootNotificationInterval;
  18201. }
  18202. int GetInternetConn(void)
  18203. {
  18204. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18205. }
  18206. int GetBackendConnectionTimeout(void)
  18207. {
  18208. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18209. }
  18210. int isConnectorInitMode(int gun_index)
  18211. {
  18212. int tempIndex = 0;
  18213. int result = TRUE;
  18214. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18215. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18216. {
  18217. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18218. {
  18219. tempIndex = ((gun_index==2) ? 1: 0);
  18220. }
  18221. else
  18222. {
  18223. tempIndex = gun_index;
  18224. }
  18225. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18226. {
  18227. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18228. {
  18229. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18230. } //end of the same index
  18231. }//end of for CHAdeMO_QUANTITY
  18232. }
  18233. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18234. {
  18235. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18236. {
  18237. tempIndex = ((gun_index==2) ? 1: 0);
  18238. }
  18239. else
  18240. {
  18241. tempIndex = gun_index;
  18242. }
  18243. for (int index = 0; index < CCS_QUANTITY; index++)
  18244. {
  18245. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18246. {
  18247. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18248. } //end of the same index
  18249. } // end of for CCS_QUANTITY
  18250. }
  18251. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18252. {
  18253. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18254. {
  18255. tempIndex = ((gun_index==2) ? 1: 0);
  18256. }
  18257. else
  18258. {
  18259. tempIndex = gun_index;
  18260. }
  18261. for (int index = 0; index < GB_QUANTITY; index++)
  18262. {
  18263. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18264. {
  18265. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18266. } //end of the same index
  18267. } // end of for GB_QUANTITY
  18268. }
  18269. else if(gunType[gun_index] == GUN_TYPE_DO)
  18270. {
  18271. tempIndex = gun_index;
  18272. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18273. {
  18274. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18275. {
  18276. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18277. } //end of the same index
  18278. }
  18279. }
  18280. else
  18281. {
  18282. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18283. {
  18284. tempIndex = 2;
  18285. }
  18286. else
  18287. {
  18288. tempIndex = gun_index;
  18289. }
  18290. for (int index = 0; index < AC_QUANTITY; index++)
  18291. {
  18292. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18293. {
  18294. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18295. }//end of the same index
  18296. }//end of for AC_QUANTITY
  18297. }
  18298. return result;
  18299. }
  18300. void refreshProcDogTimer()
  18301. {
  18302. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  18303. }
  18304. void InitialSystemValue(void)
  18305. {
  18306. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18307. locallistVersion=0;
  18308. BootNotificationInterval = 0;
  18309. authorizeRetryTimes = 0;
  18310. GunStatusInterval = 10;
  18311. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18312. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18313. //Hear Beat
  18314. HeartBeatWithNOResponse = 0;
  18315. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18316. FirstHeartBeat = 0;
  18317. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18318. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18319. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18320. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18321. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18322. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18323. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18324. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18325. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18326. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18327. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18328. //Status && ConnectorPlugIn Setting
  18329. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18330. {
  18331. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18332. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18333. }
  18334. for (int index = 0; index < CCS_QUANTITY; index++)
  18335. {
  18336. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18337. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18338. }
  18339. for (int index = 0; index < GB_QUANTITY; index++)
  18340. {
  18341. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18342. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18343. }
  18344. for (int index = 0; index < AC_QUANTITY; index++)
  18345. {
  18346. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18347. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18348. }
  18349. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18350. {
  18351. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18352. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18353. }
  18354. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18355. {
  18356. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18357. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18358. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18359. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18360. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18361. }
  18362. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18363. refreshStartTimer(&clientTime.Heartbeat);
  18364. sleep(1);
  18365. }
  18366. void LWS_Send(char *str)
  18367. {
  18368. //=====================================================
  18369. // Check InternetConn 0: disconnected, 1: connected
  18370. //====================================================
  18371. if(GetOcppConnStatus() == 0)
  18372. {
  18373. DEBUG_INFO("offline now !!!\n");
  18374. return;
  18375. }
  18376. // Only disable isWebsocketSendable operation initiated by charger
  18377. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18378. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18379. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18380. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18381. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18382. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18383. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18384. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18385. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18386. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18387. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18388. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18389. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18390. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18391. {
  18392. isWebsocketSendable = 0;
  18393. }
  18394. pthread_mutex_lock(&lock_send);
  18395. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18396. sprintf((char *)SendBuffer, "%s", str);
  18397. SendBufLen = strlen(str);
  18398. pthread_mutex_unlock(&lock_send);
  18399. lws_callback_on_writable(wsi_client);
  18400. //lws_service(context, 0);
  18401. //sleep(1);
  18402. }
  18403. void LWS_SendNow(char *str)
  18404. {
  18405. //=====================================================
  18406. // Check InternetConn 0: disconnected, 1: connected
  18407. //====================================================
  18408. if(GetOcppConnStatus() == 0)
  18409. {
  18410. DEBUG_INFO("offline now !!!\n");
  18411. return;
  18412. }
  18413. // Only disable isWebsocketSendable operation initiated by charger
  18414. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18415. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18416. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18417. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18418. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18419. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18420. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18421. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18422. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18423. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18424. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18425. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18426. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18427. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18428. {
  18429. isWebsocketSendable = 0;
  18430. }
  18431. pthread_mutex_lock(&lock_send);
  18432. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18433. sprintf((char *)SendBuffer, "%s", str);
  18434. SendBufLen = strlen(str);
  18435. pthread_mutex_unlock(&lock_send);
  18436. lws_callback_on_writable(wsi_client);
  18437. lws_service(context, 0);
  18438. //sleep(1);
  18439. }