MessageHandler.c 925 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133
  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(txId, 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. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1136. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  1137. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s}",
  1138. atoi(columnValue[1]),
  1139. columnValue[2],
  1140. atoi(columnValue[3])==1?"true":"false",
  1141. atoi(columnValue[4])==1?"true":"false");
  1142. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1143. return 0;
  1144. }
  1145. void OCPP_query_deduct_info()
  1146. {
  1147. int rc = 0;
  1148. char sql[100];
  1149. char zErrMsg[100];
  1150. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1151. /* Execute SQL statement */
  1152. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1153. if( rc != SQLITE_OK )
  1154. {
  1155. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1156. }
  1157. }
  1158. //==========================================
  1159. // Check time passed since today
  1160. //==========================================
  1161. long long DiffTimebWithNow(struct timeb ST)
  1162. {
  1163. //return milli-second
  1164. struct timeb ET;
  1165. long long StartTime,StopTime;
  1166. ftime(&ET);
  1167. StartTime=(long long)ST.time;
  1168. StopTime=(long long)ET.time;
  1169. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1170. }
  1171. int getTimePassSinceToday(uint8_t gun_index)
  1172. {
  1173. int result = -1;
  1174. static time_t lastTime[4];
  1175. time_t t;
  1176. struct tm *tmStartToday;
  1177. struct timeb tbStartToday;
  1178. t=time(NULL);
  1179. if(difftime(t, lastTime[gun_index])>0)
  1180. {
  1181. tmStartToday=localtime(&t);
  1182. tmStartToday->tm_hour = 0;
  1183. tmStartToday->tm_min = 0;
  1184. tmStartToday->tm_sec = 0;
  1185. tbStartToday.time = mktime(tmStartToday);
  1186. tbStartToday.millitm = 0;
  1187. result = DiffTimebWithNow(tbStartToday)/1000;
  1188. lastTime[gun_index] = t;
  1189. }
  1190. return result;
  1191. }
  1192. void getNowDatetime(uint8_t *data)
  1193. {
  1194. time_t t = time(NULL);
  1195. struct tm tm = *localtime(&t);
  1196. 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);
  1197. }
  1198. int syncDateTimeRTC(uint8_t *data)
  1199. {
  1200. struct ParsingResult
  1201. {
  1202. int result;
  1203. int scanedElement;
  1204. int year;
  1205. int month;
  1206. int mday;
  1207. int hour;
  1208. int min;
  1209. int sec;
  1210. int tz_hour;
  1211. int tz_min;
  1212. float minSec;
  1213. }result;
  1214. struct tm tmOrg;
  1215. struct tm *tmTarget;
  1216. struct timeb tbTarget;
  1217. char buf[128];
  1218. memset(&result, 0x00, sizeof(struct ParsingResult));
  1219. result.result = PASS;
  1220. if(strstr((char*)data, ".") != NULL)
  1221. {
  1222. // Original data with mini second
  1223. if(strstr((char*)data, "Z") != NULL)
  1224. {
  1225. // Original data with Z
  1226. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1227. &result.year,
  1228. &result.month,
  1229. &result.mday,
  1230. &result.hour,
  1231. &result.min,
  1232. &result.sec,
  1233. &result.minSec);
  1234. }
  1235. else
  1236. {
  1237. // Original data without Z
  1238. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1239. &result.year,
  1240. &result.month,
  1241. &result.mday,
  1242. &result.hour,
  1243. &result.min,
  1244. &result.sec,
  1245. &result.minSec,
  1246. &result.tz_hour,
  1247. &result.tz_min);
  1248. }
  1249. }
  1250. else
  1251. {
  1252. // Original data without mini second
  1253. if(strstr((char*)data, "Z") != NULL)
  1254. {
  1255. // Original data with Z
  1256. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1257. &result.year,
  1258. &result.month,
  1259. &result.mday,
  1260. &result.hour,
  1261. &result.min,
  1262. &result.sec);
  1263. }
  1264. else
  1265. {
  1266. // Original data without Z
  1267. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1268. &result.year,
  1269. &result.month,
  1270. &result.mday,
  1271. &result.hour,
  1272. &result.min,
  1273. &result.sec,
  1274. &result.tz_hour,
  1275. &result.tz_min);
  1276. }
  1277. }
  1278. tmOrg.tm_year = result.year - 1900;
  1279. tmOrg.tm_mon = result.month - 1;
  1280. tmOrg.tm_mday = result.mday;
  1281. tmOrg.tm_hour = result.hour;
  1282. tmOrg.tm_min = result.min;
  1283. tmOrg.tm_sec = result.sec;
  1284. tmOrg.tm_gmtoff = 0;
  1285. tbTarget.time = mktime(&tmOrg);
  1286. tbTarget.timezone = 0;
  1287. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1288. tmTarget = gmtime(&tbTarget.time);
  1289. 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);
  1290. //DEBUG_INFO(" org date time: %s\n", data);
  1291. //DEBUG_INFO("parse date time: %s\n", buf);
  1292. system(buf);
  1293. system("/sbin/hwclock -w --systohc");
  1294. if(result.scanedElement < 6)
  1295. result.result = FAIL;
  1296. return result.result;
  1297. }
  1298. //==========================================
  1299. // GetCompositeSchedule logic related function
  1300. //==========================================
  1301. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1302. {
  1303. //return milli-second
  1304. unsigned int StartTime,StopTime;
  1305. StartTime=(unsigned int)ST.time;
  1306. StopTime=(unsigned int)ET.time;
  1307. return (StopTime-StartTime);
  1308. }
  1309. int DiffTimebWithNowSec(struct timeb ST)
  1310. {
  1311. //return milli-second
  1312. struct timeb ET;
  1313. unsigned int StartTime,StopTime;
  1314. ftime(&ET);
  1315. StartTime=(unsigned int)ST.time;
  1316. StopTime=(unsigned int)ET.time;
  1317. return (StopTime-StartTime);
  1318. }
  1319. int getStartStop(uint8_t *start, uint8_t *stop)
  1320. {
  1321. int result = -1;
  1322. struct tm tmStart;
  1323. struct timeb tbStart;
  1324. struct tm tmStop;
  1325. struct timeb tbStop;
  1326. 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) &&
  1327. (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))
  1328. {
  1329. //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);
  1330. //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);
  1331. tmStart.tm_year -= 1900;
  1332. tmStart.tm_mon -= 1;
  1333. tbStart.time = mktime(&tmStart);
  1334. tbStart.millitm = 0;
  1335. tmStop.tm_year -= 1900;
  1336. tmStop.tm_mon -= 1;
  1337. tbStop.time = mktime(&tmStop);
  1338. tbStop.millitm = 0;
  1339. result = DiffTimebSec(tbStart, tbStop);
  1340. //DEBUG_INFO("getStartStop(): %d\n", result);
  1341. }
  1342. else
  1343. {
  1344. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1345. }
  1346. return result;
  1347. }
  1348. int isOvertNow(uint8_t *start)
  1349. {
  1350. int result = NO;
  1351. struct ParsingResult
  1352. {
  1353. int result;
  1354. int scanedElement;
  1355. int year;
  1356. int month;
  1357. int mday;
  1358. int hour;
  1359. int min;
  1360. int sec;
  1361. int tz_hour;
  1362. int tz_min;
  1363. float minSec;
  1364. }parsingResult;
  1365. struct tm tmStart;
  1366. struct timeb tbStart;
  1367. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1368. if(strstr((char*)start, ".") != NULL)
  1369. {
  1370. // Original data with mini second
  1371. if(strstr((char*)start, "Z") != NULL)
  1372. {
  1373. // Original data with Z
  1374. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1375. &parsingResult.year,
  1376. &parsingResult.month,
  1377. &parsingResult.mday,
  1378. &parsingResult.hour,
  1379. &parsingResult.min,
  1380. &parsingResult.sec,
  1381. &parsingResult.minSec);
  1382. }
  1383. else
  1384. {
  1385. // Original data without Z
  1386. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1387. &parsingResult.year,
  1388. &parsingResult.month,
  1389. &parsingResult.mday,
  1390. &parsingResult.hour,
  1391. &parsingResult.min,
  1392. &parsingResult.sec,
  1393. &parsingResult.minSec,
  1394. &parsingResult.tz_hour,
  1395. &parsingResult.tz_min);
  1396. }
  1397. }
  1398. else
  1399. {
  1400. // Original data without mini second
  1401. if(strstr((char*)start, "Z") != NULL)
  1402. {
  1403. // Original data with Z
  1404. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1405. &parsingResult.year,
  1406. &parsingResult.month,
  1407. &parsingResult.mday,
  1408. &parsingResult.hour,
  1409. &parsingResult.min,
  1410. &parsingResult.sec);
  1411. }
  1412. else
  1413. {
  1414. // Original data without Z
  1415. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1416. &parsingResult.year,
  1417. &parsingResult.month,
  1418. &parsingResult.mday,
  1419. &parsingResult.hour,
  1420. &parsingResult.min,
  1421. &parsingResult.sec,
  1422. &parsingResult.tz_hour,
  1423. &parsingResult.tz_min);
  1424. }
  1425. }
  1426. if(parsingResult.scanedElement >= 6)
  1427. {
  1428. tmStart.tm_year = parsingResult.year - 1900;
  1429. tmStart.tm_mon = parsingResult.month - 1;
  1430. tmStart.tm_mday = parsingResult.mday;
  1431. tmStart.tm_hour = parsingResult.hour;
  1432. tmStart.tm_min = parsingResult.min;
  1433. tmStart.tm_sec = parsingResult.sec;
  1434. tmStart.tm_gmtoff = 0;
  1435. tbStart.time = mktime(&tmStart);
  1436. tbStart.timezone = 0;
  1437. tbStart.millitm = 0;
  1438. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1439. if(DiffTimebWithNowSec(tbStart) <= 0)
  1440. result = NO;
  1441. else
  1442. result = YES;
  1443. }
  1444. else
  1445. {
  1446. DEBUG_WARN("Start date parsing error.\n");
  1447. }
  1448. return result;
  1449. }
  1450. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1451. {
  1452. int result = -1;
  1453. struct tm tmStart;
  1454. struct timeb tbStart;
  1455. struct tm tmStop;
  1456. struct timeb tbStop;
  1457. 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) &&
  1458. (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))
  1459. {
  1460. tmStart.tm_year -= 1900;
  1461. tmStart.tm_mon -= 1;
  1462. tbStart.time = mktime(&tmStart);
  1463. tbStart.millitm = 0;
  1464. tmStop.tm_year -= 1900;
  1465. tmStop.tm_mon -= 1;
  1466. tbStop.time = mktime(&tmStop);
  1467. tbStop.millitm = 0;
  1468. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1469. }
  1470. return result;
  1471. }
  1472. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1473. {
  1474. FILE *fp;
  1475. char profileFileName[128];
  1476. char *line = NULL;
  1477. size_t len = 0;
  1478. time_t CurrentTime;
  1479. struct tm *tmComposite;
  1480. struct StructChargingProfile maxProfile;
  1481. uint8_t limitMax=0;
  1482. int compositePeriodIdx = 0;
  1483. CurrentTime = time(NULL);
  1484. tmComposite=localtime(&CurrentTime);
  1485. 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);
  1486. if(isUnitA)
  1487. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1488. else
  1489. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1490. compositeProfile->ChargingSchedule.Duration = durationReq;
  1491. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1492. {
  1493. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1494. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1495. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1496. }
  1497. compositeProfile->ChargingProfileId = 0;
  1498. compositeProfile->StackLevel = 99 ;
  1499. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1500. maxProfile.ChargingProfileId = -1;
  1501. maxProfile.ChargingSchedule.Duration = -1;
  1502. system("rm -f /tmp/*.json");
  1503. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1504. // Search max profile
  1505. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1506. if((access(profileFileName, F_OK))!=-1)
  1507. {
  1508. fp = fopen(profileFileName, "r");
  1509. while(getline(&line, &len, fp) != -1)
  1510. {
  1511. json_object *obj = NULL;
  1512. obj = json_tokener_parse(line);
  1513. if(is_error(obj))
  1514. {
  1515. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1516. }
  1517. else
  1518. {
  1519. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1520. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1521. )
  1522. {
  1523. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1524. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1525. )
  1526. {
  1527. struct tm tmFrom, tmTo;
  1528. struct timeb tbFrom, tbTo;
  1529. 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) &&
  1530. (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))
  1531. {
  1532. tmFrom.tm_year -= 1900;
  1533. tmFrom.tm_mon -= 1;
  1534. tbFrom.time = mktime(&tmFrom);
  1535. tmTo.tm_year -= 1900;
  1536. tmTo.tm_mon -= 1;
  1537. tbTo.time = mktime(&tmTo);
  1538. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1539. {
  1540. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1541. {
  1542. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1543. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1544. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1545. }
  1546. maxProfile.ChargingProfileId = -1;
  1547. maxProfile.StackLevel = -1;
  1548. if(maxProfile.ChargingProfileId == -1)
  1549. DEBUG_INFO("MaxProfile found.\n");
  1550. else
  1551. DEBUG_INFO("MaxProfile updated.\n");
  1552. // Required item
  1553. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1554. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1555. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1556. if(isUnitA)
  1557. {
  1558. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1559. 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++)
  1560. {
  1561. 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"));
  1562. 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?
  1563. 3:
  1564. 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")));
  1565. 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")));
  1566. }
  1567. }
  1568. else
  1569. {
  1570. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1571. 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++)
  1572. {
  1573. 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"));
  1574. 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?
  1575. 3:
  1576. 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")));
  1577. 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));
  1578. }
  1579. }
  1580. // Optional item
  1581. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1582. {
  1583. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1584. }
  1585. else
  1586. {
  1587. sprintf((char*)maxProfile.ValidFrom, " ");
  1588. }
  1589. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1590. {
  1591. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1592. }
  1593. else
  1594. {
  1595. sprintf((char*)maxProfile.ValidTo, " ");
  1596. }
  1597. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1598. {
  1599. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1600. }
  1601. else
  1602. {
  1603. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1604. }
  1605. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1606. {
  1607. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1608. }
  1609. else
  1610. {
  1611. maxProfile.TransactionId = -1;
  1612. }
  1613. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1614. {
  1615. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1616. }
  1617. else
  1618. {
  1619. maxProfile.ChargingSchedule.Duration = 86400;
  1620. }
  1621. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1622. {
  1623. 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")));
  1624. }
  1625. else
  1626. {
  1627. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1628. }
  1629. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1630. {
  1631. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1632. }
  1633. else
  1634. {
  1635. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1636. }
  1637. }
  1638. }
  1639. }
  1640. else
  1641. {
  1642. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1643. {
  1644. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1645. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1646. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1647. }
  1648. maxProfile.ChargingProfileId = -1;
  1649. maxProfile.StackLevel = -1;
  1650. if(maxProfile.ChargingProfileId == -1)
  1651. DEBUG_INFO("MaxProfile found.\n");
  1652. else
  1653. DEBUG_INFO("MaxProfile updated.\n");
  1654. // Required item
  1655. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1656. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1657. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1658. if(isUnitA)
  1659. {
  1660. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1661. 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++)
  1662. {
  1663. 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"));
  1664. 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?
  1665. 3:
  1666. 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")));
  1667. 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")));
  1668. }
  1669. }
  1670. else
  1671. {
  1672. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1673. 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++)
  1674. {
  1675. 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"));
  1676. 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?
  1677. 3:
  1678. 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")));
  1679. 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));
  1680. }
  1681. }
  1682. // Optional item
  1683. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1684. {
  1685. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1686. }
  1687. else
  1688. {
  1689. sprintf((char*)maxProfile.ValidFrom, " ");
  1690. }
  1691. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1692. {
  1693. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1694. }
  1695. else
  1696. {
  1697. sprintf((char*)maxProfile.ValidTo, " ");
  1698. }
  1699. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1700. {
  1701. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1702. }
  1703. else
  1704. {
  1705. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1706. }
  1707. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1708. {
  1709. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1710. }
  1711. else
  1712. {
  1713. maxProfile.TransactionId = -1;
  1714. }
  1715. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1716. {
  1717. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1718. }
  1719. else
  1720. {
  1721. maxProfile.ChargingSchedule.Duration = 86400;
  1722. }
  1723. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1724. {
  1725. 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")));
  1726. }
  1727. else
  1728. {
  1729. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1730. }
  1731. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1732. {
  1733. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1734. }
  1735. else
  1736. {
  1737. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1738. }
  1739. }
  1740. }
  1741. }
  1742. json_object_put(obj);
  1743. }
  1744. fclose(fp);
  1745. /*
  1746. if(maxProfile.ChargingProfileId !=-1)
  1747. {
  1748. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1749. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1750. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1751. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1752. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1753. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1754. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1755. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1756. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1757. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1758. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1759. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1760. {
  1761. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1762. {
  1763. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1764. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1765. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1766. }
  1767. }
  1768. }
  1769. else
  1770. DEBUG_INFO("MaxProfile not found.\n");
  1771. DEBUG_INFO("------------------------------------\n");*/
  1772. }
  1773. if(maxProfile.ChargingProfileId != -1)
  1774. {
  1775. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1776. {
  1777. if(maxProfile.ChargingSchedule.Duration != -1)
  1778. {
  1779. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1780. 0:
  1781. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1782. }
  1783. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1784. {
  1785. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1786. {
  1787. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1788. 0:
  1789. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1790. if(idxPeriod > 0)
  1791. {
  1792. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1793. {
  1794. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1795. }
  1796. }
  1797. }
  1798. }
  1799. }
  1800. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1801. {
  1802. if(maxProfile.ChargingSchedule.Duration != -1)
  1803. {
  1804. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1805. }
  1806. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1807. {
  1808. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1809. {
  1810. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1811. if(idxPeriod > 0)
  1812. {
  1813. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1814. {
  1815. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1816. }
  1817. }
  1818. }
  1819. }
  1820. }
  1821. else
  1822. {
  1823. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1824. {
  1825. if(maxProfile.ChargingSchedule.Duration != -1)
  1826. {
  1827. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1828. 0:
  1829. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1830. }
  1831. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1832. {
  1833. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1834. {
  1835. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1836. 0:
  1837. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1838. if(idxPeriod > 0)
  1839. {
  1840. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1841. {
  1842. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1843. }
  1844. }
  1845. }
  1846. }
  1847. }
  1848. else
  1849. {
  1850. if(maxProfile.ChargingSchedule.Duration != -1)
  1851. {
  1852. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1853. 0:
  1854. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1855. }
  1856. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1857. {
  1858. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1859. {
  1860. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1861. 0:
  1862. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1863. if(idxPeriod > 0)
  1864. {
  1865. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1866. {
  1867. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1868. }
  1869. }
  1870. }
  1871. }
  1872. }
  1873. }
  1874. /*
  1875. DEBUG_INFO("MaxProfile after align.\n");
  1876. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1877. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1878. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1879. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1880. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1881. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1882. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1883. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1884. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1885. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1886. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1887. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1888. {
  1889. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1890. {
  1891. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1892. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1893. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1894. }
  1895. }
  1896. DEBUG_INFO("------------------------------------\n");*/
  1897. }
  1898. // Find each profile period quantity
  1899. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1900. {
  1901. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1902. limitMax = idx+1;
  1903. }
  1904. if(maxProfile.ChargingProfileId != -1)
  1905. {
  1906. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1907. {
  1908. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1909. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1910. (maxProfile.ChargingSchedule.Duration > 0))
  1911. {
  1912. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1913. {
  1914. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1915. compositePeriodIdx++;
  1916. }
  1917. else
  1918. {
  1919. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1920. }
  1921. }
  1922. }
  1923. }
  1924. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1925. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1926. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1927. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1928. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1929. {
  1930. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1931. {
  1932. compositeProfile->ChargingProfileId = 1;
  1933. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1934. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1935. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1936. }
  1937. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1938. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1939. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1940. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1941. }
  1942. if(line)
  1943. free(line);
  1944. }
  1945. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1946. {
  1947. FILE *fp;
  1948. char profileFileName[128];
  1949. char *line = NULL;
  1950. size_t len = 0;
  1951. time_t CurrentTime;
  1952. struct tm *tmComposite;
  1953. struct StructChargingProfile maxProfile;
  1954. struct StructChargingProfile defaultTxProfile;
  1955. struct StructChargingProfile txProfile;
  1956. struct StructChargingSchedulePeriod tmpPeriod;
  1957. uint8_t limitMax=0;
  1958. uint8_t limitDef=0;
  1959. uint8_t limitTx=0;
  1960. int compositePeriodIdx = 0;
  1961. CurrentTime = time(NULL);
  1962. tmComposite=localtime(&CurrentTime);
  1963. 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);
  1964. if(isUnitA)
  1965. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1966. else
  1967. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1968. compositeProfile->ChargingSchedule.Duration = durationReq;
  1969. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1970. {
  1971. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1972. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1973. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1974. }
  1975. compositeProfile->ChargingProfileId = 0;
  1976. compositeProfile->StackLevel = 99 ;
  1977. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1978. maxProfile.ChargingProfileId = -1;
  1979. defaultTxProfile.ChargingProfileId = -1;
  1980. txProfile.ChargingProfileId = -1;
  1981. maxProfile.ChargingSchedule.Duration = -1;
  1982. defaultTxProfile.ChargingSchedule.Duration = -1;
  1983. txProfile.ChargingSchedule.Duration = -1;
  1984. system("rm -f /tmp/*.json");
  1985. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1986. /*
  1987. * Search valid charging profile
  1988. */
  1989. //DEBUG_INFO("====================================\n");
  1990. // Search tx profile
  1991. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1992. if((access(profileFileName, F_OK))!=-1)
  1993. {
  1994. fp = fopen(profileFileName, "r");
  1995. while(getline(&line, &len, fp) != -1)
  1996. {
  1997. json_object *obj = NULL;
  1998. obj = json_tokener_parse(line);
  1999. if(is_error(obj))
  2000. {
  2001. DEBUG_ERROR("Parse txProfile from file error.\n");
  2002. }
  2003. else
  2004. {
  2005. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2006. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2007. )
  2008. {
  2009. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2010. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2011. )
  2012. {
  2013. struct tm tmFrom, tmTo;
  2014. struct timeb tbFrom, tbTo;
  2015. 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) &&
  2016. (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))
  2017. {
  2018. tmFrom.tm_year -= 1900;
  2019. tmFrom.tm_mon -= 1;
  2020. tbFrom.time = mktime(&tmFrom);
  2021. tmTo.tm_year -= 1900;
  2022. tmTo.tm_mon -= 1;
  2023. tbTo.time = mktime(&tmTo);
  2024. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2025. {
  2026. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2027. {
  2028. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2029. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2030. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2031. }
  2032. txProfile.ChargingProfileId = -1;
  2033. txProfile.StackLevel = -1;
  2034. if(txProfile.ChargingProfileId == -1)
  2035. DEBUG_INFO("TxProfile found.\n");
  2036. else
  2037. DEBUG_INFO("TxProfile updated.\n");
  2038. // Required item
  2039. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2040. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2041. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2042. if(isUnitA)
  2043. {
  2044. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2045. 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++)
  2046. {
  2047. 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"));
  2048. 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?
  2049. 3:
  2050. 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")));
  2051. 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")));
  2052. }
  2053. }
  2054. else
  2055. {
  2056. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2057. 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++)
  2058. {
  2059. 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"));
  2060. 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?
  2061. 3:
  2062. 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")));
  2063. 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));
  2064. }
  2065. }
  2066. // Optional item
  2067. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2068. {
  2069. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2070. }
  2071. else
  2072. {
  2073. sprintf((char*)txProfile.ValidFrom, " ");
  2074. }
  2075. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2076. {
  2077. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2078. }
  2079. else
  2080. {
  2081. sprintf((char*)txProfile.ValidTo, " ");
  2082. }
  2083. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2084. {
  2085. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2086. }
  2087. else
  2088. {
  2089. sprintf((char*)txProfile.RecurrencyKind, " ");
  2090. }
  2091. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2092. {
  2093. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2094. }
  2095. else
  2096. {
  2097. txProfile.TransactionId = -1;
  2098. }
  2099. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2100. {
  2101. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2102. }
  2103. else
  2104. {
  2105. txProfile.ChargingSchedule.Duration = 86400;
  2106. }
  2107. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2108. {
  2109. 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")));
  2110. }
  2111. else
  2112. {
  2113. 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));
  2114. }
  2115. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2116. {
  2117. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2118. }
  2119. else
  2120. {
  2121. txProfile.ChargingSchedule.MinChargingRate = -1;
  2122. }
  2123. }
  2124. }
  2125. }
  2126. else
  2127. {
  2128. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2129. {
  2130. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2131. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2132. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2133. }
  2134. txProfile.ChargingProfileId = -1;
  2135. txProfile.StackLevel = -1;
  2136. if(txProfile.ChargingProfileId == -1)
  2137. DEBUG_INFO("TxProfile found.\n");
  2138. else
  2139. DEBUG_INFO("TxProfile updated.\n");
  2140. // Required item
  2141. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2142. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2143. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2144. if(isUnitA)
  2145. {
  2146. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2147. 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++)
  2148. {
  2149. 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"));
  2150. 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?
  2151. 3:
  2152. 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")));
  2153. 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")));
  2154. }
  2155. }
  2156. else
  2157. {
  2158. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2159. 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++)
  2160. {
  2161. 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"));
  2162. 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?
  2163. 3:
  2164. 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")));
  2165. 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));
  2166. }
  2167. }
  2168. // Optional item
  2169. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2170. {
  2171. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2172. }
  2173. else
  2174. {
  2175. sprintf((char*)txProfile.ValidFrom, " ");
  2176. }
  2177. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2178. {
  2179. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2180. }
  2181. else
  2182. {
  2183. sprintf((char*)txProfile.ValidTo, " ");
  2184. }
  2185. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2186. {
  2187. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2188. }
  2189. else
  2190. {
  2191. sprintf((char*)txProfile.RecurrencyKind, " ");
  2192. }
  2193. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2194. {
  2195. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2196. }
  2197. else
  2198. {
  2199. txProfile.TransactionId = -1;
  2200. }
  2201. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2202. {
  2203. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2204. }
  2205. else
  2206. {
  2207. txProfile.ChargingSchedule.Duration = 86400;
  2208. }
  2209. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2210. {
  2211. 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")));
  2212. }
  2213. else
  2214. {
  2215. 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));
  2216. }
  2217. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2218. {
  2219. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2220. }
  2221. else
  2222. {
  2223. txProfile.ChargingSchedule.MinChargingRate = -1;
  2224. }
  2225. }
  2226. }
  2227. }
  2228. json_object_put(obj);
  2229. }
  2230. fclose(fp);
  2231. /*
  2232. if(txProfile.ChargingProfileId != -1)
  2233. {
  2234. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2235. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2236. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2237. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2238. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2239. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2240. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2241. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2242. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2243. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2244. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2245. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2246. {
  2247. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2248. {
  2249. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2250. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2251. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2252. }
  2253. }
  2254. }
  2255. else
  2256. DEBUG_INFO("TxProfile not found.\n");*/
  2257. }
  2258. // Search default tx profile
  2259. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2260. if((access(profileFileName, F_OK))==-1)
  2261. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2262. if((access(profileFileName, F_OK))!=-1)
  2263. {
  2264. fp = fopen(profileFileName, "r");
  2265. while(getline(&line, &len, fp) != -1)
  2266. {
  2267. json_object *obj = NULL;
  2268. obj = json_tokener_parse(line);
  2269. if(is_error(obj))
  2270. {
  2271. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2272. }
  2273. else
  2274. {
  2275. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2276. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2277. )
  2278. {
  2279. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2280. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2281. )
  2282. {
  2283. struct tm tmFrom, tmTo;
  2284. struct timeb tbFrom, tbTo;
  2285. 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) &&
  2286. (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))
  2287. {
  2288. tmFrom.tm_year -= 1900;
  2289. tmFrom.tm_mon -= 1;
  2290. tbFrom.time = mktime(&tmFrom);
  2291. tmTo.tm_year -= 1900;
  2292. tmTo.tm_mon -= 1;
  2293. tbTo.time = mktime(&tmTo);
  2294. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2295. {
  2296. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2297. {
  2298. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2299. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2300. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2301. }
  2302. defaultTxProfile.ChargingProfileId = -1;
  2303. defaultTxProfile.StackLevel = -1;
  2304. if(defaultTxProfile.ChargingProfileId == -1)
  2305. DEBUG_INFO("TxDefaultProfile found.\n");
  2306. else
  2307. DEBUG_INFO("TxDefaultProfile updated.\n");
  2308. // Required item
  2309. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2310. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2311. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2312. if(isUnitA)
  2313. {
  2314. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2315. 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++)
  2316. {
  2317. 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"));
  2318. 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?
  2319. 3:
  2320. 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")));
  2321. 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")));
  2322. }
  2323. }
  2324. else
  2325. {
  2326. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2327. 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++)
  2328. {
  2329. 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"));
  2330. 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?
  2331. 3:
  2332. 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")));
  2333. 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));
  2334. }
  2335. }
  2336. // Optional item
  2337. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2338. {
  2339. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2340. }
  2341. else
  2342. {
  2343. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2344. }
  2345. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2346. {
  2347. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2348. }
  2349. else
  2350. {
  2351. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2352. }
  2353. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2354. {
  2355. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2356. }
  2357. else
  2358. {
  2359. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2360. }
  2361. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2362. {
  2363. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2364. }
  2365. else
  2366. {
  2367. defaultTxProfile.TransactionId = -1;
  2368. }
  2369. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2370. {
  2371. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2372. }
  2373. else
  2374. {
  2375. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2376. }
  2377. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2378. {
  2379. 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")));
  2380. }
  2381. else
  2382. {
  2383. 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));
  2384. }
  2385. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2386. {
  2387. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2388. }
  2389. else
  2390. {
  2391. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2392. }
  2393. }
  2394. }
  2395. }
  2396. else
  2397. {
  2398. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2399. {
  2400. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2401. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2402. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2403. }
  2404. defaultTxProfile.ChargingProfileId = -1;
  2405. defaultTxProfile.StackLevel = -1;
  2406. if(defaultTxProfile.ChargingProfileId == -1)
  2407. DEBUG_INFO("TxDefaultProfile found.\n");
  2408. else
  2409. DEBUG_INFO("TxDefaultProfile updated.\n");
  2410. // Required item
  2411. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2412. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2413. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2414. if(isUnitA)
  2415. {
  2416. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2417. 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++)
  2418. {
  2419. 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"));
  2420. 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?
  2421. 3:
  2422. 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")));
  2423. 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")));
  2424. }
  2425. }
  2426. else
  2427. {
  2428. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2429. 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++)
  2430. {
  2431. 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"));
  2432. 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?
  2433. 3:
  2434. 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")));
  2435. 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));
  2436. }
  2437. }
  2438. // Optional item
  2439. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2440. {
  2441. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2442. }
  2443. else
  2444. {
  2445. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2446. }
  2447. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2448. {
  2449. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2450. }
  2451. else
  2452. {
  2453. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2454. }
  2455. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2456. {
  2457. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2458. }
  2459. else
  2460. {
  2461. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2462. }
  2463. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2464. {
  2465. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2466. }
  2467. else
  2468. {
  2469. defaultTxProfile.TransactionId = -1;
  2470. }
  2471. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2472. {
  2473. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2474. }
  2475. else
  2476. {
  2477. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2478. }
  2479. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2480. {
  2481. 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")));
  2482. }
  2483. else
  2484. {
  2485. 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));
  2486. }
  2487. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2488. {
  2489. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2490. }
  2491. else
  2492. {
  2493. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2494. }
  2495. }
  2496. }
  2497. }
  2498. json_object_put(obj);
  2499. }
  2500. fclose(fp);
  2501. /*
  2502. if(defaultTxProfile.ChargingProfileId != -1)
  2503. {
  2504. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2505. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2506. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2507. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2508. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2509. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2510. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2511. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2512. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2513. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2514. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2515. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2516. {
  2517. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2518. {
  2519. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2520. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2521. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2522. }
  2523. }
  2524. }
  2525. else
  2526. DEBUG_INFO("TxDefaultProfile not found.\n");
  2527. DEBUG_INFO("------------------------------------\n");*/
  2528. }
  2529. // Search max profile
  2530. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2531. if((access(profileFileName, F_OK))!=-1)
  2532. {
  2533. fp = fopen(profileFileName, "r");
  2534. while(getline(&line, &len, fp) != -1)
  2535. {
  2536. json_object *obj = NULL;
  2537. obj = json_tokener_parse(line);
  2538. if(is_error(obj))
  2539. {
  2540. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2541. }
  2542. else
  2543. {
  2544. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2545. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2546. )
  2547. {
  2548. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2549. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2550. )
  2551. {
  2552. struct tm tmFrom, tmTo;
  2553. struct timeb tbFrom, tbTo;
  2554. 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) &&
  2555. (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))
  2556. {
  2557. tmFrom.tm_year -= 1900;
  2558. tmFrom.tm_mon -= 1;
  2559. tbFrom.time = mktime(&tmFrom);
  2560. tmTo.tm_year -= 1900;
  2561. tmTo.tm_mon -= 1;
  2562. tbTo.time = mktime(&tmTo);
  2563. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2564. {
  2565. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2566. {
  2567. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2568. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2569. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2570. }
  2571. maxProfile.ChargingProfileId = -1;
  2572. maxProfile.StackLevel = -1;
  2573. if(maxProfile.ChargingProfileId == -1)
  2574. DEBUG_INFO("MaxProfile found.\n");
  2575. else
  2576. DEBUG_INFO("MaxProfile updated.\n");
  2577. // Required item
  2578. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2579. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2580. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2581. if(isUnitA)
  2582. {
  2583. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2584. 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++)
  2585. {
  2586. 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"));
  2587. 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?
  2588. 3:
  2589. 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")));
  2590. 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")));
  2591. }
  2592. }
  2593. else
  2594. {
  2595. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2596. 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++)
  2597. {
  2598. 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"));
  2599. 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?
  2600. 3:
  2601. 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")));
  2602. 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));
  2603. }
  2604. }
  2605. // Optional item
  2606. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2607. {
  2608. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2609. }
  2610. else
  2611. {
  2612. sprintf((char*)maxProfile.ValidFrom, " ");
  2613. }
  2614. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2615. {
  2616. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2617. }
  2618. else
  2619. {
  2620. sprintf((char*)maxProfile.ValidTo, " ");
  2621. }
  2622. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2623. {
  2624. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2625. }
  2626. else
  2627. {
  2628. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2629. }
  2630. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2631. {
  2632. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2633. }
  2634. else
  2635. {
  2636. maxProfile.TransactionId = -1;
  2637. }
  2638. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2639. {
  2640. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2641. }
  2642. else
  2643. {
  2644. maxProfile.ChargingSchedule.Duration = 86400;
  2645. }
  2646. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2647. {
  2648. 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")));
  2649. }
  2650. else
  2651. {
  2652. 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));
  2653. }
  2654. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2655. {
  2656. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2657. }
  2658. else
  2659. {
  2660. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2661. }
  2662. }
  2663. }
  2664. }
  2665. else
  2666. {
  2667. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2668. {
  2669. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2670. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2671. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2672. }
  2673. maxProfile.ChargingProfileId = -1;
  2674. maxProfile.StackLevel = -1;
  2675. if(maxProfile.ChargingProfileId == -1)
  2676. DEBUG_INFO("MaxProfile found.\n");
  2677. else
  2678. DEBUG_INFO("MaxProfile updated.\n");
  2679. // Required item
  2680. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2681. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2682. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2683. if(isUnitA)
  2684. {
  2685. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2686. 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++)
  2687. {
  2688. 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"));
  2689. 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?
  2690. 3:
  2691. 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")));
  2692. 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")));
  2693. }
  2694. }
  2695. else
  2696. {
  2697. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2698. 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++)
  2699. {
  2700. 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"));
  2701. 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?
  2702. 3:
  2703. 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")));
  2704. 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));
  2705. }
  2706. }
  2707. // Optional item
  2708. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2709. {
  2710. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2711. }
  2712. else
  2713. {
  2714. sprintf((char*)maxProfile.ValidFrom, " ");
  2715. }
  2716. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2717. {
  2718. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2719. }
  2720. else
  2721. {
  2722. sprintf((char*)maxProfile.ValidTo, " ");
  2723. }
  2724. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2725. {
  2726. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2727. }
  2728. else
  2729. {
  2730. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2731. }
  2732. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2733. {
  2734. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2735. }
  2736. else
  2737. {
  2738. maxProfile.TransactionId = -1;
  2739. }
  2740. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2741. {
  2742. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2743. }
  2744. else
  2745. {
  2746. maxProfile.ChargingSchedule.Duration = 86400;
  2747. }
  2748. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2749. {
  2750. 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")));
  2751. }
  2752. else
  2753. {
  2754. 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));
  2755. }
  2756. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2757. {
  2758. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2759. }
  2760. else
  2761. {
  2762. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2763. }
  2764. }
  2765. }
  2766. }
  2767. json_object_put(obj);
  2768. }
  2769. fclose(fp);
  2770. /*
  2771. if(maxProfile.ChargingProfileId !=-1)
  2772. {
  2773. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2774. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2775. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2776. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2777. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2778. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2779. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2780. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2781. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2782. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2783. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2784. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2785. {
  2786. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2787. {
  2788. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2789. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2790. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2791. }
  2792. }
  2793. }
  2794. else
  2795. DEBUG_INFO("MaxProfile not found.\n");
  2796. DEBUG_INFO("------------------------------------\n");*/
  2797. }
  2798. /*
  2799. * Align found profile start schedule & periods
  2800. */
  2801. //DEBUG_INFO("====================================\n");
  2802. /*
  2803. // For local test usage, force modify found profile start schedule info
  2804. 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);
  2805. 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);
  2806. 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);
  2807. */
  2808. if(txProfile.ChargingProfileId != -1)
  2809. {
  2810. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2811. {
  2812. if(txProfile.ChargingSchedule.Duration != -1)
  2813. {
  2814. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2815. 0:
  2816. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2817. }
  2818. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2819. {
  2820. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2821. {
  2822. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2823. 0:
  2824. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2825. if(idxPeriod > 0)
  2826. {
  2827. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2828. {
  2829. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2830. }
  2831. }
  2832. }
  2833. }
  2834. }
  2835. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2836. {
  2837. if(txProfile.ChargingSchedule.Duration != -1)
  2838. {
  2839. 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?
  2840. 0:
  2841. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2842. }
  2843. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2844. {
  2845. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2846. {
  2847. 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?
  2848. 0:
  2849. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2850. if(idxPeriod > 0)
  2851. {
  2852. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2853. {
  2854. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2855. }
  2856. }
  2857. }
  2858. }
  2859. }
  2860. else
  2861. {
  2862. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2863. {
  2864. if(txProfile.ChargingSchedule.Duration != -1)
  2865. {
  2866. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2867. 0:
  2868. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2869. }
  2870. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2871. {
  2872. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2873. {
  2874. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2875. 0:
  2876. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2877. if(idxPeriod > 0)
  2878. {
  2879. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2880. {
  2881. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2882. }
  2883. }
  2884. }
  2885. }
  2886. }
  2887. else
  2888. {
  2889. if(txProfile.ChargingSchedule.Duration != -1)
  2890. {
  2891. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2892. 0:
  2893. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2894. }
  2895. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2896. {
  2897. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2898. {
  2899. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2900. 0:
  2901. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2902. if(idxPeriod > 0)
  2903. {
  2904. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2905. {
  2906. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2907. }
  2908. }
  2909. }
  2910. }
  2911. }
  2912. }
  2913. /*
  2914. DEBUG_INFO("txProfile after align.\n");
  2915. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2916. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2917. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2918. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2919. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2920. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2921. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2922. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2923. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2924. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2925. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2926. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2927. {
  2928. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2929. {
  2930. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2931. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2932. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2933. }
  2934. }*/
  2935. }
  2936. if(defaultTxProfile.ChargingProfileId != -1)
  2937. {
  2938. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2939. {
  2940. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2941. {
  2942. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2943. 0:
  2944. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2945. }
  2946. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2947. {
  2948. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2949. {
  2950. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2951. 0:
  2952. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2953. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2954. {
  2955. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2956. }
  2957. if(idxPeriod > 0)
  2958. {
  2959. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2960. {
  2961. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2962. }
  2963. }
  2964. }
  2965. }
  2966. }
  2967. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2968. {
  2969. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2970. {
  2971. 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?
  2972. 0:
  2973. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2974. }
  2975. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2976. {
  2977. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2978. {
  2979. 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?
  2980. 0:
  2981. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2982. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2983. {
  2984. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2985. }
  2986. if(idxPeriod > 0)
  2987. {
  2988. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2989. {
  2990. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2991. }
  2992. }
  2993. }
  2994. }
  2995. }
  2996. else
  2997. {
  2998. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2999. {
  3000. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3001. {
  3002. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  3003. 0:
  3004. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  3005. }
  3006. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3007. {
  3008. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3009. {
  3010. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  3011. 0:
  3012. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  3013. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  3014. {
  3015. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3016. }
  3017. if(idxPeriod > 0)
  3018. {
  3019. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3020. {
  3021. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3022. }
  3023. }
  3024. }
  3025. }
  3026. }
  3027. else
  3028. {
  3029. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3030. {
  3031. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  3032. 0:
  3033. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  3034. }
  3035. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3036. {
  3037. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3038. {
  3039. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  3040. 0:
  3041. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  3042. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  3043. {
  3044. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3045. }
  3046. if(idxPeriod > 0)
  3047. {
  3048. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3049. {
  3050. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3051. }
  3052. }
  3053. }
  3054. }
  3055. }
  3056. }
  3057. /*
  3058. DEBUG_INFO("defaultTxProfile after align.\n");
  3059. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3060. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3061. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3062. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3063. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3064. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3065. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3066. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3067. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3068. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3069. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3070. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3071. {
  3072. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3073. {
  3074. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3075. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3076. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3077. }
  3078. }
  3079. DEBUG_INFO("------------------------------------\n");*/
  3080. }
  3081. if(maxProfile.ChargingProfileId != -1)
  3082. {
  3083. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3084. {
  3085. if(maxProfile.ChargingSchedule.Duration != -1)
  3086. {
  3087. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  3088. 0:
  3089. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  3090. }
  3091. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3092. {
  3093. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3094. {
  3095. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  3096. 0:
  3097. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  3098. if(idxPeriod > 0)
  3099. {
  3100. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3101. {
  3102. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3103. }
  3104. }
  3105. }
  3106. }
  3107. }
  3108. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3109. {
  3110. if(maxProfile.ChargingSchedule.Duration != -1)
  3111. {
  3112. 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?
  3113. 0:
  3114. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  3115. }
  3116. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3117. {
  3118. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3119. {
  3120. 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?
  3121. 0:
  3122. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  3123. if(idxPeriod > 0)
  3124. {
  3125. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3126. {
  3127. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3128. }
  3129. }
  3130. }
  3131. }
  3132. }
  3133. else
  3134. {
  3135. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3136. {
  3137. if(maxProfile.ChargingSchedule.Duration != -1)
  3138. {
  3139. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  3140. 0:
  3141. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  3142. }
  3143. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3144. {
  3145. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3146. {
  3147. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  3148. 0:
  3149. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  3150. if(idxPeriod > 0)
  3151. {
  3152. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3153. {
  3154. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3155. }
  3156. }
  3157. }
  3158. }
  3159. }
  3160. else
  3161. {
  3162. if(maxProfile.ChargingSchedule.Duration != -1)
  3163. {
  3164. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  3165. 0:
  3166. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  3167. }
  3168. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3169. {
  3170. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3171. {
  3172. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  3173. 0:
  3174. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  3175. if(idxPeriod > 0)
  3176. {
  3177. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3178. {
  3179. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3180. }
  3181. }
  3182. }
  3183. }
  3184. }
  3185. }
  3186. /*
  3187. DEBUG_INFO("MaxProfile after align.\n");
  3188. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3189. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3190. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3191. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3192. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3193. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3194. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3195. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3196. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3197. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3198. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3199. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3200. {
  3201. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3202. {
  3203. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3204. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3205. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3206. }
  3207. }
  3208. DEBUG_INFO("------------------------------------\n");*/
  3209. }
  3210. /*
  3211. * Merge to conposite schedule
  3212. */
  3213. //DEBUG_INFO("====================================\n");
  3214. // Find each profile period quantity
  3215. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3216. {
  3217. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3218. limitMax = idx+1;
  3219. }
  3220. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3221. {
  3222. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3223. limitDef = idx+1;
  3224. }
  3225. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3226. {
  3227. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3228. limitTx = idx+1;
  3229. }
  3230. // TxProfile found, composite schedule based on it
  3231. if(txProfile.ChargingProfileId != -1)
  3232. {
  3233. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3234. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3235. {
  3236. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3237. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3238. (txProfile.ChargingSchedule.Duration > 0))
  3239. {
  3240. if(maxProfile.ChargingProfileId != -1)
  3241. {
  3242. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3243. {
  3244. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3245. {
  3246. if((maxProfile.ChargingSchedule.Duration > 0))
  3247. {
  3248. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3249. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3250. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3251. }
  3252. else
  3253. {
  3254. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3255. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3256. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3257. }
  3258. }
  3259. if(idxMaxPeriod == (limitMax-1))
  3260. {
  3261. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3262. {
  3263. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3264. {
  3265. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3266. compositePeriodIdx++;
  3267. }
  3268. else
  3269. {
  3270. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3271. }
  3272. }
  3273. }
  3274. }
  3275. }
  3276. else
  3277. {
  3278. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3279. {
  3280. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3281. compositePeriodIdx++;
  3282. }
  3283. else
  3284. {
  3285. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3286. }
  3287. }
  3288. }
  3289. if(idxTxPeriod == (limitTx-1))
  3290. {
  3291. if(defaultTxProfile.ChargingProfileId != -1)
  3292. {
  3293. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  3294. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3295. {
  3296. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3297. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3298. (defaultTxProfile.ChargingSchedule.Duration>0))
  3299. {
  3300. if(maxProfile.ChargingProfileId != -1)
  3301. {
  3302. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3303. {
  3304. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3305. {
  3306. if((maxProfile.ChargingSchedule.Duration > 0))
  3307. {
  3308. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3309. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3310. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3311. }
  3312. else
  3313. {
  3314. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3315. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3316. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3317. }
  3318. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3319. {
  3320. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3321. {
  3322. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3323. compositePeriodIdx++;
  3324. }
  3325. else
  3326. {
  3327. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3328. }
  3329. }
  3330. // Delete duplicate period
  3331. if(compositePeriodIdx > 1)
  3332. {
  3333. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3334. {
  3335. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3336. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3337. compositePeriodIdx -= 1;
  3338. }
  3339. }
  3340. }
  3341. else
  3342. {
  3343. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3344. {
  3345. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3346. compositePeriodIdx++;
  3347. }
  3348. else
  3349. {
  3350. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3351. }
  3352. break;
  3353. }
  3354. }
  3355. }
  3356. else
  3357. {
  3358. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3359. {
  3360. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3361. compositePeriodIdx++;
  3362. }
  3363. else
  3364. {
  3365. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3366. }
  3367. }
  3368. }
  3369. }
  3370. }
  3371. }
  3372. }
  3373. }
  3374. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3375. else if(defaultTxProfile.ChargingProfileId != -1)
  3376. {
  3377. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3378. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3379. {
  3380. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3381. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3382. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3383. {
  3384. if(maxProfile.ChargingProfileId != -1)
  3385. {
  3386. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3387. {
  3388. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3389. {
  3390. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3391. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3392. if((maxProfile.ChargingSchedule.Duration > 0))
  3393. {
  3394. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3395. }
  3396. else
  3397. {
  3398. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3399. }
  3400. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3401. {
  3402. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3403. {
  3404. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3405. compositePeriodIdx++;
  3406. }
  3407. else
  3408. {
  3409. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3410. }
  3411. }
  3412. // Delete duplicate period
  3413. if(compositePeriodIdx > 1)
  3414. {
  3415. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3416. {
  3417. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3418. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3419. compositePeriodIdx -= 1;
  3420. }
  3421. }
  3422. }
  3423. else
  3424. {
  3425. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3426. {
  3427. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3428. compositePeriodIdx++;
  3429. }
  3430. else
  3431. {
  3432. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3433. }
  3434. break;
  3435. }
  3436. }
  3437. }
  3438. else
  3439. {
  3440. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3441. {
  3442. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3443. compositePeriodIdx++;
  3444. }
  3445. else
  3446. {
  3447. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3448. }
  3449. }
  3450. }
  3451. }
  3452. }
  3453. // Fill other period by MaxProfile
  3454. if(maxProfile.ChargingProfileId != -1)
  3455. {
  3456. if(compositePeriodIdx==0)
  3457. {
  3458. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3459. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3460. {
  3461. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3462. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3463. (maxProfile.ChargingSchedule.Duration > 0))
  3464. {
  3465. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3466. {
  3467. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3468. compositePeriodIdx++;
  3469. }
  3470. else
  3471. {
  3472. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3473. }
  3474. }
  3475. }
  3476. }
  3477. else
  3478. {
  3479. int lastCompositePeriodIdx = compositePeriodIdx;
  3480. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3481. {
  3482. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3483. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3484. (maxProfile.ChargingSchedule.Duration > 0))
  3485. {
  3486. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3487. {
  3488. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3489. {
  3490. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3491. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3492. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3493. }
  3494. else
  3495. {
  3496. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3497. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3498. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3499. }
  3500. }
  3501. if(tmpPeriod.Limit != -1)
  3502. {
  3503. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3504. {
  3505. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3506. {
  3507. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3508. compositePeriodIdx++;
  3509. }
  3510. else
  3511. {
  3512. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3513. }
  3514. }
  3515. // Delete duplicate period
  3516. if(compositePeriodIdx > 1)
  3517. {
  3518. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3519. {
  3520. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3521. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3522. compositePeriodIdx -= 1;
  3523. }
  3524. }
  3525. }
  3526. }
  3527. }
  3528. }
  3529. }
  3530. compositeProfile->ChargingSchedule.Duration = durationReq;
  3531. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3532. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3533. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3534. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3535. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3536. {
  3537. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3538. {
  3539. compositeProfile->ChargingProfileId = 1;
  3540. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3541. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3542. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3543. }
  3544. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3545. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3546. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3547. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3548. }
  3549. if(line)
  3550. free(line);
  3551. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3552. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3553. }
  3554. //==========================================
  3555. // Init all share memory
  3556. //==========================================
  3557. int InitShareMemory()
  3558. {
  3559. int result = PASS;
  3560. int MeterSMId;
  3561. //creat ShmSysConfigAndInfo
  3562. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3563. {
  3564. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3565. result = FAIL;
  3566. }
  3567. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3568. {
  3569. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3570. result = FAIL;
  3571. }
  3572. else
  3573. {}
  3574. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3575. {
  3576. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3577. result = FAIL;
  3578. }
  3579. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3580. {
  3581. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3582. result = FAIL;
  3583. }
  3584. else
  3585. {}
  3586. //creat ShmPsuData
  3587. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3588. {
  3589. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3590. result = FAIL;
  3591. }
  3592. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3593. {
  3594. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3595. result = FAIL;
  3596. }
  3597. else
  3598. {}
  3599. //creat ShmOCPP16Data
  3600. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3601. {
  3602. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3603. result = FAIL;
  3604. }
  3605. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3606. {
  3607. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3608. result = FAIL;
  3609. }
  3610. else
  3611. {}
  3612. /****************************** For Initial Settings************************************************/
  3613. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3614. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3615. // allocate Configuration memory address
  3616. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3617. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3618. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3619. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3620. //offline MeterValue Interval
  3621. TempMeterValueInterval = 0;
  3622. return result;
  3623. }
  3624. int ProcessShareMemory()
  3625. {
  3626. int result = PASS;
  3627. if(InitShareMemory() == FAIL)
  3628. {
  3629. DEBUG_ERROR("InitShareMemory NG\n");
  3630. if(ShmStatusCodeData!=NULL)
  3631. {
  3632. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3633. }
  3634. result = FAIL;
  3635. }
  3636. // Model name parsing
  3637. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3638. {
  3639. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3640. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3641. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3642. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3643. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3644. ) // 'D' means DC
  3645. {
  3646. // DO series
  3647. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3648. {
  3649. SystemInitial += 1;
  3650. gunTotalNumber += 1;
  3651. gunType[gun_index] = GUN_TYPE_DO;
  3652. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3653. {
  3654. case Gun_Type_Chademo:
  3655. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3656. break;
  3657. case Gun_Type_CCS_2:
  3658. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3659. break;
  3660. case Gun_Type_GB:
  3661. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3662. break;
  3663. case Gun_Type_AC:
  3664. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3665. break;
  3666. default:
  3667. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3668. break;
  3669. }
  3670. }
  3671. }
  3672. else
  3673. {
  3674. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3675. {
  3676. SystemInitial += 1;
  3677. gunTotalNumber += 1;
  3678. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3679. {
  3680. case Gun_Type_Chademo:
  3681. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3682. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3683. break;
  3684. case Gun_Type_CCS_2:
  3685. gunType[gun_index] = GUN_TYPE_CCS;
  3686. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3687. break;
  3688. case Gun_Type_GB:
  3689. gunType[gun_index] = GUN_TYPE_GBT;
  3690. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3691. break;
  3692. case Gun_Type_AC:
  3693. gunType[gun_index] = GUN_TYPE_AC;
  3694. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3695. break;
  3696. default:
  3697. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3698. break;
  3699. }
  3700. }
  3701. }
  3702. }
  3703. else
  3704. {
  3705. DEBUG_ERROR("Model name parsing fail.\n");
  3706. result = FAIL;
  3707. }
  3708. if(result != PASS)sleep(5);
  3709. return result;
  3710. }
  3711. void checkRemoteStart(uint8_t connectorIdInt)
  3712. {
  3713. uint8_t tempIndex;
  3714. int result = PASS;
  3715. char cmdBuf[512];
  3716. //check Transaction active
  3717. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3718. {
  3719. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3720. {
  3721. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3722. }
  3723. else
  3724. {
  3725. tempIndex = connectorIdInt -1;
  3726. }
  3727. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3728. {
  3729. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3730. {
  3731. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3732. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3733. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3734. {
  3735. //Reserved
  3736. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3737. }
  3738. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3739. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3740. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3741. {
  3742. //Reserved
  3743. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3744. result = FAIL;
  3745. goto end;
  3746. }
  3747. else
  3748. {
  3749. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3750. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3751. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3752. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3753. {
  3754. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  3755. result = FAIL;
  3756. goto end;
  3757. }
  3758. }//END FOR ELSE
  3759. }
  3760. }// END FOR CHAdeMO_QUANTITY
  3761. }
  3762. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3763. {
  3764. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3765. {
  3766. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3767. }
  3768. else
  3769. {
  3770. tempIndex = connectorIdInt -1;
  3771. }
  3772. for (int index = 0; index < CCS_QUANTITY; index++)
  3773. {
  3774. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3775. {
  3776. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3777. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3778. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3779. {
  3780. //Reserved
  3781. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3782. }
  3783. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3784. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3785. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3786. {
  3787. //Reserved
  3788. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3789. result = FAIL;
  3790. goto end;
  3791. }
  3792. else
  3793. {
  3794. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3795. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3796. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3797. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3798. {
  3799. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3800. result = FAIL;
  3801. goto end;
  3802. }
  3803. }// END FOR ELSE
  3804. }
  3805. }// END FOR CCS_QUANTITY
  3806. }
  3807. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3808. {
  3809. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3810. {
  3811. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3812. }
  3813. else
  3814. {
  3815. tempIndex = connectorIdInt -1;
  3816. }
  3817. for (int index = 0; index < GB_QUANTITY; index++)
  3818. {
  3819. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3820. {
  3821. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3822. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3823. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3824. {
  3825. //Reserved
  3826. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3827. }
  3828. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3829. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3830. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3831. {
  3832. //Reserved
  3833. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3834. result = FAIL;
  3835. goto end;
  3836. }
  3837. else
  3838. {
  3839. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3840. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3841. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3842. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3843. {
  3844. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  3845. result = FAIL;
  3846. goto end;
  3847. }
  3848. }// END FOR ELSE
  3849. }
  3850. } // END FOR GB_QUANTITY
  3851. }
  3852. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3853. {
  3854. tempIndex = connectorIdInt -1;
  3855. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3856. {
  3857. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3858. {
  3859. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3860. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3861. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3862. {
  3863. //Reserved
  3864. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3865. }
  3866. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3867. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3868. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3869. {
  3870. //Reserved
  3871. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3872. result = FAIL;
  3873. goto end;
  3874. }
  3875. else
  3876. {
  3877. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3878. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3879. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3880. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3881. {
  3882. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  3883. result = FAIL;
  3884. goto end;
  3885. }
  3886. }// END FOR ELSE
  3887. }
  3888. } // END FOR GB_QUANTITY
  3889. }
  3890. else
  3891. {
  3892. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3893. {
  3894. tempIndex = 2;
  3895. }
  3896. else
  3897. {
  3898. tempIndex = connectorIdInt -1;
  3899. }
  3900. for (int index = 0; index < AC_QUANTITY; index++)
  3901. {
  3902. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3903. {
  3904. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3905. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3906. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3907. {
  3908. //Reserved
  3909. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3910. }
  3911. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3912. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3913. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3914. {
  3915. //Reserved
  3916. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3917. result = FAIL;
  3918. goto end;
  3919. }
  3920. else
  3921. {
  3922. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3923. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3924. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3925. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3926. {
  3927. DEBUG_WARN("AC connector not allow start cause busy.\n");
  3928. result = FAIL;
  3929. goto end;
  3930. }
  3931. }//END FOR ELSE
  3932. }
  3933. }// END FOR AC_QUANTITY
  3934. }
  3935. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3936. {
  3937. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3938. {
  3939. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  3940. {
  3941. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3942. system(cmdBuf);
  3943. }
  3944. }
  3945. else
  3946. {
  3947. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3948. result = FAIL;
  3949. }
  3950. }
  3951. end:
  3952. if(result == PASS)
  3953. {
  3954. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3955. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3956. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3957. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3958. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3959. }
  3960. }
  3961. void CheckSystemValue(void)
  3962. {
  3963. char filenmae[100]={0};
  3964. char str[100]={0};
  3965. int tempIndex = 0;
  3966. //===============================
  3967. // send Heartbeat
  3968. //===============================
  3969. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3970. {
  3971. //parameter for test
  3972. sendHeartbeatRequest(0);
  3973. //===========================
  3974. // Reset Waiting Time
  3975. //===========================
  3976. HeartBeatWithNOResponse += 1;
  3977. }
  3978. //===============================
  3979. // Credit deduct report
  3980. //===============================
  3981. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  3982. {
  3983. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo, ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice);
  3984. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  3985. }
  3986. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3987. {
  3988. OCPP_query_deduct_info();
  3989. refreshStartTimer(&clientTime.TcciQueryDeduct);
  3990. }
  3991. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3992. {
  3993. // ClockAlign MeterValue
  3994. 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))
  3995. {
  3996. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3997. {
  3998. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3999. {
  4000. tempIndex = ((gun_index==2) ? 1: 0);
  4001. }
  4002. else
  4003. {
  4004. tempIndex = gun_index;
  4005. }
  4006. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4007. {
  4008. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4009. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4010. {
  4011. reqClockAlignMeter[gun_index] = 1;
  4012. }
  4013. }// End for CHAdeMO
  4014. }
  4015. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4016. {
  4017. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4018. {
  4019. tempIndex = ((gun_index==2) ? 1: 0);
  4020. }
  4021. else
  4022. {
  4023. tempIndex = gun_index;
  4024. }
  4025. for (int index = 0; index < CCS_QUANTITY; index++)
  4026. {
  4027. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4028. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4029. {
  4030. reqClockAlignMeter[gun_index] = 1;
  4031. }
  4032. } // End for CCS
  4033. }
  4034. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4035. {
  4036. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4037. {
  4038. tempIndex = ((gun_index==2) ? 1: 0);
  4039. }
  4040. else
  4041. {
  4042. tempIndex = gun_index;
  4043. }
  4044. for (int index = 0; index < GB_QUANTITY; index++)
  4045. {
  4046. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4047. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4048. {
  4049. reqClockAlignMeter[gun_index] = 1;
  4050. }
  4051. }// End for GB
  4052. }
  4053. else if(gunType[gun_index] == GUN_TYPE_DO)
  4054. {
  4055. tempIndex = gun_index;
  4056. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4057. {
  4058. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4059. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4060. {
  4061. reqClockAlignMeter[gun_index] = 1;
  4062. }
  4063. }
  4064. }
  4065. else
  4066. {
  4067. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4068. {
  4069. tempIndex = 2;
  4070. }
  4071. else
  4072. {
  4073. tempIndex = gun_index;
  4074. }
  4075. for (int index = 0; index < AC_QUANTITY; index++)
  4076. {
  4077. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4078. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4079. {
  4080. reqClockAlignMeter[gun_index] = 1;
  4081. }
  4082. }//End for AC
  4083. }
  4084. }
  4085. }
  4086. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4087. {
  4088. //==========================================
  4089. // Check remote start without connector id
  4090. //==========================================
  4091. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4092. {
  4093. int connectorIdInt = -1;
  4094. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4095. {
  4096. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4097. {
  4098. connectorIdInt = (gun_index+1);
  4099. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4100. checkRemoteStart(connectorIdInt);
  4101. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4102. break;
  4103. }
  4104. }
  4105. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4106. {
  4107. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4108. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4109. }
  4110. }
  4111. //==========================================
  4112. // csu trigger DataTransferReq
  4113. //==========================================
  4114. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4115. {
  4116. sendDataTransferRequest(gun_index);
  4117. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4118. }
  4119. //==========================================
  4120. // CSU Trigger Authorize Request
  4121. //==========================================
  4122. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4123. {
  4124. sendAuthorizeRequest(0);
  4125. authorizeRetryTimes = authorizeRetryTimes + 1;
  4126. if(authorizeRetryTimes < 3)
  4127. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4128. }
  4129. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4130. {
  4131. authorizeRetryTimes = 0;
  4132. SetOcppConnStatus(FALSE);
  4133. server_sign = FALSE;
  4134. }
  4135. 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))
  4136. {
  4137. sendAuthorizeRequest(0);
  4138. }
  4139. //==========================================
  4140. // Charger start transaction
  4141. //==========================================
  4142. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4143. {
  4144. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4145. sendStartTransactionRequest(gun_index);
  4146. refreshStartTimer(&clientTime.StartTransaction);
  4147. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4148. storeTempStopTransaction(gun_index);
  4149. }
  4150. //==========================================
  4151. // Charger stop transaction
  4152. //==========================================
  4153. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4154. {
  4155. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4156. sendStopTransactionRequest(gun_index);
  4157. OCPP_updatePeriodEnergy(gun_index);
  4158. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4159. refreshStartTimer(&clientTime.StopTransaction);
  4160. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4161. }
  4162. //==========================================
  4163. // Charger status report
  4164. //==========================================
  4165. //--- Check Mode Change ---//
  4166. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4167. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4168. {
  4169. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4170. {
  4171. tempIndex = ((gun_index==2) ? 1: 0);
  4172. }
  4173. else
  4174. {
  4175. tempIndex = gun_index;
  4176. }
  4177. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4178. {
  4179. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4180. {
  4181. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4182. {
  4183. // Sent unplug message for California pricing logic
  4184. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  4185. {
  4186. uint8_t ts[20];
  4187. getNowDatetime(ts);
  4188. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4189. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4190. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4191. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4192. }
  4193. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4194. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4195. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4196. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4197. {
  4198. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4199. if((access(filenmae,F_OK))!=-1)
  4200. {
  4201. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4202. sprintf(str,"rm -f %s",filenmae);
  4203. system(str);
  4204. }
  4205. }
  4206. }
  4207. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4208. #if 1 // for TempStopTransaction
  4209. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4210. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4211. {
  4212. checkTempStopTransaction(gun_index);
  4213. }
  4214. #endif
  4215. }
  4216. }
  4217. }
  4218. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4219. {
  4220. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4221. {
  4222. tempIndex = ((gun_index==2) ? 1: 0);
  4223. }
  4224. else
  4225. {
  4226. tempIndex = gun_index;
  4227. }
  4228. for (int index = 0; index < CCS_QUANTITY; index++)
  4229. {
  4230. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4231. {
  4232. 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]*/ )
  4233. {
  4234. // Sent unplug message for California pricing logic
  4235. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  4236. {
  4237. uint8_t ts[20];
  4238. getNowDatetime(ts);
  4239. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4240. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4241. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4242. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4243. }
  4244. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4245. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4246. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4247. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4248. {
  4249. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4250. if((access(filenmae,F_OK))!=-1)
  4251. {
  4252. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4253. sprintf(str,"rm -f %s",filenmae);
  4254. system(str);
  4255. }
  4256. }
  4257. }
  4258. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4259. #if 1 // for TempStopTransaction
  4260. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4261. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4262. {
  4263. checkTempStopTransaction(gun_index);
  4264. }
  4265. #endif
  4266. }
  4267. }
  4268. }
  4269. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4270. {
  4271. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4272. {
  4273. tempIndex = ((gun_index==2) ? 1: 0);
  4274. }
  4275. else
  4276. {
  4277. tempIndex = gun_index;
  4278. }
  4279. for (int index = 0; index < GB_QUANTITY; index++)
  4280. {
  4281. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4282. {
  4283. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4284. {
  4285. // Sent unplug message for California pricing logic
  4286. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  4287. {
  4288. uint8_t ts[20];
  4289. getNowDatetime(ts);
  4290. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4291. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4292. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4293. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4294. }
  4295. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4296. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4297. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4298. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4299. {
  4300. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4301. if((access(filenmae,F_OK))!=-1)
  4302. {
  4303. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4304. sprintf(str,"rm -f %s",filenmae);
  4305. system(str);
  4306. }
  4307. }
  4308. }
  4309. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4310. #if 1 // for TempStopTransaction
  4311. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4312. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4313. {
  4314. checkTempStopTransaction(gun_index);
  4315. }
  4316. #endif
  4317. }
  4318. }
  4319. }
  4320. else if(gunType[gun_index] == GUN_TYPE_DO)
  4321. {
  4322. tempIndex = gun_index;
  4323. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4324. {
  4325. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4326. {
  4327. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4328. {
  4329. // Sent unplug message for California pricing logic
  4330. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  4331. {
  4332. uint8_t ts[20];
  4333. getNowDatetime(ts);
  4334. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4335. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4336. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4337. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4338. }
  4339. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4340. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4341. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4342. 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
  4343. {
  4344. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4345. if((access(filenmae,F_OK))!=-1)
  4346. {
  4347. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4348. sprintf(str,"rm -f %s",filenmae);
  4349. system(str);
  4350. }
  4351. }
  4352. }
  4353. 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);
  4354. #if 1 // for TempStopTransaction
  4355. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4356. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4357. {
  4358. checkTempStopTransaction(gun_index);
  4359. }
  4360. #endif
  4361. }
  4362. }
  4363. }
  4364. else
  4365. {
  4366. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4367. {
  4368. tempIndex = 2;
  4369. }
  4370. else
  4371. {
  4372. tempIndex = gun_index;
  4373. }
  4374. for (int index = 0; index < AC_QUANTITY; index++)
  4375. {
  4376. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4377. {
  4378. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4379. {
  4380. // Sent unplug message for California pricing logic
  4381. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  4382. {
  4383. uint8_t ts[20];
  4384. getNowDatetime(ts);
  4385. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4386. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4387. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4388. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4389. }
  4390. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4391. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4392. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4393. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4394. {
  4395. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4396. if((access(filenmae,F_OK))!=-1)
  4397. {
  4398. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4399. sprintf(str,"rm -f %s",filenmae);
  4400. system(str);
  4401. }
  4402. }
  4403. }
  4404. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4405. #if 1 // for TempStopTransaction
  4406. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4407. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4408. {
  4409. checkTempStopTransaction(gun_index);
  4410. }
  4411. #endif
  4412. }
  4413. }// END
  4414. }
  4415. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  4416. (
  4417. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4418. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4419. )
  4420. )
  4421. {
  4422. if(SystemInitial > 0)
  4423. SystemInitial -= 1;
  4424. sendStatusNotificationRequest(gun_index);
  4425. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4426. }
  4427. //==============================================
  4428. // CSU Trigger Smart Charging Profile
  4429. //==============================================
  4430. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4431. {
  4432. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4433. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4434. }
  4435. //==============================================
  4436. // Meter report
  4437. //==============================================
  4438. // Trigger MeterValue
  4439. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4440. {
  4441. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4442. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4443. }
  4444. // Clock-aligned Meter value
  4445. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4446. {
  4447. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4448. reqClockAlignMeter[gun_index] = 0;
  4449. }
  4450. // Sample period MeterValue
  4451. 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))))
  4452. {
  4453. //check Transaction active
  4454. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4455. {
  4456. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4457. {
  4458. tempIndex = ((gun_index==2) ? 1: 0);
  4459. }
  4460. else
  4461. {
  4462. tempIndex = gun_index;
  4463. }
  4464. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4465. {
  4466. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4467. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4468. {
  4469. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4470. {
  4471. reqSampleMeter[gun_index] = 1;
  4472. }
  4473. }
  4474. }// End for CHAdeMO
  4475. }
  4476. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4477. {
  4478. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4479. {
  4480. tempIndex = ((gun_index==2) ? 1: 0);
  4481. }
  4482. else
  4483. {
  4484. tempIndex = gun_index;
  4485. }
  4486. for (int index = 0; index < CCS_QUANTITY; index++)
  4487. {
  4488. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4489. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4490. {
  4491. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4492. {
  4493. reqSampleMeter[gun_index] = 1;
  4494. }
  4495. }
  4496. } // End for CCS
  4497. }
  4498. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4499. {
  4500. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4501. {
  4502. tempIndex = ((gun_index==2) ? 1: 0);
  4503. }
  4504. else
  4505. {
  4506. tempIndex = gun_index;
  4507. }
  4508. for (int index = 0; index < GB_QUANTITY; index++)
  4509. {
  4510. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4511. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4512. {
  4513. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4514. {
  4515. reqSampleMeter[gun_index] = 1;
  4516. }
  4517. }
  4518. }// End for GB
  4519. }
  4520. else if(gunType[gun_index] == GUN_TYPE_DO)
  4521. {
  4522. tempIndex = gun_index;
  4523. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4524. {
  4525. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4526. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4527. {
  4528. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4529. {
  4530. reqSampleMeter[gun_index] = 1;
  4531. }
  4532. }
  4533. }
  4534. }
  4535. else
  4536. {
  4537. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4538. {
  4539. tempIndex = 2;
  4540. }
  4541. else
  4542. {
  4543. tempIndex = gun_index;
  4544. }
  4545. for (int index = 0; index < AC_QUANTITY; index++)
  4546. {
  4547. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4548. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4549. {
  4550. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4551. {
  4552. reqSampleMeter[gun_index] = 1;
  4553. }
  4554. }
  4555. }//End for AC
  4556. }
  4557. if(reqSampleMeter[gun_index] == 1)
  4558. {
  4559. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4560. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4561. storeTempStopTransaction(gun_index);
  4562. reqSampleMeter[gun_index] = 0;
  4563. }
  4564. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4565. }
  4566. //==============================================
  4567. // Check Connector reserved
  4568. //==============================================
  4569. //===============================
  4570. // Check if Reserve is expired
  4571. //===============================
  4572. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4573. {
  4574. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4575. {
  4576. DEBUG_INFO("reserve expired.\n");
  4577. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4578. }
  4579. }//END OF Check if Reserve is expired
  4580. //==========================================
  4581. // csu trigger FirmwareStatusNotificationReq
  4582. //==========================================
  4583. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4584. {
  4585. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  4586. }
  4587. //==========================================
  4588. // csu trigger DiagnosticsStatusNotificationReq
  4589. //==========================================
  4590. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4591. {
  4592. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  4593. }
  4594. //==========================================
  4595. // csu trigger CancelReservationConf
  4596. //==========================================
  4597. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4598. {
  4599. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  4600. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4601. }
  4602. //==========================================
  4603. // csu trigger ChangeAvailabilityConf
  4604. //==========================================
  4605. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4606. {
  4607. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  4608. }
  4609. //==========================================
  4610. // csu trigger UnlockConnectorConf
  4611. //==========================================
  4612. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4613. {
  4614. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  4615. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4616. }
  4617. //==========================================
  4618. // csu trigger ReserveNowConf
  4619. //==========================================
  4620. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4621. {
  4622. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  4623. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4624. }
  4625. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  4626. {
  4627. sendSignCertificateRequest();
  4628. }
  4629. }
  4630. }
  4631. //==========================================
  4632. // send request routine
  4633. //==========================================
  4634. int sendAuthorizeRequest(int gun_index)
  4635. {
  4636. mtrace();
  4637. int result = FAIL;
  4638. char message[100]={0};
  4639. char guid[37];
  4640. char tempdata[65]={0};
  4641. DEBUG_INFO("sendAuthorizeRequest...\n");
  4642. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4643. //Local Authorize
  4644. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  4645. {
  4646. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4647. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4648. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4649. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4650. result = PASS;
  4651. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4652. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4653. authorizeRetryTimes = 0;
  4654. return result;
  4655. }
  4656. 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))||
  4657. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4658. {
  4659. // Query from cache
  4660. DEBUG_INFO("Authorize from cache.\n");
  4661. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4662. // Query from list
  4663. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4664. {
  4665. DEBUG_INFO("Authorize from list.\n");
  4666. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4667. }
  4668. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4669. {
  4670. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4671. {
  4672. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4673. }
  4674. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4675. {
  4676. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4677. }
  4678. if(!GetOcppConnStatus())
  4679. {
  4680. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4681. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4682. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4683. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4684. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4685. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4686. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4687. authorizeRetryTimes = 0;
  4688. return result;
  4689. }
  4690. }
  4691. else
  4692. {
  4693. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4694. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4695. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4696. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4697. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  4698. else
  4699. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4700. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4701. result = PASS;
  4702. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4703. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4704. authorizeRetryTimes = 0;
  4705. return result;
  4706. }
  4707. }
  4708. //initialize struct Authorize
  4709. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  4710. //get data from shared memory
  4711. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4712. random_uuid(guid);
  4713. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  4714. LWS_Send(message);
  4715. sprintf(tempdata, "Authorize,%d", gun_index);
  4716. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4717. {
  4718. result = PASS;
  4719. DEBUG_INFO("Authorize mapItem pass\n");
  4720. }
  4721. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4722. return result;
  4723. }
  4724. int sendBootNotificationRequest(void)
  4725. {
  4726. mtrace();
  4727. int result = FAIL;
  4728. char message[500]={0}, payload[700]={0};
  4729. char guid[37]={0};
  4730. char tempdata[65]={0};
  4731. // Fill BootNotification fields
  4732. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  4733. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4734. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4735. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4736. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4737. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4738. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4739. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4740. ShmOCPP16Data->ChargeBoxId
  4741. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4742. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4743. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4744. ,ShmOCPP16Data->BootNotification.CpFwVersion
  4745. ,ShmOCPP16Data->BootNotification.CpIccid
  4746. ,ShmOCPP16Data->BootNotification.CpImsi);
  4747. random_uuid(guid);
  4748. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4749. LWS_Send(message);
  4750. sprintf(tempdata, "BootNotification,0");
  4751. 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*/)
  4752. {
  4753. result = PASS;
  4754. }
  4755. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4756. strcpy(queuedata,message);
  4757. return result;
  4758. }
  4759. int sendDataTransferRequest(int gun_index)
  4760. {
  4761. mtrace();
  4762. char message[1000]={0};
  4763. char guid[37]={0};
  4764. char tempdata[65]={0};
  4765. int result = FAIL;
  4766. random_uuid(guid);
  4767. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4768. MESSAGE_TYPE_CALL,
  4769. guid,
  4770. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4771. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4772. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4773. LWS_Send(message);
  4774. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4775. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4776. {
  4777. result = PASS;
  4778. DEBUG_INFO("DataTransfer mapItem pass\n");
  4779. }
  4780. return result;
  4781. }
  4782. int sendDiagnosticsStatusNotificationRequest(char *status)
  4783. {
  4784. mtrace();
  4785. int result = FAIL;
  4786. char message[110]={0};
  4787. char guid[37]={0};
  4788. char tempdata[65]={0};
  4789. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4790. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4791. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4792. random_uuid(guid);
  4793. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4794. LWS_SendNow(message);
  4795. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4796. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4797. {
  4798. result = PASS;
  4799. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4800. }
  4801. //#ifdef SystemLogMessage
  4802. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4803. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4804. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4805. //#endif
  4806. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4807. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4808. //record status
  4809. if(strcmp(status,"Idle")==0)
  4810. {
  4811. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4812. }
  4813. else if(strcmp(status,"Uploaded")==0)
  4814. {
  4815. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4816. }
  4817. else if(strcmp(status,"UploadFailed")==0)
  4818. {
  4819. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4820. }
  4821. else if(strcmp(status,"Uploading")==0)
  4822. {
  4823. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4824. }
  4825. return result;
  4826. }
  4827. int sendFirmwareStatusNotificationRequest(char *status)
  4828. {
  4829. mtrace();
  4830. int result = FAIL;
  4831. char message[110]={0};
  4832. char guid[37]={0};
  4833. char tempdata[65]={0};
  4834. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4835. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4836. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4837. random_uuid(guid);
  4838. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4839. LWS_SendNow(message);
  4840. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4841. 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*/)
  4842. {
  4843. result = PASS;
  4844. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4845. }
  4846. //#ifdef SystemLogMessage
  4847. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4848. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4849. //#endif
  4850. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4851. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4852. //record status
  4853. if(strcmp(status,"Downloaded")==0)
  4854. {
  4855. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4856. }
  4857. else if(strcmp(status,"DownloadFailed")==0)
  4858. {
  4859. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4860. }
  4861. else if(strcmp(status,"Downloading")==0)
  4862. {
  4863. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4864. }
  4865. else if(strcmp(status,"Idle")==0)
  4866. {
  4867. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4868. }
  4869. else if(strcmp(status,"InstallationFailed")==0)
  4870. {
  4871. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4872. }
  4873. else if(strcmp(status,"Installing")==0)
  4874. {
  4875. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4876. }
  4877. else if(strcmp(status,"Installed")==0)
  4878. {
  4879. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4880. }
  4881. return result;
  4882. }
  4883. int sendHeartbeatRequest(int gun_index)
  4884. {
  4885. mtrace();
  4886. int result = FAIL;
  4887. char message[80]={0};
  4888. char guid[37]={0};
  4889. char tempdata[65]={0};
  4890. random_uuid(guid);
  4891. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4892. , MESSAGE_TYPE_CALL
  4893. , guid );
  4894. LWS_Send(message);
  4895. sprintf(tempdata, "Heartbeat,%d", 0);
  4896. 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*/)
  4897. {
  4898. result = PASS;
  4899. }
  4900. return result;
  4901. }
  4902. int sendStartTransactionRequest(int gun_index)
  4903. {
  4904. mtrace();
  4905. int result = FAIL;
  4906. char message[250]={0};
  4907. char guid[37]={0};
  4908. struct timeval tmnow;
  4909. struct tm *tm;
  4910. char buf[28];//, usec_buf[6];
  4911. char tempdata[65]={0};
  4912. int tempIndex = 0;
  4913. DEBUG_INFO("sendStartTransactionRequest...\n");
  4914. gettimeofday(&tmnow, NULL);
  4915. time_t t;
  4916. t = time(NULL);
  4917. /*UTC time and date*/
  4918. tm = gmtime(&t);
  4919. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4920. #if 0 // remove temporally
  4921. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4922. strcat(buf,".");
  4923. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4924. strcat(buf,usec_buf);
  4925. #endif
  4926. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4927. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4928. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4929. // clear StartTransaction Response
  4930. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4931. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4932. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4933. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4934. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4935. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4936. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4937. {
  4938. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4939. {
  4940. tempIndex = ((gun_index==2) ? 1: 0);
  4941. }
  4942. else
  4943. {
  4944. tempIndex = gun_index;
  4945. }
  4946. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4947. {
  4948. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4949. {
  4950. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4951. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4952. }
  4953. }
  4954. }
  4955. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4956. {
  4957. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4958. {
  4959. tempIndex = ((gun_index==2) ? 1: 0);
  4960. }
  4961. else
  4962. {
  4963. tempIndex = gun_index;
  4964. }
  4965. for (int index = 0; index < CCS_QUANTITY; index++)
  4966. {
  4967. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4968. {
  4969. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4970. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4971. }
  4972. }
  4973. }
  4974. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4975. {
  4976. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4977. {
  4978. tempIndex = ((gun_index==2) ? 1: 0);
  4979. }
  4980. else
  4981. {
  4982. tempIndex = gun_index;
  4983. }
  4984. for (int index = 0; index < GB_QUANTITY; index++)
  4985. {
  4986. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4987. {
  4988. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4989. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4990. }
  4991. }
  4992. }
  4993. else if(gunType[gun_index] == GUN_TYPE_DO)
  4994. {
  4995. tempIndex = gun_index;
  4996. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4997. {
  4998. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4999. {
  5000. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5001. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5002. }
  5003. }
  5004. }
  5005. else
  5006. {
  5007. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5008. {
  5009. tempIndex = 2;
  5010. }
  5011. else
  5012. {
  5013. tempIndex = gun_index;
  5014. }
  5015. for (int index = 0; index < AC_QUANTITY; index++)
  5016. {
  5017. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5018. {
  5019. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5020. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5021. }
  5022. }
  5023. }
  5024. random_uuid(guid);
  5025. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5026. {
  5027. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5028. , gun_index +1
  5029. , MESSAGE_TYPE_CALL
  5030. , guid
  5031. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5032. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5033. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5034. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5035. }
  5036. else
  5037. {
  5038. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5039. , gun_index +1
  5040. , MESSAGE_TYPE_CALL
  5041. , guid
  5042. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5043. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5044. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5045. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  5046. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5047. }
  5048. #if 1
  5049. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5050. 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*/)
  5051. {
  5052. result = PASS;
  5053. }
  5054. #endif
  5055. strcpy(queuedata, message);
  5056. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5057. OCPP_insert_transaction_msg(YES, queuedata);
  5058. return result;
  5059. }
  5060. int sendStatusNotificationRequest(int gun_index)
  5061. {
  5062. mtrace();
  5063. int result = FAIL;
  5064. char message[600]={0};
  5065. char guid[37];
  5066. int currentStatus = 0;
  5067. struct timeval tmnow;
  5068. struct tm *tm;
  5069. char buf[28];//, usec_buf[6];
  5070. char tempdata[65]={0};
  5071. int tempIndex = 0;
  5072. uint8_t isStateChanged = TRUE;
  5073. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5074. gettimeofday(&tmnow, NULL);
  5075. time_t t;
  5076. t = time(NULL);
  5077. /*UTC time and date*/
  5078. tm = gmtime(&t);
  5079. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5080. #if 0 // remove temporally
  5081. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5082. strcat(buf,".");
  5083. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5084. strcat(buf,usec_buf);
  5085. #endif
  5086. //printf("%s",buf);
  5087. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5088. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5089. // it's option
  5090. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5091. /*
  5092. enum _SYSTEM_STATUS
  5093. {
  5094. S_BOOTING = 0,
  5095. S_IDLE, = 1
  5096. S_AUTHORIZING, =2
  5097. S_REASSIGN_CHECK, =3
  5098. S_REASSIGN, =4
  5099. S_PRECHARGE, =5
  5100. S_PREPARING_FOR_EV, =6
  5101. S_PREPARING_FOR_EVSE, =7
  5102. S_CHARGING, =8
  5103. S_TERMINATING, =9
  5104. S_COMPLETE, =10
  5105. S_ALARM, =11
  5106. S_FAULT =12
  5107. }
  5108. */
  5109. //check Transaction active
  5110. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5111. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5112. {
  5113. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5114. {
  5115. tempIndex = ((gun_index==2) ? 1: 0);
  5116. }
  5117. else
  5118. {
  5119. tempIndex = gun_index;
  5120. }
  5121. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5122. {
  5123. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5124. {
  5125. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5126. {
  5127. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5128. {
  5129. currentStatus = Preparing; //OCPP Status: Preparing
  5130. }
  5131. else
  5132. {
  5133. currentStatus = Available; //OCPP Status: Available
  5134. }
  5135. }
  5136. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5137. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5138. ) //S_PRECHARGE
  5139. {
  5140. currentStatus = Preparing; //OCPP Status: Preparing
  5141. }
  5142. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5143. {
  5144. currentStatus = Charging; //OCPP Status: Charging
  5145. }
  5146. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5147. {
  5148. currentStatus = Finishing; //OCPP Status: Finishing
  5149. }
  5150. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5151. {
  5152. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5153. }
  5154. 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
  5155. {
  5156. currentStatus = Unavailable; //OCPP Status: Unavailable
  5157. }
  5158. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5159. {
  5160. currentStatus = Faulted; //OCPP Status: Faulted
  5161. }
  5162. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5163. {
  5164. currentStatus = Reserved; //OCPP Status: Reserved
  5165. }
  5166. } //end of the same index
  5167. }//end of for CHAdeMO_QUANTITY
  5168. }
  5169. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5170. {
  5171. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5172. {
  5173. tempIndex = ((gun_index==2) ? 1: 0);
  5174. }
  5175. else
  5176. {
  5177. tempIndex = gun_index;
  5178. }
  5179. for (int index = 0; index < CCS_QUANTITY; index++)
  5180. {
  5181. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5182. {
  5183. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5184. {
  5185. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5186. {
  5187. currentStatus = Preparing; //OCPP Status: Preparing
  5188. }
  5189. else
  5190. {
  5191. currentStatus = Available; //OCPP Status: Available
  5192. }
  5193. }
  5194. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5195. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5196. ) //S_PRECHARGE
  5197. {
  5198. currentStatus = Preparing; //OCPP Status: Preparing
  5199. }
  5200. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5201. {
  5202. currentStatus = Charging; //OCPP Status: Charging
  5203. }
  5204. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5205. {
  5206. currentStatus = Finishing; //OCPP Status: Finishing
  5207. }
  5208. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5209. {
  5210. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5211. }
  5212. 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
  5213. {
  5214. currentStatus = Unavailable; //OCPP Status : Unavailable
  5215. }
  5216. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5217. {
  5218. currentStatus = Faulted; //OCPP Status: Faulted
  5219. }
  5220. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5221. {
  5222. currentStatus = Reserved; //OCPP Status: Reserved
  5223. }
  5224. } //end of the same index
  5225. } // end of for CCS_QUANTITY
  5226. }
  5227. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5228. {
  5229. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5230. {
  5231. tempIndex = ((gun_index==2) ? 1: 0);
  5232. }
  5233. else
  5234. {
  5235. tempIndex = gun_index;
  5236. }
  5237. for (int index = 0; index < GB_QUANTITY; index++)
  5238. {
  5239. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5240. {
  5241. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5242. {
  5243. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5244. {
  5245. currentStatus = Preparing; //OCPP Status: Preparing
  5246. }
  5247. else
  5248. {
  5249. currentStatus = Available; //OCPP Status: Available
  5250. }
  5251. }
  5252. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5253. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5254. ) //S_PRECHARGE
  5255. {
  5256. currentStatus = Preparing; //OCPP Status: Preparing
  5257. }
  5258. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5259. {
  5260. currentStatus = Charging; //OCPP Status: Charging
  5261. }
  5262. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5263. {
  5264. currentStatus = Finishing; //OCPP Status: Finishing
  5265. }
  5266. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5267. {
  5268. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5269. }
  5270. 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
  5271. {
  5272. currentStatus = Unavailable; //OCPP Status: Unavailable
  5273. }
  5274. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5275. {
  5276. currentStatus = Faulted; //OCPP Status: Faulted
  5277. }
  5278. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5279. {
  5280. currentStatus = Reserved; //OCPP Status: Reserved
  5281. }
  5282. } //end of the same index
  5283. } // end of for GB_QUANTITY
  5284. }
  5285. else if(gunType[gun_index] == GUN_TYPE_DO)
  5286. {
  5287. tempIndex = gun_index;
  5288. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5289. {
  5290. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5291. {
  5292. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5293. {
  5294. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5295. {
  5296. currentStatus = Preparing; //OCPP Status: Preparing
  5297. }
  5298. else
  5299. {
  5300. currentStatus = Available; //OCPP Status: Available
  5301. }
  5302. }
  5303. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5304. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5305. ) //S_PRECHARGE
  5306. {
  5307. currentStatus = Preparing; //OCPP Status: Preparing
  5308. }
  5309. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5310. {
  5311. currentStatus = Charging; //OCPP Status: Charging
  5312. }
  5313. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5314. {
  5315. currentStatus = Finishing; //OCPP Status: Finishing
  5316. }
  5317. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5318. {
  5319. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5320. }
  5321. 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
  5322. {
  5323. currentStatus = Unavailable; //OCPP Status: Unavailable
  5324. }
  5325. 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
  5326. {
  5327. currentStatus = Faulted; //OCPP Status: Faulted
  5328. }
  5329. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5330. {
  5331. currentStatus = Reserved; //OCPP Status: Reserved
  5332. }
  5333. } //end of the same index
  5334. }
  5335. }
  5336. else
  5337. {
  5338. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5339. {
  5340. tempIndex = 2;
  5341. }
  5342. else
  5343. {
  5344. tempIndex = gun_index;
  5345. }
  5346. for (int index = 0; index < AC_QUANTITY; index++)
  5347. {
  5348. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5349. {
  5350. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5351. {
  5352. 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))
  5353. {
  5354. currentStatus = Preparing; //OCPP Status: Preparing
  5355. }
  5356. else
  5357. {
  5358. currentStatus = Available; //OCPP Status: Available
  5359. }
  5360. }
  5361. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5362. {
  5363. currentStatus = Preparing; //OCPP Status: Preparing
  5364. }
  5365. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5366. {
  5367. currentStatus = Charging; //OCPP Status: Charging
  5368. }
  5369. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5370. {
  5371. currentStatus = Finishing; //OCPP Status: Finishing
  5372. }
  5373. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5374. {
  5375. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5376. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5377. else
  5378. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5379. }
  5380. 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
  5381. {
  5382. currentStatus = Unavailable; //OCPP Status: Unavailable
  5383. }
  5384. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5385. {
  5386. currentStatus = Faulted; //OCPP Status: Faulted
  5387. }
  5388. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5389. {
  5390. currentStatus = Reserved; //OCPP Status: Reserved
  5391. }
  5392. }//end of the same index
  5393. }//end of for AC_QUANTITY
  5394. }
  5395. //it's option
  5396. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5397. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5398. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5399. {
  5400. isStateChanged = FALSE;
  5401. }
  5402. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5403. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5404. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5405. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5406. random_uuid(guid);
  5407. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5408. , MESSAGE_TYPE_CALL
  5409. , guid
  5410. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5411. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5412. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5413. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5414. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5415. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5416. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5417. if((server_sign == TRUE) && isStateChanged)
  5418. {
  5419. LWS_Send(message);
  5420. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5421. 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*/)
  5422. {
  5423. //DEBUG_ERROR("statusNotification mapitem pass");
  5424. result = PASS;
  5425. }
  5426. }
  5427. else
  5428. {
  5429. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5430. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5431. result = PASS;
  5432. }
  5433. return result;
  5434. }
  5435. int sendStopTransactionRequest(int gun_index)
  5436. {
  5437. mtrace();
  5438. int result = FAIL;
  5439. //char message[1500]={0};
  5440. char guid[37]={0};
  5441. char tempdata[65]={0};
  5442. int tempIndex = 0;
  5443. char TempStopTransaction[256];
  5444. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5445. //int idx_sample=0;
  5446. DEBUG_INFO("sendStopTransactionRequest \n");
  5447. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5448. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5449. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5450. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5451. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5452. {
  5453. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5454. {
  5455. tempIndex = ((gun_index==2) ? 1: 0);
  5456. }
  5457. else
  5458. {
  5459. tempIndex = gun_index;
  5460. }
  5461. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5462. {
  5463. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5464. {
  5465. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5466. }
  5467. }// END OF CHAdeMO_QUANTITY
  5468. }
  5469. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5470. {
  5471. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5472. {
  5473. tempIndex = ((gun_index==2) ? 1: 0);
  5474. }
  5475. else
  5476. {
  5477. tempIndex = gun_index;
  5478. }
  5479. for (int index = 0; index < CCS_QUANTITY; index++)
  5480. {
  5481. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5482. {
  5483. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5484. }
  5485. }// END OF CCS_QUANTITY
  5486. }
  5487. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5488. {
  5489. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5490. {
  5491. tempIndex = ((gun_index==2) ? 1: 0);
  5492. }
  5493. else
  5494. {
  5495. tempIndex = gun_index;
  5496. }
  5497. for (int index = 0; index < GB_QUANTITY; index++)
  5498. {
  5499. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5500. {
  5501. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5502. }
  5503. }// END OF GB_QUANTITY
  5504. }
  5505. else if(gunType[gun_index] == GUN_TYPE_DO)
  5506. {
  5507. tempIndex = gun_index;
  5508. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5509. {
  5510. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5511. {
  5512. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5513. }
  5514. }// END OF GB_QUANTITY
  5515. }
  5516. else
  5517. {
  5518. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5519. {
  5520. tempIndex = 2;
  5521. }
  5522. else
  5523. {
  5524. tempIndex = gun_index;
  5525. }
  5526. for (int index = 0; index < AC_QUANTITY; index++)
  5527. {
  5528. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5529. {
  5530. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5531. }
  5532. }// END OF AC_QUANTITY
  5533. }
  5534. //====================================== Stop Transaction Time =====================================================
  5535. struct timeval tmnow;
  5536. struct tm *tm;
  5537. char buf[28];//, usec_buf[6];
  5538. gettimeofday(&tmnow, NULL);
  5539. time_t t;
  5540. t = time(NULL);
  5541. /*UTC time and date*/
  5542. tm = gmtime(&t);
  5543. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5544. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  5545. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  5546. random_uuid(guid);
  5547. /***********************************transactionData******************************************************/
  5548. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5549. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5550. //=================================
  5551. // Transaction_Begin
  5552. //=================================
  5553. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5554. {
  5555. //============================================ Energy.Active.Import.Interval ================================
  5556. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5557. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5558. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5559. 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*/]);
  5560. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5561. 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))
  5562. {
  5563. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5564. }
  5565. else
  5566. {
  5567. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5568. }
  5569. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5570. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5571. }
  5572. //=================================
  5573. // Transaction_End
  5574. //=================================
  5575. // ================================= Current.Import L1 ===============================================
  5576. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5577. {
  5578. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5579. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5580. {
  5581. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5582. {
  5583. tempIndex = ((gun_index==2) ? 1: 0);
  5584. }
  5585. else
  5586. {
  5587. tempIndex = gun_index;
  5588. }
  5589. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5590. {
  5591. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5592. {
  5593. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5594. }
  5595. }// End of for CHAdeMO_QUANTITY
  5596. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5597. }
  5598. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5599. {
  5600. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5601. {
  5602. tempIndex = ((gun_index==2) ? 1: 0);
  5603. }
  5604. else
  5605. {
  5606. tempIndex = gun_index;
  5607. }
  5608. for (int index = 0; index < CCS_QUANTITY; index++)
  5609. {
  5610. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5611. {
  5612. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5613. }
  5614. }// End of for CCS_QUANTITY
  5615. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5616. }
  5617. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5618. {
  5619. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5620. {
  5621. tempIndex = ((gun_index==2) ? 1: 0);
  5622. }
  5623. else
  5624. {
  5625. tempIndex = gun_index;
  5626. }
  5627. for (int index = 0; index < GB_QUANTITY; index++)
  5628. {
  5629. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5630. {
  5631. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5632. }
  5633. }// End of for GB_QUANTITY
  5634. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5635. }
  5636. else if(gunType[gun_index] == GUN_TYPE_DO)
  5637. {
  5638. tempIndex = gun_index;
  5639. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5640. {
  5641. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5642. {
  5643. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5644. }
  5645. }
  5646. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5647. }
  5648. else
  5649. {
  5650. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5651. {
  5652. tempIndex = 2;
  5653. }
  5654. else
  5655. {
  5656. tempIndex = gun_index;
  5657. }
  5658. for (int index = 0; index < AC_QUANTITY; index++)
  5659. {
  5660. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5661. {
  5662. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5663. }
  5664. }// End of for AC_QUANTITY
  5665. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5666. }
  5667. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5668. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5669. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5670. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5671. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5672. }
  5673. // ================================= Energy.Active.Import.Interval ==============================================
  5674. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5675. {
  5676. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5677. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5678. {
  5679. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5680. {
  5681. tempIndex = ((gun_index==2) ? 1: 0);
  5682. }
  5683. else
  5684. {
  5685. tempIndex = gun_index;
  5686. }
  5687. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5688. {
  5689. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5690. {
  5691. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5692. }
  5693. }// END OF CHAdeMO_QUANTITY
  5694. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5695. }
  5696. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5697. {
  5698. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5699. {
  5700. tempIndex = ((gun_index==2) ? 1: 0);
  5701. }
  5702. else
  5703. {
  5704. tempIndex = gun_index;
  5705. }
  5706. for (int index = 0; index < CCS_QUANTITY; index++)
  5707. {
  5708. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5709. {
  5710. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5711. }
  5712. }// END OF CCS_QUANTITY
  5713. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5714. }
  5715. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5716. {
  5717. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5718. {
  5719. tempIndex = ((gun_index==2) ? 1: 0);
  5720. }
  5721. else
  5722. {
  5723. tempIndex = gun_index;
  5724. }
  5725. for (int index = 0; index < GB_QUANTITY; index++)
  5726. {
  5727. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5728. {
  5729. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5730. }
  5731. }// END OF GB_QUANTITY
  5732. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5733. }
  5734. else if(gunType[gun_index] == GUN_TYPE_DO)
  5735. {
  5736. tempIndex = gun_index;
  5737. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5738. {
  5739. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5740. {
  5741. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5742. }
  5743. }
  5744. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5745. }
  5746. else
  5747. {
  5748. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5749. {
  5750. tempIndex = 2;
  5751. }
  5752. else
  5753. {
  5754. tempIndex = gun_index;
  5755. }
  5756. for (int index = 0; index < AC_QUANTITY; index++)
  5757. {
  5758. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5759. {
  5760. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5761. }
  5762. }// END OF AC_QUANTITY
  5763. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5764. }
  5765. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5766. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5767. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5768. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5769. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5770. }
  5771. //=================================== Power.Active.Import ==================================================
  5772. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5773. {
  5774. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5775. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5776. {
  5777. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5778. {
  5779. tempIndex = ((gun_index==2) ? 1: 0);
  5780. }
  5781. else
  5782. {
  5783. tempIndex = gun_index;
  5784. }
  5785. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5786. {
  5787. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5788. {
  5789. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5790. }
  5791. } // End for CHAdeMO_QUANTITY
  5792. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5793. }
  5794. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5795. {
  5796. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5797. {
  5798. tempIndex = ((gun_index==2) ? 1: 0);
  5799. }
  5800. else
  5801. {
  5802. tempIndex = gun_index;
  5803. }
  5804. for (int index = 0; index < CCS_QUANTITY; index++)
  5805. {
  5806. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5807. {
  5808. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5809. }
  5810. } // END for CCS_QUANTITY
  5811. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5812. }
  5813. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5814. {
  5815. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5816. {
  5817. tempIndex = ((gun_index==2) ? 1: 0);
  5818. }
  5819. else
  5820. {
  5821. tempIndex = gun_index;
  5822. }
  5823. for (int index = 0; index < GB_QUANTITY; index++)
  5824. {
  5825. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5826. {
  5827. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5828. }
  5829. }// END for GB_QUANTITY
  5830. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5831. }
  5832. else if(gunType[gun_index] == GUN_TYPE_DO)
  5833. {
  5834. tempIndex = gun_index;
  5835. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5836. {
  5837. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5838. {
  5839. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5840. }
  5841. }
  5842. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5843. }
  5844. else
  5845. {
  5846. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5847. {
  5848. tempIndex = 2;
  5849. }
  5850. else
  5851. {
  5852. tempIndex = gun_index;
  5853. }
  5854. for (int index = 0; index < AC_QUANTITY; index++)
  5855. {
  5856. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5857. {
  5858. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5859. }
  5860. } // END for AC_QUANTITY
  5861. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5862. }
  5863. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5864. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5865. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5866. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5867. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5868. }
  5869. //============================ Voltage L1 ====================================
  5870. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5871. {
  5872. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5873. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5874. {
  5875. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5876. {
  5877. tempIndex = ((gun_index==2) ? 1: 0);
  5878. }
  5879. else
  5880. {
  5881. tempIndex = gun_index;
  5882. }
  5883. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5884. {
  5885. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5886. {
  5887. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5888. }
  5889. } // END OF FOR CHAdeMO_QUANTITY
  5890. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5891. }
  5892. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5893. {
  5894. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5895. {
  5896. tempIndex = ((gun_index==2) ? 1: 0);
  5897. }
  5898. else
  5899. {
  5900. tempIndex = gun_index;
  5901. }
  5902. for (int index = 0; index < CCS_QUANTITY; index++)
  5903. {
  5904. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5905. {
  5906. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5907. }
  5908. } // END OF FOR CCS_QUANTITY
  5909. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5910. }
  5911. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5912. {
  5913. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5914. {
  5915. tempIndex = ((gun_index==2) ? 1: 0);
  5916. }
  5917. else
  5918. {
  5919. tempIndex = gun_index;
  5920. }
  5921. for (int index = 0; index < GB_QUANTITY; index++)
  5922. {
  5923. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5924. {
  5925. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5926. }
  5927. } // END OF FOR GB_QUANTITY
  5928. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5929. }
  5930. else if(gunType[gun_index] == GUN_TYPE_DO)
  5931. {
  5932. tempIndex = gun_index;
  5933. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5934. {
  5935. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5936. {
  5937. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5938. }
  5939. }
  5940. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5941. }
  5942. else
  5943. {
  5944. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5945. {
  5946. tempIndex = 2;
  5947. }
  5948. else
  5949. {
  5950. tempIndex = gun_index;
  5951. }
  5952. for (int index = 0; index < AC_QUANTITY; index++)
  5953. {
  5954. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5955. {
  5956. 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
  5957. }
  5958. } // END OF FOR AC_QUANTITY
  5959. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5960. }
  5961. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5962. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5963. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5964. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5965. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5966. }
  5967. //====================== End SoC ================================
  5968. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5969. {
  5970. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5971. 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))
  5972. {
  5973. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5974. {
  5975. tempIndex = ((gun_index==2) ? 1: 0);
  5976. }
  5977. else
  5978. {
  5979. tempIndex = gun_index;
  5980. }
  5981. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5982. {
  5983. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5984. {
  5985. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5986. {
  5987. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5988. }
  5989. }
  5990. }
  5991. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5992. {
  5993. for (int index = 0; index < CCS_QUANTITY; index++)
  5994. {
  5995. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5996. {
  5997. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5998. }
  5999. }
  6000. }
  6001. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6002. {
  6003. for (int index = 0; index < GB_QUANTITY; index++)
  6004. {
  6005. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6006. {
  6007. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6008. }
  6009. }
  6010. }
  6011. else if(gunType[gun_index] == GUN_TYPE_DO)
  6012. {
  6013. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6014. {
  6015. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6016. {
  6017. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6018. }
  6019. }
  6020. }
  6021. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6022. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6023. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6024. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6025. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6026. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6027. } // END FOR DC CASE
  6028. }
  6029. // ================================= Current.Import L2 ===============================================
  6030. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6031. {
  6032. // AC 3 phse L2 current
  6033. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6034. {
  6035. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6036. {
  6037. tempIndex = 2;
  6038. }
  6039. else
  6040. {
  6041. tempIndex = gun_index;
  6042. }
  6043. for (int index = 0; index < AC_QUANTITY; index++)
  6044. {
  6045. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6046. {
  6047. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6048. }
  6049. }// End of for AC_QUANTITY
  6050. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6051. }
  6052. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6053. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6054. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6055. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6056. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6057. }
  6058. // ================================= Current.Import L3 ===============================================
  6059. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6060. {
  6061. // AC 3 phse L3 current
  6062. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6063. {
  6064. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6065. {
  6066. tempIndex = 2;
  6067. }
  6068. else
  6069. {
  6070. tempIndex = gun_index;
  6071. }
  6072. for (int index = 0; index < AC_QUANTITY; index++)
  6073. {
  6074. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6075. {
  6076. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6077. }
  6078. }// End of for AC_QUANTITY
  6079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6080. }
  6081. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6082. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6084. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6085. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6086. }
  6087. //============================ Voltage L2 ====================================
  6088. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6089. {
  6090. // AC 3 phse L2 voltage
  6091. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6092. {
  6093. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6094. {
  6095. tempIndex = 2;
  6096. }
  6097. else
  6098. {
  6099. tempIndex = gun_index;
  6100. }
  6101. for (int index = 0; index < AC_QUANTITY; index++)
  6102. {
  6103. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6104. {
  6105. 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
  6106. }
  6107. } // END OF FOR AC_QUANTITY
  6108. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6109. }
  6110. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6112. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6113. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6114. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6115. }
  6116. //============================ Voltage L3 ====================================
  6117. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6118. {
  6119. // AC 3 phse L3 voltage
  6120. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6121. {
  6122. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6123. {
  6124. tempIndex = 2;
  6125. }
  6126. else
  6127. {
  6128. tempIndex = gun_index;
  6129. }
  6130. for (int index = 0; index < AC_QUANTITY; index++)
  6131. {
  6132. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6133. {
  6134. 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
  6135. }
  6136. } // END OF FOR AC_QUANTITY
  6137. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6138. }
  6139. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6140. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6141. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6142. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6143. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6144. }
  6145. //====================== Start SoC ================================
  6146. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6147. {
  6148. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6149. 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))
  6150. {
  6151. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6152. {
  6153. tempIndex = ((gun_index==2) ? 1: 0);
  6154. }
  6155. else
  6156. {
  6157. tempIndex = gun_index;
  6158. }
  6159. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6160. {
  6161. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6162. {
  6163. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6164. {
  6165. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6166. }
  6167. }
  6168. }
  6169. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6170. {
  6171. for (int index = 0; index < CCS_QUANTITY; index++)
  6172. {
  6173. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6174. {
  6175. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6176. }
  6177. }
  6178. }
  6179. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6180. {
  6181. for (int index = 0; index < GB_QUANTITY; index++)
  6182. {
  6183. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6184. {
  6185. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6186. }
  6187. }
  6188. }
  6189. else if(gunType[gun_index] == GUN_TYPE_DO)
  6190. {
  6191. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6192. {
  6193. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6194. {
  6195. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6196. }
  6197. }
  6198. }
  6199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6203. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6204. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6205. } // END FOR DC CASE
  6206. }
  6207. //================================================ Message create ====================================================
  6208. json_object *StopTransaction = json_object_new_object();
  6209. json_object *transactionDatas = json_object_new_array();
  6210. json_object *sampledValues = json_object_new_array();
  6211. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6212. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6213. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6214. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6215. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6216. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6217. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6218. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6219. {
  6220. json_object *transactionData = json_object_new_object();
  6221. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6222. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6223. {
  6224. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6225. {
  6226. json_object *sampledValue = json_object_new_object();
  6227. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6228. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6229. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6230. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6231. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6232. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6233. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6234. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6235. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6236. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6237. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6238. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6239. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6240. json_object_array_add(sampledValues, sampledValue);
  6241. }
  6242. }
  6243. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6244. json_object_array_add(transactionDatas, transactionData);
  6245. }
  6246. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6247. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6248. ,MESSAGE_TYPE_CALL
  6249. ,guid
  6250. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6251. json_object_put(StopTransaction);
  6252. #if 1 // for TempStopTransaction
  6253. //Delete TempStopTransaction
  6254. if((access(TempStopTransaction,F_OK))!=-1)
  6255. {
  6256. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6257. }
  6258. #endif
  6259. #if 1
  6260. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6261. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6262. {
  6263. result = PASS;
  6264. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6265. }
  6266. #endif
  6267. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6268. OCPP_insert_transaction_msg(NO, queuedata);
  6269. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6270. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6271. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6272. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6273. {
  6274. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6275. }
  6276. //for test
  6277. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6278. return result;
  6279. }
  6280. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6281. {
  6282. mtrace();
  6283. int result = FAIL;
  6284. char guid[37]={0};
  6285. char tempdata[65]={0};
  6286. int tempIndex = 0;
  6287. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6288. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6289. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6290. //set value
  6291. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6292. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6293. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6294. -1);
  6295. random_uuid(guid);
  6296. //UTC Date time
  6297. struct timeval tmnow;
  6298. struct tm *tm;
  6299. char buf[28];//, usec_buf[6];
  6300. gettimeofday(&tmnow, NULL);
  6301. time_t t;
  6302. t = time(NULL);
  6303. /*UTC time and date*/
  6304. tm = gmtime(&t);
  6305. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6306. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6307. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6308. //********************************(1)Current.Import L1************************************************/
  6309. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6310. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6311. (dataType == ReadingContext_Trigger))
  6312. {
  6313. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6314. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6315. {
  6316. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6317. {
  6318. tempIndex = ((gun_index==2) ? 1: 0);
  6319. }
  6320. else
  6321. {
  6322. tempIndex = gun_index;
  6323. }
  6324. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6325. {
  6326. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6327. {
  6328. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6329. }
  6330. }
  6331. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6332. }
  6333. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6334. {
  6335. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6336. {
  6337. tempIndex = ((gun_index==2) ? 1: 0);
  6338. }
  6339. else
  6340. {
  6341. tempIndex = gun_index;
  6342. }
  6343. for (int index = 0; index < CCS_QUANTITY; index++)
  6344. {
  6345. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6346. {
  6347. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6348. }
  6349. }
  6350. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6351. }
  6352. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6353. {
  6354. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6355. {
  6356. tempIndex = ((gun_index==2) ? 1: 0);
  6357. }
  6358. else
  6359. {
  6360. tempIndex = gun_index;
  6361. }
  6362. for (int index = 0; index < GB_QUANTITY; index++)
  6363. {
  6364. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6365. {
  6366. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6367. }
  6368. }
  6369. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6370. }
  6371. else if(gunType[gun_index] == GUN_TYPE_DO)
  6372. {
  6373. tempIndex = gun_index;
  6374. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6375. {
  6376. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6377. {
  6378. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6379. }
  6380. }
  6381. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6382. }
  6383. else
  6384. {
  6385. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6386. {
  6387. tempIndex = 2;
  6388. }
  6389. else
  6390. {
  6391. tempIndex = gun_index;
  6392. }
  6393. for (int index = 0; index < AC_QUANTITY; index++)
  6394. {
  6395. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6396. {
  6397. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6398. }
  6399. }
  6400. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6401. }
  6402. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6403. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6404. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6405. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6406. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6407. }
  6408. //********************************(2)Energy.Active.Import.Register ************************************************/
  6409. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6410. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6411. (dataType == ReadingContext_Trigger))
  6412. {
  6413. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6414. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6415. {
  6416. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6417. {
  6418. tempIndex = ((gun_index==2) ? 1: 0);
  6419. }
  6420. else
  6421. {
  6422. tempIndex = gun_index;
  6423. }
  6424. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6425. {
  6426. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6427. {
  6428. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6429. }
  6430. }
  6431. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6432. }
  6433. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6434. {
  6435. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6436. {
  6437. tempIndex = ((gun_index==2) ? 1: 0);
  6438. }
  6439. else
  6440. {
  6441. tempIndex = gun_index;
  6442. }
  6443. for (int index = 0; index < CCS_QUANTITY; index++)
  6444. {
  6445. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6446. {
  6447. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6448. }
  6449. }
  6450. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6451. }
  6452. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6453. {
  6454. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6455. {
  6456. tempIndex = ((gun_index==2) ? 1: 0);
  6457. }
  6458. else
  6459. {
  6460. tempIndex = gun_index;
  6461. }
  6462. for (int index = 0; index < GB_QUANTITY; index++)
  6463. {
  6464. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6465. {
  6466. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6467. }
  6468. }
  6469. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6470. }
  6471. else if(gunType[gun_index] == GUN_TYPE_DO)
  6472. {
  6473. tempIndex = gun_index;
  6474. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6475. {
  6476. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6477. {
  6478. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6479. }
  6480. }
  6481. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6482. }
  6483. else
  6484. {
  6485. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6486. {
  6487. tempIndex = 2;
  6488. }
  6489. else
  6490. {
  6491. tempIndex = gun_index;
  6492. }
  6493. for (int index = 0; index < AC_QUANTITY; index++)
  6494. {
  6495. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6496. {
  6497. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6498. }
  6499. }
  6500. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6501. }
  6502. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6503. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6504. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6505. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6506. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6507. }
  6508. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6509. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6510. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6511. (dataType == ReadingContext_Trigger))
  6512. {
  6513. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6514. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6515. {
  6516. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6517. {
  6518. tempIndex = ((gun_index==2) ? 1: 0);
  6519. }
  6520. else
  6521. {
  6522. tempIndex = gun_index;
  6523. }
  6524. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6525. {
  6526. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6527. {
  6528. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6529. }
  6530. } // END OF FOR CHAdeMO_QUANTITY
  6531. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6532. }
  6533. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6534. {
  6535. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6536. {
  6537. tempIndex = ((gun_index==2) ? 1: 0);
  6538. }
  6539. else
  6540. {
  6541. tempIndex = gun_index;
  6542. }
  6543. for (int index = 0; index < CCS_QUANTITY; index++)
  6544. {
  6545. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6546. {
  6547. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6548. }
  6549. } // END OF CCS_QUANTITY
  6550. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6551. }
  6552. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6553. {
  6554. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6555. {
  6556. tempIndex = ((gun_index==2) ? 1: 0);
  6557. }
  6558. else
  6559. {
  6560. tempIndex = gun_index;
  6561. }
  6562. for (int index = 0; index < GB_QUANTITY; index++)
  6563. {
  6564. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6565. {
  6566. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6567. }
  6568. } // END OF GB_QUANTITY
  6569. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6570. }
  6571. else if(gunType[gun_index] == GUN_TYPE_DO)
  6572. {
  6573. tempIndex = gun_index;
  6574. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6575. {
  6576. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6577. {
  6578. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6579. }
  6580. }
  6581. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6582. }
  6583. else
  6584. {
  6585. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6586. {
  6587. tempIndex = 2;
  6588. }
  6589. else
  6590. {
  6591. tempIndex = gun_index;
  6592. }
  6593. for (int index = 0; index < AC_QUANTITY; index++)
  6594. {
  6595. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6596. {
  6597. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6598. }
  6599. }
  6600. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6601. }
  6602. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6603. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6604. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6605. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6606. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6607. }
  6608. //********************************(4)Power.Active.Import************************************************/
  6609. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6610. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6611. (dataType == ReadingContext_Trigger))
  6612. {
  6613. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6614. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6615. {
  6616. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6617. {
  6618. tempIndex = ((gun_index==2) ? 1: 0);
  6619. }
  6620. else
  6621. {
  6622. tempIndex = gun_index;
  6623. }
  6624. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6625. {
  6626. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6627. {
  6628. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6629. }
  6630. } // END OF FOR
  6631. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6632. }
  6633. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6634. {
  6635. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6636. {
  6637. tempIndex = ((gun_index==2) ? 1: 0);
  6638. }
  6639. else
  6640. {
  6641. tempIndex = gun_index;
  6642. }
  6643. for (int index = 0; index < CCS_QUANTITY; index++)
  6644. {
  6645. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6646. {
  6647. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6648. }
  6649. }
  6650. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6651. }
  6652. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6653. {
  6654. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6655. {
  6656. tempIndex = ((gun_index==2) ? 1: 0);
  6657. }
  6658. else
  6659. {
  6660. tempIndex = gun_index;
  6661. }
  6662. for (int index = 0; index < GB_QUANTITY; index++)
  6663. {
  6664. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6665. {
  6666. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6667. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6668. }
  6669. }
  6670. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6671. }
  6672. else if(gunType[gun_index] == GUN_TYPE_DO)
  6673. {
  6674. tempIndex = gun_index;
  6675. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6676. {
  6677. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6678. {
  6679. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6680. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6681. }
  6682. }
  6683. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6684. }
  6685. else
  6686. {
  6687. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6688. {
  6689. tempIndex = 2;
  6690. }
  6691. else
  6692. {
  6693. tempIndex = gun_index;
  6694. }
  6695. for (int index = 0; index < AC_QUANTITY; index++)
  6696. {
  6697. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6698. {
  6699. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6700. }
  6701. }
  6702. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6703. }
  6704. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6705. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6706. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6707. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6708. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6709. }
  6710. //***********************************************(5)VOLTAGE L1******************************************************/
  6711. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6712. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6713. (dataType == ReadingContext_Trigger))
  6714. {
  6715. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6716. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6717. {
  6718. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6719. {
  6720. tempIndex = ((gun_index==2) ? 1: 0);
  6721. }
  6722. else
  6723. {
  6724. tempIndex = gun_index;
  6725. }
  6726. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6727. {
  6728. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6729. {
  6730. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6731. }
  6732. }
  6733. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6734. }
  6735. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6736. {
  6737. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6738. {
  6739. tempIndex = ((gun_index==2) ? 1: 0);
  6740. }
  6741. else
  6742. {
  6743. tempIndex = gun_index;
  6744. }
  6745. for (int index = 0; index < CCS_QUANTITY; index++)
  6746. {
  6747. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6748. {
  6749. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6750. }
  6751. }
  6752. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6753. }
  6754. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6755. {
  6756. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6757. {
  6758. tempIndex = ((gun_index==2) ? 1: 0);
  6759. }
  6760. else
  6761. {
  6762. tempIndex = gun_index;
  6763. }
  6764. for (int index = 0; index < GB_QUANTITY; index++)
  6765. {
  6766. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6767. {
  6768. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6769. }
  6770. }
  6771. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6772. }
  6773. else if(gunType[gun_index] == GUN_TYPE_DO)
  6774. {
  6775. tempIndex = gun_index;
  6776. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6777. {
  6778. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6779. {
  6780. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6781. }
  6782. }
  6783. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6784. }
  6785. else
  6786. {
  6787. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6788. {
  6789. tempIndex = 2;
  6790. }
  6791. else
  6792. {
  6793. tempIndex = gun_index;
  6794. }
  6795. for (int index = 0; index < AC_QUANTITY; index++)
  6796. {
  6797. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6798. {
  6799. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6800. }
  6801. }
  6802. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6803. }
  6804. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6805. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6806. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6807. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6808. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6809. }
  6810. //***********************************************(6)SOC******************************************************/
  6811. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6812. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6813. (dataType == ReadingContext_Trigger))
  6814. {
  6815. 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))
  6816. {
  6817. //idx_sample=5;
  6818. //sampledValue = NULL;
  6819. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6820. {
  6821. tempIndex = ((gun_index==2) ? 1: 0);
  6822. }
  6823. else
  6824. {
  6825. tempIndex = gun_index;
  6826. }
  6827. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6828. {
  6829. //tempIndex = ((gun_index==2) ? 1: 0);
  6830. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6831. {
  6832. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6833. {
  6834. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6835. }
  6836. }
  6837. }
  6838. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6839. {
  6840. //tempIndex = ((gun_index==2) ? 1: 0);
  6841. for (int index = 0; index < CCS_QUANTITY; index++)
  6842. {
  6843. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6844. {
  6845. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6846. }
  6847. }
  6848. }
  6849. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6850. {
  6851. //tempIndex = ((gun_index==2) ? 1: 0);
  6852. for (int index = 0; index < GB_QUANTITY; index++)
  6853. {
  6854. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6855. {
  6856. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6857. }
  6858. }
  6859. }
  6860. else if(gunType[gun_index] == GUN_TYPE_DO)
  6861. {
  6862. //tempIndex = ((gun_index==2) ? 1: 0);
  6863. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6864. {
  6865. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6866. {
  6867. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6868. }
  6869. }
  6870. }
  6871. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6872. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6873. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6874. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6875. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6876. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6877. }
  6878. }
  6879. //********************************(7)Current.Import L2************************************************/
  6880. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6881. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6882. (dataType == ReadingContext_Trigger))
  6883. {
  6884. // Only for AC 3 phase
  6885. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6886. {
  6887. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6888. {
  6889. tempIndex = 2;
  6890. }
  6891. else
  6892. {
  6893. tempIndex = gun_index;
  6894. }
  6895. for (int index = 0; index < AC_QUANTITY; index++)
  6896. {
  6897. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6898. {
  6899. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6900. }
  6901. }
  6902. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6903. }
  6904. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6905. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6906. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6907. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6908. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6909. }
  6910. //********************************(8)Current.Import L3************************************************/
  6911. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6912. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6913. (dataType == ReadingContext_Trigger))
  6914. {
  6915. // Only for AC 3 phase
  6916. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6917. {
  6918. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6919. {
  6920. tempIndex = 2;
  6921. }
  6922. else
  6923. {
  6924. tempIndex = gun_index;
  6925. }
  6926. for (int index = 0; index < AC_QUANTITY; index++)
  6927. {
  6928. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6929. {
  6930. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6931. }
  6932. }
  6933. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6934. }
  6935. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6936. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6937. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6938. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6939. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6940. }
  6941. //***********************************************(9)VOLTAGE L2******************************************************/
  6942. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6943. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6944. (dataType == ReadingContext_Trigger))
  6945. {
  6946. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6947. {
  6948. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6949. {
  6950. tempIndex = 2;
  6951. }
  6952. else
  6953. {
  6954. tempIndex = gun_index;
  6955. }
  6956. for (int index = 0; index < AC_QUANTITY; index++)
  6957. {
  6958. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6959. {
  6960. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6961. }
  6962. }
  6963. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6964. }
  6965. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6966. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6967. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6968. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6969. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6970. }
  6971. //***********************************************(10)VOLTAGE L3******************************************************/
  6972. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6973. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6974. (dataType == ReadingContext_Trigger))
  6975. {
  6976. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6977. {
  6978. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6979. {
  6980. tempIndex = 2;
  6981. }
  6982. else
  6983. {
  6984. tempIndex = gun_index;
  6985. }
  6986. for (int index = 0; index < AC_QUANTITY; index++)
  6987. {
  6988. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6989. {
  6990. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6991. }
  6992. }
  6993. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6994. }
  6995. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6996. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6997. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6998. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6999. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7000. }
  7001. //***********************************************(11)Current.Offered******************************************************/
  7002. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7003. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7004. (dataType == ReadingContext_Trigger))
  7005. {
  7006. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7007. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7008. {
  7009. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7010. {
  7011. tempIndex = ((gun_index==2) ? 1: 0);
  7012. }
  7013. else
  7014. {
  7015. tempIndex = gun_index;
  7016. }
  7017. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7018. {
  7019. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7020. {
  7021. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7022. }
  7023. } // END OF FOR CHAdeMO_QUANTITY
  7024. }
  7025. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7026. {
  7027. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7028. {
  7029. tempIndex = ((gun_index==2) ? 1: 0);
  7030. }
  7031. else
  7032. {
  7033. tempIndex = gun_index;
  7034. }
  7035. for (int index = 0; index < CCS_QUANTITY; index++)
  7036. {
  7037. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7038. {
  7039. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7040. }
  7041. } // END OF CCS_QUANTITY
  7042. }
  7043. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7044. {
  7045. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7046. {
  7047. tempIndex = ((gun_index==2) ? 1: 0);
  7048. }
  7049. else
  7050. {
  7051. tempIndex = gun_index;
  7052. }
  7053. for (int index = 0; index < GB_QUANTITY; index++)
  7054. {
  7055. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7056. {
  7057. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7058. }
  7059. } // END OF GB_QUANTITY
  7060. }
  7061. else if(gunType[gun_index] == GUN_TYPE_DO)
  7062. {
  7063. tempIndex = gun_index;
  7064. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7065. {
  7066. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7067. {
  7068. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7069. }
  7070. }
  7071. }
  7072. else
  7073. {
  7074. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7075. {
  7076. tempIndex = 2;
  7077. }
  7078. else
  7079. {
  7080. tempIndex = gun_index;
  7081. }
  7082. for (int index = 0; index < AC_QUANTITY; index++)
  7083. {
  7084. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7085. {
  7086. uint16_t currentOffer;
  7087. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7088. {
  7089. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7090. }
  7091. else
  7092. {
  7093. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7094. }
  7095. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7096. }
  7097. }
  7098. }
  7099. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7100. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7101. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7102. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7103. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7104. }
  7105. //***********************************************(12)Power.Offered******************************************************/
  7106. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7107. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7108. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7109. {
  7110. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7111. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7112. {
  7113. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7114. {
  7115. tempIndex = ((gun_index==2) ? 1: 0);
  7116. }
  7117. else
  7118. {
  7119. tempIndex = gun_index;
  7120. }
  7121. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7122. {
  7123. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7124. {
  7125. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7126. }
  7127. } // END OF FOR CHAdeMO_QUANTITY
  7128. }
  7129. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7130. {
  7131. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7132. {
  7133. tempIndex = ((gun_index==2) ? 1: 0);
  7134. }
  7135. else
  7136. {
  7137. tempIndex = gun_index;
  7138. }
  7139. for (int index = 0; index < CCS_QUANTITY; index++)
  7140. {
  7141. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7142. {
  7143. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7144. }
  7145. } // END OF CCS_QUANTITY
  7146. }
  7147. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7148. {
  7149. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7150. {
  7151. tempIndex = ((gun_index==2) ? 1: 0);
  7152. }
  7153. else
  7154. {
  7155. tempIndex = gun_index;
  7156. }
  7157. for (int index = 0; index < GB_QUANTITY; index++)
  7158. {
  7159. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7160. {
  7161. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7162. }
  7163. } // END OF GB_QUANTITY
  7164. }
  7165. else if(gunType[gun_index] == GUN_TYPE_DO)
  7166. {
  7167. tempIndex = gun_index;
  7168. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7169. {
  7170. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7171. {
  7172. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7173. }
  7174. }
  7175. }
  7176. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7177. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7178. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7179. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7180. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7181. }
  7182. // Message create ====================================================================================================
  7183. if(TRUE)
  7184. {
  7185. json_object *MeterValueReq = json_object_new_object();
  7186. json_object *MeterValues = json_object_new_array();
  7187. json_object *sampledValues = json_object_new_array();
  7188. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7189. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7190. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7191. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7192. {
  7193. json_object *MeterValue = json_object_new_object();
  7194. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7195. {
  7196. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7197. {
  7198. json_object *sampledValue = json_object_new_object();
  7199. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7200. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7201. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7202. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7203. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7204. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7205. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7206. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7207. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7208. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7209. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7210. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7211. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7212. json_object_array_add(sampledValues, sampledValue);
  7213. }
  7214. }
  7215. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7216. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7217. json_object_array_add(MeterValues, MeterValue);
  7218. }
  7219. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7220. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7221. ,gun_index + 1
  7222. ,MESSAGE_TYPE_CALL
  7223. ,guid
  7224. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7225. json_object_put(MeterValueReq);
  7226. }
  7227. // Put request guid to hash map
  7228. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7229. 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*/)
  7230. {
  7231. result = PASS;
  7232. //DEBUG_INFO("MeterValues mapitem pass\n");
  7233. }
  7234. if((dataType != ReadingContext_Trigger) &&
  7235. (dataType != ReadingContext_Sample_Clock) &&
  7236. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7237. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7238. else
  7239. {
  7240. if(FirstHeartBeat)
  7241. LWS_Send(queuedata +2);
  7242. }
  7243. return result;
  7244. }
  7245. int sendLogStatusNotificationRequest(char *status)
  7246. {
  7247. mtrace();
  7248. int result = PASS;
  7249. char message[4096]={0};
  7250. char guid[37]={0};
  7251. char tempdata[128]={0};
  7252. json_object *LogStatusNotification = json_object_new_object();
  7253. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7254. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7255. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7256. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7257. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7258. random_uuid(guid);
  7259. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7260. json_object_put(LogStatusNotification);
  7261. LWS_Send(message);
  7262. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7263. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7264. {
  7265. result = PASS;
  7266. }
  7267. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7268. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7269. return result;
  7270. }
  7271. int sendSecurityEventNotificationRequest()
  7272. {
  7273. mtrace();
  7274. int result = PASS;
  7275. char message[4096]={0};
  7276. char guid[37]={0};
  7277. char tempdata[128]={0};
  7278. json_object *SecurityEventNotification = json_object_new_object();
  7279. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7280. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7281. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7282. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7283. random_uuid(guid);
  7284. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7285. json_object_put(SecurityEventNotification);
  7286. LWS_Send(message);
  7287. sprintf(tempdata, "SecurityEventNotification,0");
  7288. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7289. {
  7290. result = PASS;
  7291. }
  7292. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7293. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7294. return result;
  7295. }
  7296. int sendSignCertificateRequest()
  7297. {
  7298. mtrace();
  7299. int result = PASS;
  7300. char message[4096]={0};
  7301. char guid[37]={0};
  7302. char tempdata[128]={0};
  7303. json_object *SignCertificate = json_object_new_object();
  7304. DEBUG_INFO("sendSignCertificateRequest...\n");
  7305. // Read csr file content
  7306. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7307. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7308. char *line = NULL;
  7309. size_t len = 0;
  7310. while(getline(&line, &len, fp) != -1)
  7311. {
  7312. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7313. {
  7314. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7315. }
  7316. }
  7317. fclose(fp);
  7318. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7319. random_uuid(guid);
  7320. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7321. json_object_put(SignCertificate);
  7322. LWS_Send(message);
  7323. sprintf(tempdata, "SignCertificate,0");
  7324. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7325. {
  7326. result = PASS;
  7327. }
  7328. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7329. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7330. return result;
  7331. }
  7332. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7333. {
  7334. mtrace();
  7335. int result = PASS;
  7336. char message[110]={0};
  7337. char guid[37]={0};
  7338. char tempdata[65]={0};
  7339. json_object *FirmwareStatusNotification = json_object_new_object();
  7340. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7341. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7342. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7343. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7344. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7345. random_uuid(guid);
  7346. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7347. json_object_put(FirmwareStatusNotification);
  7348. LWS_Send(message);
  7349. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7350. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7351. {
  7352. result = PASS;
  7353. }
  7354. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7355. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7356. return result;
  7357. }
  7358. //==========================================
  7359. // send confirm routine
  7360. //==========================================
  7361. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7362. {
  7363. mtrace();
  7364. int result = FAIL;
  7365. char message[100]={0};
  7366. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7367. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7368. LWS_Send(message);
  7369. result = TRUE;
  7370. return result;
  7371. }
  7372. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7373. {
  7374. mtrace();
  7375. int result = FAIL;
  7376. char message[100]={0};
  7377. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7378. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7379. LWS_Send(message);
  7380. result = TRUE;
  7381. return result;
  7382. }
  7383. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7384. {
  7385. mtrace();
  7386. int result = FAIL;
  7387. char message[100]={0};
  7388. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7389. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7390. LWS_Send(message);
  7391. result = TRUE;
  7392. return result;
  7393. }
  7394. int sendClearCacheConfirmation(char *uuid,char *payload)
  7395. {
  7396. mtrace();
  7397. int result = FAIL;
  7398. char message[500]={0};
  7399. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7400. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7401. LWS_Send(message);
  7402. return result;
  7403. }
  7404. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7405. {
  7406. mtrace();
  7407. int result = FAIL;
  7408. char message[500]={0};
  7409. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7410. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7411. LWS_Send(message);
  7412. return result;
  7413. }
  7414. int sendDataTransferConfirmation(char *uuid,char *payload)
  7415. {
  7416. mtrace();
  7417. char statusStr[20]={0};
  7418. char dataStr[10]={0};
  7419. char sstr[20]={0};
  7420. int c = 0;
  7421. char *loc;
  7422. int result = FAIL;
  7423. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7424. /**********************status**************************/
  7425. loc = strstr(payload, "status");
  7426. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7427. c = 0;
  7428. while (loc[3+strlen("status")+c] != '\"')
  7429. {
  7430. sstr[c] = loc[3+strlen("status")+c];
  7431. c++;
  7432. }
  7433. sstr[c] = '\0';
  7434. strcpy(statusStr, sstr);
  7435. /**********************data**************************/
  7436. loc = strstr(payload, "data");
  7437. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7438. c = 0;
  7439. while (loc[3+strlen("data")+c] != '\"')
  7440. {
  7441. sstr[c] = loc[3+strlen("data")+c];
  7442. c++;
  7443. }
  7444. sstr[c] = '\0';
  7445. strcpy(dataStr, sstr);
  7446. return result;
  7447. }
  7448. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7449. {
  7450. mtrace();
  7451. int result = FAIL;
  7452. char message[1000]={0};
  7453. int CompositeScheduleIndex = 0;
  7454. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7455. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7456. if(nPeriod == 0)
  7457. {
  7458. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7459. {
  7460. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7461. ,MESSAGE_TYPE_CALLRESULT
  7462. ,uuid
  7463. ,payload
  7464. ,connectorIdInt);
  7465. }
  7466. else
  7467. {
  7468. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7469. ,MESSAGE_TYPE_CALLRESULT
  7470. ,uuid
  7471. ,payload
  7472. ,connectorIdInt
  7473. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7474. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7475. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7476. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7477. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7478. }
  7479. }
  7480. else
  7481. {
  7482. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7483. ,MESSAGE_TYPE_CALLRESULT
  7484. ,uuid
  7485. ,payload
  7486. ,connectorIdInt
  7487. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7488. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7489. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7490. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7491. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7492. {
  7493. if (idx_sample == 0)
  7494. {
  7495. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7496. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7497. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7498. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7499. }
  7500. else
  7501. {
  7502. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7503. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7504. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7505. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7506. }
  7507. }
  7508. sprintf(message + strlen(message), "]}}]");
  7509. }
  7510. LWS_Send(message);
  7511. result = TRUE;
  7512. return result;
  7513. }
  7514. int sendGetConfigurationConfirmation(char *uuid)
  7515. {
  7516. mtrace();
  7517. int result = FAIL;
  7518. int MaxKeySupported = 0;
  7519. int sentConfigurationNumber= 0;
  7520. int sentunConfigurationNumber= 0;
  7521. char message[1024*10]={0};
  7522. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7523. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7524. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7525. ,MESSAGE_TYPE_CALLRESULT
  7526. ,uuid );
  7527. //configuration key
  7528. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7529. {
  7530. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7531. {
  7532. if (sentConfigurationNumber == 0)
  7533. {
  7534. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7535. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7536. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7537. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7538. }
  7539. else
  7540. {
  7541. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7542. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7543. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7544. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7545. }
  7546. sentConfigurationNumber = sentConfigurationNumber + 1;
  7547. }
  7548. }
  7549. sprintf(message + strlen(message), "]");
  7550. if(UnknownKeynum != 0)
  7551. {
  7552. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7553. //unkown key
  7554. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7555. {
  7556. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7557. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7558. if(sentunConfigurationNumber == 0)
  7559. {
  7560. sprintf(message + strlen(message), "\"%s\""
  7561. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7562. }
  7563. else
  7564. {
  7565. sprintf(message + strlen(message), ",\"%s\""
  7566. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7567. }
  7568. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7569. }
  7570. sprintf(message + strlen(message), "]");
  7571. }
  7572. sprintf(message + strlen(message), "}]");
  7573. LWS_Send(message);
  7574. return result;
  7575. }
  7576. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7577. {
  7578. mtrace();
  7579. int result = FAIL;
  7580. char message[400]={0};
  7581. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7582. if(strcmp(payload,"")==0)
  7583. {
  7584. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7585. }
  7586. else
  7587. {
  7588. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7589. }
  7590. LWS_Send(message);
  7591. result = TRUE;
  7592. return result;
  7593. }
  7594. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7595. {
  7596. mtrace();
  7597. int result = FAIL;
  7598. char message[80]={0};
  7599. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7600. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  7601. LWS_Send(message);
  7602. result = TRUE;
  7603. return result;
  7604. }
  7605. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7606. {
  7607. mtrace();
  7608. int result = FAIL;
  7609. char message[80]={0};
  7610. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7611. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7612. LWS_Send(message);
  7613. result = TRUE;
  7614. return result;
  7615. }
  7616. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7617. {
  7618. mtrace();
  7619. int result = FAIL;
  7620. char message[80]={0};
  7621. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7622. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7623. LWS_Send(message);
  7624. result = TRUE;
  7625. return result;
  7626. }
  7627. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7628. {
  7629. mtrace();
  7630. int result = FAIL;
  7631. char message[80]={0};
  7632. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7633. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7634. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7635. LWS_Send(message);
  7636. result = TRUE;
  7637. return result;
  7638. }
  7639. int sendResetConfirmation(char *uuid,char *payload)
  7640. {
  7641. mtrace();
  7642. int result = FAIL;
  7643. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7644. char message[80]={0};
  7645. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  7646. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7647. LWS_Send(message);
  7648. result = TRUE;
  7649. return result;
  7650. }
  7651. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7652. {
  7653. mtrace();
  7654. int result = FAIL;
  7655. char message[500]={0};
  7656. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7657. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7658. LWS_Send(message);
  7659. result = TRUE;
  7660. return result;
  7661. }
  7662. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7663. {
  7664. mtrace();
  7665. int result = FAIL;
  7666. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7667. char message[80]={0};
  7668. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7669. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7670. LWS_Send(message);
  7671. result = TRUE;
  7672. return result;
  7673. }
  7674. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7675. {
  7676. mtrace();
  7677. int result = FAIL;
  7678. char message[80]={0};
  7679. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7680. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7681. LWS_Send(message);
  7682. result = TRUE;
  7683. return result;
  7684. }
  7685. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7686. {
  7687. mtrace();
  7688. int result = FAIL;
  7689. char message[80]={0};
  7690. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7691. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7692. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7693. LWS_Send(message);
  7694. result = TRUE;
  7695. return result;
  7696. }
  7697. int sendUpdateFirmwareConfirmation(char *uuid)
  7698. {
  7699. mtrace();
  7700. int result = FAIL;
  7701. char message[60]={0};
  7702. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7703. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7704. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7705. LWS_Send(message);
  7706. result = TRUE;
  7707. return result;
  7708. }
  7709. int sendCertificateSignedConfirmation(char *uuid)
  7710. {
  7711. mtrace();
  7712. int result = PASS;
  7713. char message[4096]={0};
  7714. json_object *CertificateSigned = json_object_new_object();
  7715. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7716. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  7717. sprintf(message,"[%d,\"%s\",%s]"
  7718. ,MESSAGE_TYPE_CALLRESULT
  7719. ,uuid
  7720. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7721. json_object_put(CertificateSigned);
  7722. LWS_Send(message);
  7723. return result;
  7724. }
  7725. int sendDeleteCertificateConfirmation(char *uuid)
  7726. {
  7727. mtrace();
  7728. int result = PASS;
  7729. char message[4096]={0};
  7730. json_object *DeleteCertificate = json_object_new_object();
  7731. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7732. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  7733. sprintf(message,"[%d,\"%s\",%s]"
  7734. ,MESSAGE_TYPE_CALLRESULT
  7735. ,uuid
  7736. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7737. json_object_put(DeleteCertificate);
  7738. LWS_Send(message);
  7739. return result;
  7740. }
  7741. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7742. {
  7743. mtrace();
  7744. int result = PASS;
  7745. char message[4096]={0};
  7746. json_object *ExtendedTriggerMessage = json_object_new_object();
  7747. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7748. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  7749. sprintf(message,"[%d,\"%s\",%s]"
  7750. ,MESSAGE_TYPE_CALLRESULT
  7751. ,uuid
  7752. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7753. json_object_put(ExtendedTriggerMessage);
  7754. LWS_Send(message);
  7755. return result;
  7756. }
  7757. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7758. {
  7759. mtrace();
  7760. int result = PASS;
  7761. char message[4096]={0};
  7762. json_object *GetInstalledCertificateIds = json_object_new_object();
  7763. json_object *certificateHashDataDatas = json_object_new_array();
  7764. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7765. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  7766. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7767. {
  7768. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7769. {
  7770. json_object *certificateHashData = json_object_new_object();
  7771. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7772. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7773. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7774. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7775. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7776. }
  7777. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7778. }
  7779. else
  7780. {
  7781. json_object_put(certificateHashDataDatas);
  7782. }
  7783. sprintf(message,"[%d,\"%s\",%s]"
  7784. ,MESSAGE_TYPE_CALLRESULT
  7785. ,uuid
  7786. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7787. json_object_put(GetInstalledCertificateIds);
  7788. LWS_Send(message);
  7789. return result;
  7790. }
  7791. int sendGetLogConfirmation(char *uuid)
  7792. {
  7793. mtrace();
  7794. int result = PASS;
  7795. char message[4096]={0};
  7796. json_object *GetLog = json_object_new_object();
  7797. DEBUG_INFO("sendGetLogConfirmation...\n");
  7798. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  7799. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  7800. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  7801. sprintf(message,"[%d,\"%s\",%s]"
  7802. ,MESSAGE_TYPE_CALLRESULT
  7803. ,uuid
  7804. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7805. json_object_put(GetLog);
  7806. LWS_Send(message);
  7807. return result;
  7808. }
  7809. int sendInstallCertificateConfirmation(char *uuid)
  7810. {
  7811. mtrace();
  7812. int result = PASS;
  7813. char message[4096]={0};
  7814. json_object *InstallCertificate = json_object_new_object();
  7815. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7816. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  7817. sprintf(message,"[%d,\"%s\",%s]"
  7818. ,MESSAGE_TYPE_CALLRESULT
  7819. ,uuid
  7820. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7821. json_object_put(InstallCertificate);
  7822. LWS_Send(message);
  7823. return result;
  7824. }
  7825. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7826. {
  7827. mtrace();
  7828. int result = PASS;
  7829. char message[4096]={0};
  7830. json_object *SignedUpdateFirmware = json_object_new_object();
  7831. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7832. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  7833. sprintf(message,"[%d,\"%s\",%s]"
  7834. ,MESSAGE_TYPE_CALLRESULT
  7835. ,uuid
  7836. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7837. json_object_put(SignedUpdateFirmware);
  7838. LWS_Send(message);
  7839. return result;
  7840. }
  7841. int sendUnknownConfirmation(char *uuid)
  7842. {
  7843. mtrace();
  7844. int result = PASS;
  7845. char message[256]={0};
  7846. DEBUG_INFO("sendUnknownConfirmation...\n");
  7847. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7848. LWS_Send(message);
  7849. return result;
  7850. }
  7851. //==========================================
  7852. // Handle server request routine Start
  7853. //==========================================
  7854. int handleCancelReservationRequest(char *uuid, char *payload)
  7855. {
  7856. mtrace();
  7857. int result = FAIL;
  7858. int gunNO = 0;
  7859. int reservationIdInt = -1;
  7860. char comfirmstr[20];
  7861. DEBUG_INFO("handleCancelReservationRequest...\n");
  7862. json_object *CancelReservation;
  7863. CancelReservation = json_tokener_parse(payload);
  7864. if(!is_error(CancelReservation))
  7865. {
  7866. // Required data
  7867. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7868. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7869. }
  7870. json_object_put(CancelReservation);
  7871. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7872. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7873. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7874. if(reservationIdInt != -1)
  7875. {
  7876. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7877. //check Transaction active
  7878. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7879. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7880. {
  7881. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7882. {
  7883. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7884. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7885. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7886. {
  7887. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7888. }
  7889. else
  7890. {
  7891. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7892. }
  7893. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7894. goto end;
  7895. }
  7896. }
  7897. for (int index = 0; index < CCS_QUANTITY; index++)
  7898. {
  7899. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7900. {
  7901. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7902. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7903. if(gunType[2] == GUN_TYPE_CCS)
  7904. {
  7905. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7906. }
  7907. else
  7908. {
  7909. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7910. }
  7911. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7912. goto end;
  7913. }
  7914. }
  7915. for (int index = 0; index < GB_QUANTITY; index++)
  7916. {
  7917. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7918. {
  7919. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7920. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7921. if(gunType[2] == GUN_TYPE_GBT)
  7922. {
  7923. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7924. }
  7925. else
  7926. {
  7927. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7928. }
  7929. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7930. goto end;
  7931. }
  7932. }
  7933. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7934. {
  7935. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7936. {
  7937. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7938. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7939. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7940. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7941. goto end;
  7942. }
  7943. }
  7944. for (int index = 0; index < AC_QUANTITY; index++)
  7945. {
  7946. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7947. {
  7948. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7949. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7950. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7951. {
  7952. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7953. }
  7954. else
  7955. {
  7956. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7957. }
  7958. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7959. goto end;
  7960. }
  7961. }
  7962. }
  7963. //The reservationId does NOT match the reservationId
  7964. sendCancelReservationConfirmation(uuid, comfirmstr);
  7965. end:
  7966. // Fill in ocpp packet uuid
  7967. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  7968. return result;
  7969. }
  7970. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7971. {
  7972. mtrace();
  7973. int result = FAIL;
  7974. int gunIndex = -1;
  7975. char typeStr[16]={0};
  7976. char comfirmstr[20];
  7977. int specificId = FALSE;
  7978. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7979. json_object *ChangeAvailability;
  7980. ChangeAvailability = json_tokener_parse(payload);
  7981. if(!is_error(ChangeAvailability))
  7982. {
  7983. // Required data
  7984. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7985. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7986. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7987. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7988. }
  7989. json_object_put(ChangeAvailability);
  7990. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7991. {
  7992. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7993. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7994. }
  7995. else if(gunIndex == 0)
  7996. {
  7997. for(int i=0; i < gunTotalNumber; i++)
  7998. {
  7999. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8000. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8001. }
  8002. }
  8003. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8004. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8005. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8006. {
  8007. specificId = TRUE;
  8008. }
  8009. if(specificId == FALSE)
  8010. goto end;
  8011. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8012. {
  8013. //----------------------gunIndex is 0 ------------------------------------------------//
  8014. if(gunIndex == 0)
  8015. {
  8016. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8017. {
  8018. for(int i=0; i < gunTotalNumber; i++)
  8019. {
  8020. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8021. {
  8022. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8023. {
  8024. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8025. {
  8026. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8027. goto end;
  8028. }
  8029. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8030. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8031. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8032. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8033. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8034. {
  8035. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8036. goto end;
  8037. }
  8038. }
  8039. }//END FOR CHAdeMO_QUANTITY
  8040. for (int index = 0; index < CCS_QUANTITY; index++)
  8041. {
  8042. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8043. {
  8044. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8045. {
  8046. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8047. goto end;
  8048. }
  8049. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8050. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8051. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8052. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8053. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8054. {
  8055. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8056. goto end;
  8057. }
  8058. }
  8059. }//END FOR CCS_QUANTITY
  8060. for (int index = 0; index < GB_QUANTITY; index++)
  8061. {
  8062. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8063. {
  8064. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8065. {
  8066. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8067. goto end;
  8068. }
  8069. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8070. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8071. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8072. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8073. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8074. {
  8075. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8076. goto end;
  8077. }
  8078. }
  8079. }// END FOR GB_QUANTITY
  8080. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8081. {
  8082. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8083. {
  8084. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8085. {
  8086. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8087. goto end;
  8088. }
  8089. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8090. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8091. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8092. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8093. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8094. {
  8095. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8096. goto end;
  8097. }
  8098. }
  8099. }// END FOR GENERAL_GUN_QUANTITY
  8100. for (int index = 0; index < AC_QUANTITY; index++)
  8101. {
  8102. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8103. {
  8104. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8105. {
  8106. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8107. goto end;
  8108. }
  8109. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8110. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8111. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8112. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8113. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8114. {
  8115. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8116. goto end;
  8117. }
  8118. }
  8119. }//END FOR AC_QUANTITY
  8120. }// END FOR gunTotalNumber
  8121. }
  8122. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8123. {
  8124. for(int i=0; i < gunTotalNumber; i++)
  8125. {
  8126. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8127. {
  8128. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8129. goto end;
  8130. }
  8131. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8132. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8133. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8134. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8135. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8136. {
  8137. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8138. goto end;
  8139. }
  8140. }
  8141. }
  8142. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8143. goto end;
  8144. }
  8145. //----------------------gunIndex is not 0 ------------------------------------------------//
  8146. //check Transaction active
  8147. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8148. {
  8149. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8150. {
  8151. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8152. {
  8153. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8154. goto end;
  8155. }
  8156. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8157. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8158. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8159. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8160. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8161. {
  8162. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8163. goto end;
  8164. }
  8165. else
  8166. {
  8167. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8168. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8169. goto end;
  8170. }
  8171. }
  8172. }//END FOR CHAdeMO_QUANTITY
  8173. for (int index = 0; index < CCS_QUANTITY; index++)
  8174. {
  8175. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8176. {
  8177. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8178. {
  8179. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8180. goto end;
  8181. }
  8182. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8183. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8184. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8185. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8186. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8187. {
  8188. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8189. goto end;
  8190. }
  8191. else
  8192. {
  8193. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8194. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8195. goto end;
  8196. }
  8197. }
  8198. }//END FOR CCS_QUANTITY
  8199. for (int index = 0; index < GB_QUANTITY; index++)
  8200. {
  8201. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8202. {
  8203. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8204. {
  8205. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8206. goto end;
  8207. }
  8208. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8209. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8210. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8211. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8212. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8213. {
  8214. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8215. goto end;
  8216. }
  8217. else
  8218. {
  8219. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8220. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8221. goto end;
  8222. }
  8223. }
  8224. }// END FOR GB_QUANTITY
  8225. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8226. {
  8227. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8228. {
  8229. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8230. {
  8231. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8232. goto end;
  8233. }
  8234. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8235. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8236. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8237. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8238. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8239. {
  8240. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8241. goto end;
  8242. }
  8243. else
  8244. {
  8245. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8246. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8247. goto end;
  8248. }
  8249. }
  8250. }// END FOR GENERAL_GUN_QUANTITY
  8251. for (int index = 0; index < AC_QUANTITY; index++)
  8252. {
  8253. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8254. {
  8255. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8256. {
  8257. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8258. goto end;
  8259. }
  8260. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8261. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8262. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8263. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8264. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8265. {
  8266. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8267. goto end;
  8268. }
  8269. else
  8270. {
  8271. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8272. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8273. goto end;
  8274. }
  8275. }
  8276. }//END FOR AC_QUANTITY
  8277. }//END FOR AvailabilityTypeStr[Inoperative]
  8278. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8279. {
  8280. //----------------------gunIndex is 0 ------------------------------------------------//
  8281. if(gunIndex == 0)
  8282. {
  8283. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8284. {
  8285. for(int i=0; i < gunTotalNumber; i++)
  8286. {
  8287. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8288. {
  8289. 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
  8290. {
  8291. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8292. goto end;
  8293. }
  8294. }//END FOR CHAdeMO_QUANTITY
  8295. for (int index = 0; index < CCS_QUANTITY; index++)
  8296. {
  8297. 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
  8298. {
  8299. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8300. goto end;
  8301. }
  8302. }//END FOR CCS_QUANTITY
  8303. for (int index = 0; index < GB_QUANTITY; index++)
  8304. {
  8305. 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
  8306. {
  8307. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8308. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8309. goto end;
  8310. }
  8311. }// END FOR GB_QUANTITY
  8312. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8313. {
  8314. 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
  8315. {
  8316. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8317. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8318. goto end;
  8319. }
  8320. }// END FOR GENERAL_GUN_QUANTITY
  8321. for (int index = 0; index < AC_QUANTITY; index++)
  8322. {
  8323. 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
  8324. {
  8325. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8326. goto end;
  8327. }
  8328. }//END FOR CHAdeMO_QUANTITY
  8329. }// END FOR gunTotalNumber
  8330. }
  8331. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8332. {
  8333. for(int i=0; i < gunTotalNumber; i++)
  8334. {
  8335. for (int index = 0; index < AC_QUANTITY; index++)
  8336. {
  8337. 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
  8338. {
  8339. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8340. goto end;
  8341. }
  8342. }//END FOR CHAdeMO_QUANTITY
  8343. } // END FOR gunTotalNumber
  8344. }
  8345. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8346. goto end;
  8347. }
  8348. //----------------------gunIndex is not 0 ------------------------------------------------//
  8349. //check Transaction active
  8350. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8351. {
  8352. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8353. {
  8354. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8355. goto end;
  8356. }
  8357. }//END FOR CHAdeMO_QUANTITY
  8358. for (int index = 0; index < CCS_QUANTITY; index++)
  8359. {
  8360. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8361. {
  8362. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8363. goto end;
  8364. }
  8365. }//END FOR CCS_QUANTITY
  8366. for (int index = 0; index < GB_QUANTITY; index++)
  8367. {
  8368. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8369. {
  8370. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8371. goto end;
  8372. }
  8373. }// END FOR GB_QUANTITY
  8374. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8375. {
  8376. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8377. {
  8378. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8379. goto end;
  8380. }
  8381. }// END FOR GENERAL_GUN_QUANTITY
  8382. for (int index = 0; index < AC_QUANTITY; index++)
  8383. {
  8384. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8385. {
  8386. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8387. goto end;
  8388. }
  8389. }//END FOR AC_QUANTITY
  8390. }//END FOR AvailabilityTypeStr[Operative]
  8391. end:
  8392. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8393. {
  8394. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8395. }
  8396. else
  8397. {
  8398. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8399. }
  8400. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8401. {
  8402. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8403. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8404. }
  8405. else if(gunIndex == 0)
  8406. {
  8407. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8408. {
  8409. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8410. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8411. }
  8412. }
  8413. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8414. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8415. return result;
  8416. }
  8417. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8418. {
  8419. mtrace();
  8420. int valueInvalid = NO;
  8421. int result = FAIL;
  8422. char keystr[40]={0};
  8423. char valuestr[501]={0}; //value should be limited in 500 bytes
  8424. char comfirmstr[20]={0};
  8425. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8426. json_object *ChangeConfiguration;
  8427. ChangeConfiguration = json_tokener_parse(payload);
  8428. if(!is_error(ChangeConfiguration))
  8429. {
  8430. // Required data
  8431. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8432. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8433. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8434. {
  8435. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8436. }
  8437. else
  8438. {
  8439. valueInvalid = YES;
  8440. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8441. }
  8442. }
  8443. json_object_put(ChangeConfiguration);
  8444. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  8445. {
  8446. DEBUG_ERROR("Payload is null or value is invalid.\n");
  8447. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8448. }
  8449. else
  8450. {
  8451. int status = setKeyValue(keystr, valuestr);
  8452. switch(status)
  8453. {
  8454. case ConfigurationStatus_Accepted:
  8455. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8456. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8457. StoreConfigurationTable();
  8458. break;
  8459. case RebootRequired:
  8460. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8461. StoreConfigurationTable();
  8462. break;
  8463. case NotSupported:
  8464. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8465. break;
  8466. case ConfigurationStatus_Rejected:
  8467. default:
  8468. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8469. break;
  8470. }
  8471. }
  8472. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8473. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8474. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8475. {
  8476. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8477. SetOcppConnStatus(FALSE);
  8478. }
  8479. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8480. {
  8481. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8482. }
  8483. return result;
  8484. }
  8485. int handleClearCacheRequest(char *uuid, char *payload)
  8486. {
  8487. mtrace();
  8488. int result = FAIL;
  8489. char comfirmstr[20];
  8490. char rmFileCmd[100]={0};
  8491. struct stat stats;
  8492. DEBUG_INFO("handleClearCacheRequest...\n");
  8493. stat("/Storage/OCPP", &stats);
  8494. // Check for directory existence
  8495. if (S_ISDIR(stats.st_mode) == 1)
  8496. {}
  8497. else
  8498. {
  8499. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8500. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  8501. system(rmFileCmd);
  8502. }
  8503. if(OCPP_cleanLocalCache())
  8504. {
  8505. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8506. }
  8507. else
  8508. {
  8509. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8510. }
  8511. sendClearCacheConfirmation(uuid, comfirmstr);
  8512. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8513. return result;
  8514. }
  8515. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8516. {
  8517. mtrace();
  8518. int result = FAIL;
  8519. int resultRename;
  8520. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8521. char chargingProfilePurposeStr[26]={0};
  8522. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8523. char tempchargingProfilePurposeStr[26]={0};
  8524. char str[100]={0};
  8525. char fname[200]={0};
  8526. char comfirmstr[20]={0};
  8527. char word[1600]={0};
  8528. int clearflag = FALSE;
  8529. int chargingProfileIdIsNULL = FALSE;
  8530. int connectorIsNULL = FALSE;
  8531. int chargingProfilePurposeIsNULL = FALSE;
  8532. int stackLevelIsNULL = FALSE;
  8533. //int GotoEnd = FALSE;
  8534. FILE *fptr1, *fptr2;
  8535. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  8536. int n_chargingProfile=0;
  8537. int isEmptyFile = FALSE;
  8538. char sLineWord[1600]={0};
  8539. char chargingProfiles[10][100]={0};
  8540. int ChargeProfileCount = 0;
  8541. int ch;
  8542. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8543. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8544. json_object *ClearChargingProfile;
  8545. ClearChargingProfile = json_tokener_parse(payload);
  8546. if(!is_error(ClearChargingProfile))
  8547. {
  8548. // Optional data
  8549. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8550. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8551. else
  8552. chargingProfileIdIsNULL = TRUE;
  8553. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8554. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8555. else
  8556. connectorIsNULL = TRUE;
  8557. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8558. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8559. else
  8560. chargingProfilePurposeIsNULL = TRUE;
  8561. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8562. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8563. else
  8564. stackLevelIsNULL = TRUE;
  8565. }
  8566. json_object_put(ClearChargingProfile);
  8567. if(connectorIsNULL == FALSE)
  8568. {
  8569. switch(connectorIdInt)
  8570. {
  8571. case 0:
  8572. if(chargingProfilePurposeIsNULL == TRUE)
  8573. {
  8574. int l = 0;
  8575. strcpy(fname, ChargePointMaxProfile_JSON);
  8576. if((access(fname,F_OK))!=-1)
  8577. {
  8578. strcpy(chargingProfiles[l], fname);
  8579. l = l + 1;
  8580. }
  8581. strcpy(fname, TxDefaultProfile_0_JSON);
  8582. if((access(fname,F_OK))!=-1)
  8583. {
  8584. strcpy(chargingProfiles[l], fname);
  8585. l = l + 1;
  8586. }
  8587. ChargeProfileCount = l;
  8588. }
  8589. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8590. {
  8591. strcpy(fname, ChargePointMaxProfile_JSON);
  8592. if((access(fname,F_OK))!=-1)
  8593. {
  8594. strcpy(chargingProfiles[0], fname);
  8595. ChargeProfileCount = 1;
  8596. }
  8597. }
  8598. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8599. {
  8600. strcpy(fname, TxDefaultProfile_0_JSON);
  8601. if((access(fname,F_OK))!=-1)
  8602. {
  8603. strcpy(chargingProfiles[0], fname);
  8604. ChargeProfileCount = 1;
  8605. }
  8606. }
  8607. break;
  8608. default:
  8609. if(chargingProfilePurposeIsNULL == TRUE)
  8610. {
  8611. int m = 0;
  8612. memset(fname, 0, ARRAY_SIZE(fname));
  8613. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8614. if((access(fname,F_OK))!=-1)
  8615. {
  8616. strcpy(chargingProfiles[m], fname);
  8617. m = m + 1;
  8618. }
  8619. memset(fname, 0, ARRAY_SIZE(fname));
  8620. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8621. if((access(fname,F_OK))!=-1)
  8622. {
  8623. strcpy(chargingProfiles[m], fname);
  8624. m = m + 1;
  8625. }
  8626. ChargeProfileCount = m;
  8627. }
  8628. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8629. {
  8630. //strcpy(fname, TxDefaultProfile_1_JSON);
  8631. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8632. if((access(fname,F_OK))!=-1)
  8633. {
  8634. strcpy(chargingProfiles[0], fname);
  8635. ChargeProfileCount = 1;
  8636. }
  8637. }
  8638. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8639. {
  8640. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8641. if((access(fname,F_OK))!=-1)
  8642. {
  8643. strcpy(chargingProfiles[0], fname);
  8644. ChargeProfileCount = 1;
  8645. }
  8646. //strcpy(fname, TxProfile_1_JSON);
  8647. }
  8648. //strcpy(fname, ChargePointMaxProfile_JSON );
  8649. break;
  8650. }
  8651. }
  8652. else // Check all Charging Profiles
  8653. {
  8654. int i = 0;
  8655. char fnametemp[200]={0};
  8656. ChargeProfileCount = 0;
  8657. //Check ChargePointMaxProfile.json exit
  8658. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8659. {
  8660. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  8661. i = i + 1;
  8662. }
  8663. //Check TxDefaultProfile_0.json exit
  8664. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8665. {
  8666. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  8667. i = i + 1;
  8668. }
  8669. //Check TxDefaultProfile_%d.json
  8670. for(int j=1; j <= gunTotalNumber; j++)
  8671. {
  8672. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8673. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8674. if((access(fnametemp,F_OK))!=-1)
  8675. {
  8676. strcpy(chargingProfiles[i], fnametemp);
  8677. i = i + 1;
  8678. }
  8679. }
  8680. //Check TxProfile_%d.json
  8681. for(int j=1; j <= gunTotalNumber; j++)
  8682. {
  8683. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8684. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8685. if((access(fnametemp,F_OK))!=-1)
  8686. {
  8687. strcpy(chargingProfiles[i], fnametemp);
  8688. i = i + 1;
  8689. }
  8690. }
  8691. ChargeProfileCount = i;
  8692. }// End connectorIsNULL is TRUE
  8693. if(ChargeProfileCount == 0)
  8694. {
  8695. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8696. goto end;
  8697. }
  8698. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8699. {
  8700. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8701. goto end;
  8702. }
  8703. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8704. {
  8705. memset(str, 0, ARRAY_SIZE(str));
  8706. // clear temp file
  8707. sprintf(str,"rm -f %s",temp);
  8708. system(str);
  8709. for(int k=0; k < ChargeProfileCount; k++)
  8710. {
  8711. memset(str, 0, ARRAY_SIZE(str));
  8712. //clear file in C
  8713. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8714. system(str);
  8715. }
  8716. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8717. goto end;
  8718. }
  8719. else if(connectorIsNULL == TRUE)
  8720. {
  8721. for(int k=0; k < ChargeProfileCount; k++)
  8722. {
  8723. fptr1 = fopen(chargingProfiles[k], "r");
  8724. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  8725. //Check Charging Profile Count
  8726. while(fscanf(fptr1, "%s", word) != EOF)
  8727. {
  8728. //DEBUG_INFO("word=%s\n",word);
  8729. if(strstr(word, "chargingProfileId")!= NULL)
  8730. {
  8731. //DEBUG_INFO("test chargingProfileId \n");
  8732. n_chargingProfile = n_chargingProfile + 1;
  8733. //DEBUG_INFO("chargingProfileId Found\n");
  8734. }
  8735. }
  8736. rewind(fptr1);
  8737. //search Charging Profile Element
  8738. //int i= 0;
  8739. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8740. {
  8741. json_object *tmpProfilee;
  8742. tmpProfilee = json_tokener_parse(sLineWord);
  8743. if(!is_error(tmpProfilee))
  8744. {
  8745. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8746. {
  8747. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8748. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8749. }
  8750. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8751. {
  8752. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8753. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8754. }
  8755. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8756. {
  8757. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8758. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8759. }
  8760. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8761. {
  8762. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8763. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8764. }
  8765. }
  8766. json_object_put(tmpProfilee);
  8767. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8768. {
  8769. //------- not write to fptr2-------//
  8770. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8771. //clearflag = TRUE;
  8772. }
  8773. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8774. {
  8775. //------- not write to fptr2-------//
  8776. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8777. }
  8778. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8779. {
  8780. //------- not write to fptr2-------//
  8781. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8782. }
  8783. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8784. {
  8785. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8786. }
  8787. else
  8788. {
  8789. fprintf(fptr2, sLineWord);//writing data into file
  8790. }
  8791. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8792. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8793. if(clearflag == TRUE)
  8794. {
  8795. fclose(fptr1);
  8796. fclose(fptr2);
  8797. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8798. system(str);
  8799. // clear temp file
  8800. sprintf(str,"rm -f %s",temp);
  8801. system(str);
  8802. }
  8803. else
  8804. {
  8805. fclose(fptr1);
  8806. fclose(fptr2);
  8807. memset(str, 0, ARRAY_SIZE(str));
  8808. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8809. system(str);
  8810. resultRename = rename(temp, chargingProfiles[k]);
  8811. if(resultRename == 0)
  8812. {
  8813. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8814. }
  8815. else
  8816. {
  8817. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8818. }
  8819. if(comfirmstr[0]== 0)
  8820. {
  8821. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8822. }
  8823. //Check chargingProfile is empty file
  8824. /*------ Read the file ----------------*/
  8825. fptr1=fopen(chargingProfiles[k],"r");
  8826. ch=fgetc(fptr1);
  8827. rewind(fptr1);
  8828. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8829. if(ch!=EOF)
  8830. {
  8831. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8832. {
  8833. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8834. if(sLineWord[0]=='\0')
  8835. {
  8836. isEmptyFile = TRUE;
  8837. break;
  8838. }
  8839. else
  8840. {
  8841. isEmptyFile = FALSE;
  8842. break;
  8843. }
  8844. }
  8845. }
  8846. else
  8847. isEmptyFile = TRUE;
  8848. fclose(fptr1);
  8849. if(isEmptyFile == TRUE)
  8850. {
  8851. memset(str, 0, ARRAY_SIZE(str));
  8852. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8853. system(str);
  8854. }
  8855. }
  8856. }// End of while(int k=0; k < ChargePointCount; k++)
  8857. }
  8858. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8859. {
  8860. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8861. for(int k=0; k < ChargeProfileCount; k++)
  8862. {
  8863. fptr1 = fopen(chargingProfiles[k], "r");
  8864. fptr2 = fopen(temp, "w+");
  8865. //Check Charging Profile Count
  8866. while(fscanf(fptr1, "%s", word) != EOF)
  8867. {
  8868. //DEBUG_INFO("word=%s\n",word);
  8869. if(strstr(word, "chargingProfileId")!= NULL)
  8870. {
  8871. n_chargingProfile = n_chargingProfile + 1;
  8872. }
  8873. }
  8874. rewind(fptr1);
  8875. //search Charging Profile Element
  8876. //int i= 0;
  8877. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8878. {
  8879. json_object *tmpProfilee;
  8880. tmpProfilee = json_tokener_parse(sLineWord);
  8881. if(!is_error(tmpProfilee))
  8882. {
  8883. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8884. {
  8885. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8886. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8887. }
  8888. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8889. {
  8890. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8891. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8892. }
  8893. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8894. {
  8895. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8896. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8897. }
  8898. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8899. {
  8900. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8901. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8902. }
  8903. }
  8904. json_object_put(tmpProfilee);
  8905. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8906. {
  8907. //------- not write to fptr2-------//
  8908. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8909. //clearflag = TRUE;
  8910. }
  8911. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8912. {
  8913. //------- not write to fptr2-------//
  8914. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8915. }
  8916. else if(stackLevelIsNULL == TRUE)
  8917. {
  8918. //Clear Whole File
  8919. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8920. clearflag = TRUE;
  8921. break;
  8922. }
  8923. else
  8924. {
  8925. fprintf(fptr2, sLineWord);//writing data into file
  8926. }
  8927. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8928. }
  8929. if(clearflag == TRUE)
  8930. {
  8931. fclose(fptr1);
  8932. fclose(fptr2);
  8933. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8934. system(str);
  8935. // clear temp file
  8936. sprintf(str,"rm -f %s",temp);
  8937. system(str);
  8938. }
  8939. else
  8940. {
  8941. fclose(fptr1);
  8942. fclose(fptr2);
  8943. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8944. system(str);
  8945. resultRename = rename(temp, chargingProfiles[k]);
  8946. if(resultRename == 0)
  8947. {
  8948. DEBUG_INFO("File ChargingProfile renamed successfully");
  8949. }
  8950. else
  8951. {
  8952. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8953. }
  8954. if(comfirmstr[0]== 0)
  8955. {
  8956. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8957. }
  8958. //Check chargingProfile is empty file
  8959. /*------ Read the file ----------------*/
  8960. fptr1=fopen(chargingProfiles[k],"r");
  8961. ch=fgetc(fptr1);
  8962. rewind(fptr1);
  8963. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8964. if(ch!=EOF)
  8965. {
  8966. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8967. {
  8968. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8969. if(sLineWord[0]=='\0')
  8970. {
  8971. isEmptyFile = TRUE;
  8972. break;
  8973. }
  8974. else
  8975. {
  8976. isEmptyFile = FALSE;
  8977. break;
  8978. }
  8979. }
  8980. }
  8981. else
  8982. isEmptyFile = TRUE;
  8983. fclose(fptr1);
  8984. if(isEmptyFile == TRUE)
  8985. {
  8986. memset(str, 0, ARRAY_SIZE(str));
  8987. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8988. system(str);
  8989. }
  8990. /*------- End of reading ---------------*/
  8991. }
  8992. } // while(int k=0; k < ChargeProfileCount; k++)
  8993. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8994. end:
  8995. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8996. {
  8997. if(connectorIdInt == 0)
  8998. {
  8999. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9000. {
  9001. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9002. }
  9003. }
  9004. else
  9005. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9006. }
  9007. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9008. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9009. return result;
  9010. }
  9011. void createFirmwareVersionByDataTransfer(void)
  9012. {
  9013. json_object *FirmwareDataTransfer = json_object_new_object();
  9014. // AC & DC model
  9015. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9016. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9017. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9018. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9019. // DC model
  9020. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9021. {
  9022. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9023. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9024. (gunType[3] != GUN_TYPE_UNKNOWN))
  9025. {
  9026. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9027. }
  9028. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9029. {
  9030. // DS DM DW
  9031. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9032. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9033. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9034. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9035. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9036. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9037. }
  9038. else
  9039. {
  9040. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9041. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9042. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9043. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9044. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9045. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9046. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9047. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9048. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9049. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9050. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9051. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9052. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9053. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9054. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9055. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9056. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9057. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9058. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9059. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9060. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9061. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9062. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9063. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9064. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9065. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9066. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9067. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9068. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9069. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9070. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9071. }
  9072. }
  9073. // 4G model
  9074. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9075. {
  9076. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9077. }
  9078. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9079. json_object_put(FirmwareDataTransfer);
  9080. }
  9081. int handleDataTransferRequest(char *uuid, char *payload)
  9082. {
  9083. mtrace();
  9084. json_object *response = json_object_new_object();
  9085. int result = FAIL;
  9086. char tempvendorId[255]={0};
  9087. char tempmessageId[50]={0};
  9088. char tempdata[512]={0};
  9089. char message[2048]={0};
  9090. DEBUG_INFO("handleDataTransferRequest...\n");
  9091. if((uuid != NULL) && (payload != NULL))
  9092. {
  9093. json_object *DataTransfer;
  9094. DataTransfer = json_tokener_parse(payload);
  9095. if(!is_error(DataTransfer))
  9096. {
  9097. // Required data
  9098. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9099. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9100. // Optional data
  9101. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9102. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9103. if(json_object_object_get(DataTransfer, "data") != NULL)
  9104. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9105. result = PASS;
  9106. }
  9107. json_object_put(DataTransfer);
  9108. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9109. {
  9110. // Send all moudle firmware version on EVSE
  9111. createFirmwareVersionByDataTransfer();
  9112. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9113. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9114. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9115. json_object_put(response);
  9116. }
  9117. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9118. {
  9119. system("/usr/bin/run_tmate_restart.sh &");
  9120. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9121. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9122. json_object_put(response);
  9123. }
  9124. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9125. {
  9126. json_object *data;
  9127. data = json_tokener_parse(tempdata);
  9128. if(!is_error(data))
  9129. {
  9130. 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))
  9131. {
  9132. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9133. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9134. if(json_object_object_get(data, "SOC") != NULL)
  9135. {
  9136. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9137. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9138. }
  9139. if(json_object_object_get(data, "Energy") != NULL)
  9140. {
  9141. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9142. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9143. }
  9144. if(json_object_object_get(data, "Duration") != NULL)
  9145. {
  9146. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9147. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9148. }
  9149. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9150. }
  9151. else
  9152. {
  9153. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9154. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9155. }
  9156. }
  9157. else
  9158. {
  9159. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9160. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9161. }
  9162. json_object_put(data);
  9163. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9164. json_object_put(response);
  9165. }
  9166. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9167. {
  9168. json_object *data;
  9169. data = json_tokener_parse(tempdata);
  9170. if(!is_error(data))
  9171. {
  9172. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9173. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9174. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9175. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9176. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9177. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9178. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9179. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9180. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9181. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9182. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9183. }
  9184. else
  9185. {
  9186. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9187. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9188. }
  9189. json_object_put(data);
  9190. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9191. json_object_put(response);
  9192. }
  9193. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9194. {
  9195. json_object *data;
  9196. data = json_tokener_parse(tempdata);
  9197. if(!is_error(data))
  9198. {
  9199. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9200. if(json_object_object_get(data, "idToken") != NULL)
  9201. {
  9202. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9203. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9204. }
  9205. if(json_object_object_get(data, "price") != NULL)
  9206. {
  9207. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9208. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9209. }
  9210. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9211. }
  9212. else
  9213. {
  9214. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9215. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9216. }
  9217. json_object_put(data);
  9218. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9219. json_object_put(response);
  9220. }
  9221. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9222. {
  9223. json_object *data;
  9224. data = json_tokener_parse(tempdata);
  9225. if(!is_error(data))
  9226. {
  9227. if(json_object_object_get(data, "txId") != NULL)
  9228. {
  9229. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9230. for(int idx = 0;idx<gunTotalNumber;idx++)
  9231. {
  9232. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9233. {
  9234. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9235. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9236. if(json_object_object_get(data, "description") != NULL)
  9237. {
  9238. // California pricing V1.0
  9239. DEBUG_INFO("California pricing V1.0\n");
  9240. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9241. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9242. }
  9243. else
  9244. {
  9245. // California pricing V1.1
  9246. DEBUG_INFO("California pricing V1.1\n");
  9247. if(json_object_object_get(data, "timestamp") != NULL)
  9248. {
  9249. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9250. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9251. }
  9252. if(json_object_object_get(data, "meterValue") != NULL)
  9253. {
  9254. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9255. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9256. }
  9257. if(json_object_object_get(data, "cost") != NULL)
  9258. {
  9259. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9260. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9261. }
  9262. if(json_object_object_get(data, "state") != NULL)
  9263. {
  9264. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9265. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9266. }
  9267. if(json_object_object_get(data, "chargingPrice") != NULL)
  9268. {
  9269. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9270. {
  9271. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9272. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9273. }
  9274. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9275. {
  9276. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9277. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9278. }
  9279. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9280. {
  9281. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9282. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9283. }
  9284. }
  9285. if(json_object_object_get(data, "idlePrice") != NULL)
  9286. {
  9287. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9288. {
  9289. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9290. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9291. }
  9292. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9293. {
  9294. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9295. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9296. }
  9297. }
  9298. if(json_object_object_get(data, "nextPeriod") != NULL)
  9299. {
  9300. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9301. {
  9302. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9303. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9304. }
  9305. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9306. {
  9307. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9308. {
  9309. 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")));
  9310. 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"));
  9311. }
  9312. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9313. {
  9314. 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")));
  9315. 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"));
  9316. }
  9317. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9318. {
  9319. 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")));
  9320. 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"));
  9321. }
  9322. }
  9323. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9324. {
  9325. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9326. {
  9327. 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")));
  9328. 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"));
  9329. }
  9330. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9331. {
  9332. 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")));
  9333. 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"));
  9334. }
  9335. }
  9336. }
  9337. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9338. {
  9339. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9340. {
  9341. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9342. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9343. }
  9344. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9345. {
  9346. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9347. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9348. }
  9349. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9350. {
  9351. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9352. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9353. }
  9354. }
  9355. }
  9356. }
  9357. }
  9358. }
  9359. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9360. }
  9361. else
  9362. {
  9363. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9364. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9365. }
  9366. json_object_put(data);
  9367. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9368. json_object_put(response);
  9369. }
  9370. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9371. {
  9372. json_object *data;
  9373. data = json_tokener_parse(tempdata);
  9374. if(!is_error(data))
  9375. {
  9376. if(json_object_object_get(data, "txId") != NULL)
  9377. {
  9378. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9379. for(int idx = 0;idx<gunTotalNumber;idx++)
  9380. {
  9381. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9382. {
  9383. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9384. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9385. if(json_object_object_get(data, "description") != NULL)
  9386. {
  9387. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9388. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9389. }
  9390. }
  9391. }
  9392. }
  9393. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9394. }
  9395. else
  9396. {
  9397. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9398. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9399. }
  9400. json_object_put(data);
  9401. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9402. json_object_put(response);
  9403. }
  9404. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9405. {
  9406. json_object *data;
  9407. data = json_tokener_parse(tempdata);
  9408. if(!is_error(data))
  9409. {
  9410. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9411. if(json_object_object_get(data, "Content_Type") != NULL)
  9412. {
  9413. 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))
  9414. {
  9415. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9416. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9417. {
  9418. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9419. }
  9420. }
  9421. else
  9422. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9423. }
  9424. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9425. }
  9426. else
  9427. {
  9428. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9429. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9430. }
  9431. json_object_put(data);
  9432. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9433. json_object_put(response);
  9434. }
  9435. else if(strstr(tempmessageId, "ID_DisplayLcdPage") != NULL)
  9436. {
  9437. json_object *data;
  9438. data = json_tokener_parse(tempdata);
  9439. if(!is_error(data))
  9440. {
  9441. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9442. if(json_object_object_get(data, "ConnectorId") != NULL)
  9443. {
  9444. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9445. }
  9446. if(json_object_object_get(data, "Page_Index") != NULL)
  9447. {
  9448. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9449. }
  9450. if(json_object_object_get(data, "Duration") != NULL)
  9451. {
  9452. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9453. }
  9454. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9455. }
  9456. else
  9457. {
  9458. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9459. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9460. }
  9461. json_object_put(data);
  9462. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9463. json_object_put(response);
  9464. }
  9465. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9466. {
  9467. json_object *data;
  9468. data = json_tokener_parse(tempdata);
  9469. if(!is_error(data))
  9470. {
  9471. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9472. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9473. {
  9474. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9475. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9476. else
  9477. {
  9478. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9479. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9480. }
  9481. }
  9482. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9483. {
  9484. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9485. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9486. else
  9487. {
  9488. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9489. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9490. }
  9491. }
  9492. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9493. {
  9494. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9495. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9496. else
  9497. {
  9498. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9499. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9500. }
  9501. }
  9502. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9503. {
  9504. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9505. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9506. else
  9507. {
  9508. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9509. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9510. }
  9511. }
  9512. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9513. {
  9514. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9515. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9516. else
  9517. {
  9518. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9519. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9520. }
  9521. }
  9522. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9523. {
  9524. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9525. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9526. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9527. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9528. else
  9529. {
  9530. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9531. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9532. }
  9533. }
  9534. if(json_object_object_get(data, "isAuthentication") != NULL)
  9535. {
  9536. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9537. {
  9538. case 0:
  9539. case 1:
  9540. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9541. break;
  9542. default:
  9543. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9544. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9545. break;
  9546. }
  9547. }
  9548. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9549. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9550. }
  9551. else
  9552. {
  9553. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9554. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9555. }
  9556. json_object_put(data);
  9557. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9558. json_object_put(response);
  9559. }
  9560. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  9561. {
  9562. json_object *data;
  9563. data = json_tokener_parse(tempdata);
  9564. if(!is_error(data))
  9565. {
  9566. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9567. {
  9568. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  9569. {
  9570. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9571. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9572. }
  9573. else
  9574. {
  9575. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9576. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  9577. }
  9578. }
  9579. else
  9580. {
  9581. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9582. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9583. }
  9584. }
  9585. else
  9586. {
  9587. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9588. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9589. }
  9590. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9591. json_object_put(response);
  9592. }
  9593. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9594. {
  9595. json_object *data;
  9596. data = json_tokener_parse(tempdata);
  9597. if(!is_error(data))
  9598. {
  9599. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9600. if(json_object_object_get(data, "stationName") != NULL)
  9601. {
  9602. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9603. }
  9604. else
  9605. {
  9606. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9607. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9608. }
  9609. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9610. {
  9611. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  9612. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9613. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  9614. }
  9615. }
  9616. else
  9617. {
  9618. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9619. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9620. }
  9621. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9622. json_object_put(response);
  9623. }
  9624. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9625. {
  9626. json_object *data;
  9627. data = json_tokener_parse(tempdata);
  9628. if(!is_error(data))
  9629. {
  9630. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9631. if(json_object_object_get(data, "weatherId") != NULL)
  9632. {
  9633. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9634. }
  9635. else
  9636. {
  9637. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9638. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9639. }
  9640. if(json_object_object_get(data, "Temperature") != NULL)
  9641. {
  9642. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9643. }
  9644. else
  9645. {
  9646. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9647. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9648. }
  9649. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9650. {
  9651. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  9652. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9653. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  9654. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  9655. );
  9656. }
  9657. }
  9658. else
  9659. {
  9660. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9661. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9662. }
  9663. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9664. json_object_put(response);
  9665. }
  9666. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9667. {
  9668. json_object *data;
  9669. data = json_tokener_parse(tempdata);
  9670. if(!is_error(data))
  9671. {
  9672. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9673. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9674. {
  9675. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9676. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9677. }
  9678. else
  9679. {
  9680. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9681. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9682. }
  9683. }
  9684. else
  9685. {
  9686. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9687. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9688. }
  9689. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9690. json_object_put(response);
  9691. }
  9692. else
  9693. {
  9694. // Can not find valid message id
  9695. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9696. }
  9697. }
  9698. else
  9699. {
  9700. // Payload is null
  9701. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9702. }
  9703. LWS_Send(message);
  9704. return result;
  9705. }
  9706. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9707. {
  9708. mtrace();
  9709. int result = FAIL;
  9710. int connectorIdInt, durationInt;
  9711. char chargingRateUnitStr[4]={0};
  9712. char comfirmstr[20];
  9713. int confirmPeriods = 0;
  9714. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9715. json_object *GetCompositeSchedule;
  9716. GetCompositeSchedule = json_tokener_parse(payload);
  9717. if(!is_error(GetCompositeSchedule))
  9718. {
  9719. // Required data
  9720. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9721. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9722. else
  9723. connectorIdInt = -1;
  9724. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9725. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9726. else
  9727. durationInt = 86400;
  9728. // Optional data
  9729. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9730. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9731. }
  9732. json_object_put(GetCompositeSchedule);
  9733. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9734. if((connectorIdInt == 0) ||
  9735. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9736. {
  9737. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9738. struct StructChargingProfile tmpProfile[1];
  9739. if(strstr(chargingRateUnitStr, "W") != NULL)
  9740. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9741. else
  9742. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9743. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9744. {
  9745. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9746. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9747. }
  9748. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9749. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9750. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9751. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9752. {
  9753. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9754. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9755. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9756. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9757. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9758. {
  9759. confirmPeriods = idx;
  9760. break;
  9761. }
  9762. }
  9763. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9764. {
  9765. confirmPeriods += 1;
  9766. }
  9767. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9768. }
  9769. else
  9770. {
  9771. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9772. }
  9773. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9774. return result;
  9775. }
  9776. int handleGetConfigurationRequest(char *uuid, char *payload)
  9777. {
  9778. mtrace();
  9779. int result = FAIL;
  9780. int MaxKeySupported = 0;
  9781. int n_keys = 0;
  9782. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9783. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9784. json_object *GetConfiguration;
  9785. GetConfiguration = json_tokener_parse(payload);
  9786. if(!is_error(GetConfiguration))
  9787. {
  9788. // Optional data
  9789. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9790. {
  9791. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9792. {
  9793. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9794. n_keys = idx + 1;
  9795. }
  9796. }
  9797. }
  9798. json_object_put(GetConfiguration);
  9799. UnknownKeynum = 0;
  9800. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9801. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9802. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9803. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9804. if(n_keys != 0)
  9805. {
  9806. for(int i=0;i<n_keys;i++)
  9807. {
  9808. getKeyValue(requestKey[i]);
  9809. }
  9810. }
  9811. else
  9812. {
  9813. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9814. getKeyValue("");
  9815. }
  9816. processUnkownKey();
  9817. sendGetConfigurationConfirmation(uuid);
  9818. return result;
  9819. }
  9820. static char fnamePlusPath[100]={0};
  9821. static char fnamePWithNoPath[60]={0};
  9822. void checkUploadLog(void)
  9823. {
  9824. FILE *fp;
  9825. /* Open the command for reading. */
  9826. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9827. if (fp == NULL) {
  9828. DEBUG_WARN("Failed to run command\n" );
  9829. exit(1);
  9830. }
  9831. int ftppathlen = 0;
  9832. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9833. int i = 0;
  9834. /* Read the output a line at a time - output it. */
  9835. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9836. if(i==0)
  9837. {
  9838. ftppathlen = strlen(fnamePlusPath);
  9839. DEBUG_INFO("%s\n", fnamePlusPath);
  9840. fnamePlusPath[ftppathlen]='\0';
  9841. break;
  9842. }
  9843. i= i+1;
  9844. }
  9845. /* close */
  9846. pclose(fp);
  9847. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9848. {
  9849. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9850. {
  9851. fnamePlusPath[k]='\0';
  9852. }
  9853. }
  9854. i=1;
  9855. //char fname[60]={0};
  9856. while(i < ftppathlen)
  9857. {
  9858. int len=ftppathlen-i;
  9859. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9860. {
  9861. DEBUG_INFO("compare '/' all right\n");
  9862. break;
  9863. }
  9864. i=i+1;
  9865. }
  9866. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9867. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9868. fnamePWithNoPath[i+1] = '\0';
  9869. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9870. {
  9871. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9872. {
  9873. fnamePWithNoPath[j]='\0';
  9874. }
  9875. }
  9876. FILE* fp1 = fopen(fnamePlusPath, "r");
  9877. if (fp1)
  9878. {
  9879. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9880. // file exists
  9881. fclose(fp1);
  9882. }
  9883. else
  9884. {
  9885. // file doesn't exist
  9886. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9887. }
  9888. }
  9889. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9890. {
  9891. mtrace();
  9892. int result = FAIL;
  9893. time_t CurrentTime;
  9894. struct tm *tm;
  9895. pthread_t th_Status;
  9896. CurrentTime = time(NULL);
  9897. tm = localtime(&CurrentTime);
  9898. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  9899. 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);
  9900. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9901. if(!interLock.isGetDiagnosticGoing)
  9902. {
  9903. interLock.isGetDiagnosticGoing = 1;
  9904. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9905. sleep(1);
  9906. }
  9907. else
  9908. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9909. return result;
  9910. }
  9911. void* GetDiagnosticsProcess(void* data)
  9912. {
  9913. pthread_detach(pthread_self());
  9914. mtrace();
  9915. int retriesInt=0, retryIntervalInt=0;
  9916. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9917. 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};
  9918. int port=0;
  9919. int isSuccess = FALSE;
  9920. char cmdBuf[2048];
  9921. struct tm *tmNow;
  9922. time_t CurrentTime;
  9923. struct tm tmStart;
  9924. struct tm tmStop;
  9925. CurrentTime = time(NULL);
  9926. tmNow=localtime(&CurrentTime);
  9927. uint16_t targetYear, targetMonth;
  9928. json_object *GetDiagnostics;
  9929. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9930. GetDiagnostics = json_tokener_parse(data);
  9931. if(!is_error(GetDiagnostics))
  9932. {
  9933. // Required data
  9934. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9935. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9936. // Optional data
  9937. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9938. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9939. else
  9940. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9941. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9942. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9943. else
  9944. retryIntervalInt = 30;
  9945. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9946. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9947. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9948. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9949. }
  9950. json_object_put(GetDiagnostics);
  9951. // Pack log to compress file
  9952. 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) &&
  9953. (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))
  9954. {
  9955. // Pack system log
  9956. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9957. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9958. targetYear = tmStart.tm_year;
  9959. targetMonth = tmStart.tm_mon;
  9960. do
  9961. {
  9962. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9963. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9964. if(targetMonth+1>=13)
  9965. {
  9966. targetYear += 1;
  9967. targetMonth = 1;
  9968. }
  9969. else
  9970. {
  9971. targetMonth += 1;
  9972. }
  9973. }while((targetYear < (tmNow->tm_year+1900)) ||
  9974. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9975. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9976. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9977. system(cmdBuf);
  9978. // Pack charging & event log
  9979. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9980. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9981. targetYear = tmStart.tm_year;
  9982. targetMonth = tmStart.tm_mon;
  9983. do
  9984. {
  9985. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9986. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9987. if(targetMonth+1>=13)
  9988. {
  9989. targetYear += 1;
  9990. targetMonth = 1;
  9991. }
  9992. else
  9993. {
  9994. targetMonth += 1;
  9995. }
  9996. }while((targetYear < (tmNow->tm_year+1900)) ||
  9997. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9998. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9999. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10000. system(cmdBuf);
  10001. // Combine log file
  10002. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10003. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10004. }
  10005. else
  10006. {
  10007. system("exec /root/logPackTools 'log' 6");
  10008. }
  10009. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10010. system(cmdBuf);
  10011. checkUploadLog();
  10012. //****************location*******************/
  10013. if(strcmp(locationstr,"")==0)
  10014. {
  10015. DEBUG_INFO("location is <Empty>!\n");
  10016. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10017. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10018. goto end;
  10019. }
  10020. memset(protocol, 0, ARRAY_SIZE(protocol));
  10021. memset(user, 0, ARRAY_SIZE(user) );
  10022. memset(password, 0, ARRAY_SIZE(password));
  10023. memset(host, 0, ARRAY_SIZE(host));
  10024. memset(path, 0, ARRAY_SIZE(path));
  10025. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10026. memset(host1, 0, ARRAY_SIZE(host1));
  10027. memset(path1, 0, ARRAY_SIZE(path1));
  10028. /*location: ftp://user:password@host:port/path*/
  10029. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10030. if((access(fnamePlusPath,F_OK))!=-1)
  10031. {
  10032. DEBUG_INFO("fnamePlusPath exist.\n");
  10033. }
  10034. else
  10035. {
  10036. DEBUG_INFO("fnamePlusPath not exist!\n");
  10037. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10038. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10039. goto end;
  10040. }
  10041. if(strchr(locationstr,'@')==NULL)
  10042. {
  10043. sscanf(locationstr,
  10044. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10045. protocol, host, &port, path);
  10046. strcpy(user,"anonymous");
  10047. strcpy(password,"");
  10048. }
  10049. else
  10050. {
  10051. //DEBUG_INFO("pch=%s\n", pch);
  10052. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10053. protocol, user, password, host, &port, path);
  10054. }
  10055. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10056. {
  10057. DEBUG_INFO("protocol is not ftp/http ! \n");
  10058. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10059. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10060. goto end;
  10061. }
  10062. if(strncmp(locationstr,"http", 4) == 0)
  10063. {
  10064. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10065. sprintf(ftppath,"/%s", path);
  10066. do
  10067. {
  10068. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10069. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10070. sleep(3);
  10071. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10072. if(!isSuccess)
  10073. {
  10074. DEBUG_INFO("Diagnostics fail.\n");
  10075. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10076. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10077. sleep(retryIntervalInt);
  10078. }
  10079. else
  10080. {
  10081. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10082. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10083. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10084. }
  10085. retriesInt--;
  10086. }while((isSuccess == 0)&&(retriesInt >= 0));
  10087. }
  10088. else
  10089. {
  10090. sscanf(host,"%[^/]%s",host1, path1);
  10091. if(strlen(path) > 0)
  10092. sprintf(ftppath,"/%s", path);
  10093. else
  10094. sprintf(ftppath,"/%s", path1);
  10095. int ftppathlen=strlen(ftppath);
  10096. int i=1;
  10097. char filenametemp[50];
  10098. while(i < ftppathlen)
  10099. {
  10100. int len=ftppathlen-i;
  10101. if(ftppath[len]== 47) // '/' ascll code: 47
  10102. {
  10103. DEBUG_INFO("find '/' all right\n");
  10104. break;
  10105. }
  10106. i=i+1;
  10107. }
  10108. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10109. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10110. filenametemp[i+1] = 0;
  10111. if(port == 0)
  10112. port = 21;
  10113. do
  10114. {
  10115. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10116. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10117. sleep(3);
  10118. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10119. if(!isSuccess)
  10120. {
  10121. DEBUG_INFO("Diagnostics fail.\n");
  10122. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10123. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10124. sleep(retryIntervalInt);
  10125. }
  10126. else
  10127. {
  10128. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10129. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10130. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10131. }
  10132. retriesInt--;
  10133. }while((!isSuccess)&&(retriesInt >= 0));
  10134. }
  10135. end:
  10136. system("rm -f /mnt/*");
  10137. sleep(5);
  10138. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10139. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10140. interLock.isGetDiagnosticGoing = 0;
  10141. pthread_exit(NULL);
  10142. }
  10143. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10144. {
  10145. mtrace();
  10146. int result = FAIL;
  10147. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10148. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10149. {
  10150. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10151. locallistVersion = -1;
  10152. }
  10153. else
  10154. {
  10155. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10156. OCPP_getListVerion();
  10157. }
  10158. //from db.OCPP_getListVerion
  10159. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10160. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  10161. sendGetLocalListVersionConfirmation(uuid,"");
  10162. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  10163. return result;
  10164. }
  10165. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10166. {
  10167. mtrace();
  10168. int result = FAIL;
  10169. int connectorIdInt=-1;
  10170. int tempIndex = 0;
  10171. int connectorIdIsNULL, chargingProfileIsNULL;
  10172. char comfirmstr[20]={0};
  10173. char cmdBuf[512];
  10174. json_object *RemoteStartTransaction;
  10175. FILE *fp;
  10176. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10177. if(server_pending == TRUE)
  10178. {
  10179. return 0;
  10180. }
  10181. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10182. RemoteStartTransaction = json_tokener_parse(payload);
  10183. if(!is_error(RemoteStartTransaction))
  10184. {
  10185. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10186. {
  10187. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10188. }
  10189. else
  10190. {
  10191. connectorIdIsNULL = TRUE;
  10192. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10193. {
  10194. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10195. {
  10196. connectorIdIsNULL = FALSE;
  10197. connectorIdInt = (gun_index+1);
  10198. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10199. break;
  10200. }
  10201. }
  10202. }
  10203. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10204. {
  10205. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10206. // Required data
  10207. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10208. // Optional data
  10209. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10210. {
  10211. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10212. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10213. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10214. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10215. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10216. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10217. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10218. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10219. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10220. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10221. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10222. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10223. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10224. {
  10225. 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")));
  10226. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10227. 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"));
  10228. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10229. 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"));
  10230. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10231. 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")));
  10232. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10233. {
  10234. 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++)
  10235. {
  10236. 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"));
  10237. 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"));
  10238. 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)
  10239. 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"));
  10240. }
  10241. }
  10242. }
  10243. }
  10244. else
  10245. {
  10246. chargingProfileIsNULL = TRUE;
  10247. }
  10248. }
  10249. }
  10250. else
  10251. {
  10252. connectorIdIsNULL = TRUE;
  10253. }
  10254. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10255. {
  10256. DEBUG_WARN("Connector id is NULL\n.");
  10257. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10258. goto end;
  10259. }
  10260. /*
  10261. enum _SYSTEM_STATUS
  10262. {
  10263. S_BOOTING = 0,
  10264. S_IDLE, = 1
  10265. S_AUTHORIZING, = 2
  10266. S_REASSIGN_CHECK, = 3
  10267. S_REASSIGN, = 4
  10268. S_PRECHARGE, = 5
  10269. S_PREPARING_FOR_EV, = 6
  10270. S_PREPARING_FOR_EVSE, = 7
  10271. S_CHARGING, = 8
  10272. S_TERMINATING, = 9
  10273. S_COMPLETE, = 10
  10274. S_ALARM, = 11
  10275. S_FAULT = 12
  10276. }
  10277. */
  10278. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10279. {
  10280. //check Transaction active
  10281. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10282. {
  10283. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10284. {
  10285. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10286. }
  10287. else
  10288. {
  10289. tempIndex = connectorIdInt -1;
  10290. }
  10291. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10292. {
  10293. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10294. {
  10295. 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))
  10296. {
  10297. //Reserved
  10298. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10299. }
  10300. 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))
  10301. {
  10302. //Reserved
  10303. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10304. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10305. goto end;
  10306. }
  10307. else
  10308. {
  10309. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10310. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10311. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10312. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10313. {
  10314. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10315. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10316. goto end;
  10317. }
  10318. }//END FOR ELSE
  10319. }
  10320. }// END FOR CHAdeMO_QUANTITY
  10321. }
  10322. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10323. {
  10324. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10325. {
  10326. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10327. }
  10328. else
  10329. {
  10330. tempIndex = connectorIdInt -1;
  10331. }
  10332. for (int index = 0; index < CCS_QUANTITY; index++)
  10333. {
  10334. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10335. {
  10336. 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))
  10337. {
  10338. //Reserved
  10339. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10340. }
  10341. 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))
  10342. {
  10343. //Reserved
  10344. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10345. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10346. goto end;
  10347. }
  10348. else
  10349. {
  10350. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10351. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10352. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10353. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10354. {
  10355. DEBUG_WARN("CCS connector not allow start\n.");
  10356. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10357. goto end;
  10358. }
  10359. }// END FOR ELSE
  10360. }
  10361. }// END FOR CCS_QUANTITY
  10362. }
  10363. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10364. {
  10365. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10366. {
  10367. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10368. }
  10369. else
  10370. {
  10371. tempIndex = connectorIdInt -1;
  10372. }
  10373. for (int index = 0; index < GB_QUANTITY; index++)
  10374. {
  10375. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10376. {
  10377. 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))
  10378. {
  10379. //Reserved
  10380. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10381. }
  10382. 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))
  10383. {
  10384. //Reserved
  10385. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10386. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10387. goto end;
  10388. }
  10389. else
  10390. {
  10391. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10392. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10393. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10394. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10395. {
  10396. DEBUG_WARN("GB connector not allow start\n.");
  10397. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10398. goto end;
  10399. }
  10400. }// END FOR ELSE
  10401. }
  10402. } // END FOR GB_QUANTITY
  10403. }
  10404. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10405. {
  10406. tempIndex = connectorIdInt -1;
  10407. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10408. {
  10409. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10410. {
  10411. 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))
  10412. {
  10413. //Reserved
  10414. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10415. }
  10416. 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))
  10417. {
  10418. //Reserved
  10419. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10420. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10421. goto end;
  10422. }
  10423. else
  10424. {
  10425. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10426. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10427. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10428. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10429. {
  10430. DEBUG_WARN("GB connector not allow start\n.");
  10431. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10432. goto end;
  10433. }
  10434. }// END FOR ELSE
  10435. }
  10436. } // END FOR GB_QUANTITY
  10437. }
  10438. else
  10439. {
  10440. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10441. {
  10442. tempIndex = 2;
  10443. }
  10444. else
  10445. {
  10446. tempIndex = connectorIdInt -1;
  10447. }
  10448. for (int index = 0; index < AC_QUANTITY; index++)
  10449. {
  10450. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10451. {
  10452. 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))
  10453. {
  10454. //Reserved
  10455. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10456. }
  10457. 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))
  10458. {
  10459. //Reserved
  10460. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10461. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10462. goto end;
  10463. }
  10464. else
  10465. {
  10466. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10467. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10468. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10469. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10470. {
  10471. DEBUG_WARN("AC connector not allow start\n.");
  10472. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10473. goto end;
  10474. }
  10475. }//END FOR ELSE
  10476. }
  10477. }// END FOR AC_QUANTITY
  10478. }
  10479. if(chargingProfileIsNULL == FALSE)
  10480. {
  10481. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10482. {
  10483. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10484. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10485. //memset idTag
  10486. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10487. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10488. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10489. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10490. // Save profile to file
  10491. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10492. system(cmdBuf);
  10493. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10494. fp = fopen(cmdBuf, "w");
  10495. 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));
  10496. fclose(fp);
  10497. }
  10498. else
  10499. {
  10500. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10501. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10502. }
  10503. }
  10504. else
  10505. {
  10506. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10507. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10508. //memset idTag
  10509. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10510. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10511. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10512. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10513. }
  10514. }
  10515. else
  10516. {
  10517. DEBUG_WARN("Connector id over\n.");
  10518. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10519. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10520. }
  10521. end:
  10522. json_object_put(RemoteStartTransaction);
  10523. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10524. {
  10525. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10526. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10527. }
  10528. //OCPP send RemoteStartConfirmation by first.
  10529. sendRemoteStartConfirmation(uuid, comfirmstr);
  10530. return result;
  10531. }
  10532. int handleRemoteStartRequest(char *uuid, char *payload)
  10533. {
  10534. mtrace();
  10535. int result = PASS;
  10536. int connectorIdInt=-1;
  10537. int tempIndex = 0;
  10538. char comfirmstr[20]={0};
  10539. char cmdBuf[512];
  10540. json_object *RemoteStartTransaction;
  10541. FILE *fp;
  10542. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10543. if(server_pending == TRUE)
  10544. {
  10545. result = FAIL;
  10546. }
  10547. RemoteStartTransaction = json_tokener_parse(payload);
  10548. if(!is_error(RemoteStartTransaction))
  10549. {
  10550. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10551. {
  10552. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10553. }
  10554. else
  10555. {
  10556. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10557. {
  10558. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10559. {
  10560. connectorIdInt = (gun_index+1);
  10561. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10562. break;
  10563. }
  10564. }
  10565. }
  10566. if(connectorIdInt == 0)
  10567. {
  10568. DEBUG_WARN("Connector id shall not equal 0.\n");
  10569. result = FAIL;
  10570. }
  10571. else if(connectorIdInt == -1)
  10572. {
  10573. DEBUG_INFO("Connector id does not specific.\n");
  10574. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10575. {
  10576. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10577. // Required data
  10578. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10579. // Optional data
  10580. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10581. {
  10582. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10583. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10584. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10585. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10586. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10587. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10588. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10589. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10590. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10591. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10592. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10593. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10594. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10595. {
  10596. 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")));
  10597. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10598. 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"));
  10599. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10600. 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"));
  10601. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10602. 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")));
  10603. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10604. {
  10605. 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++)
  10606. {
  10607. 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"));
  10608. 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"));
  10609. 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)
  10610. 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"));
  10611. }
  10612. }
  10613. }
  10614. }
  10615. else
  10616. {
  10617. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10618. }
  10619. }
  10620. }
  10621. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10622. {
  10623. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10624. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10625. // Required data
  10626. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10627. // Optional data
  10628. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10629. {
  10630. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10631. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10632. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10633. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10634. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10635. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10636. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10637. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10638. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10639. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10640. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10641. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10642. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10643. {
  10644. 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")));
  10645. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10646. 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"));
  10647. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10648. 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"));
  10649. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10650. 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")));
  10651. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10652. {
  10653. 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++)
  10654. {
  10655. 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"));
  10656. 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"));
  10657. 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)
  10658. 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"));
  10659. }
  10660. }
  10661. }
  10662. }
  10663. else
  10664. {
  10665. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10666. }
  10667. }
  10668. else
  10669. {
  10670. DEBUG_WARN("Connector id is over maximun value.\n");
  10671. result = FAIL;
  10672. }
  10673. }
  10674. if(result == PASS)
  10675. {
  10676. if(connectorIdInt > 0)
  10677. {
  10678. //check Transaction active
  10679. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10680. {
  10681. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10682. {
  10683. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10684. }
  10685. else
  10686. {
  10687. tempIndex = connectorIdInt -1;
  10688. }
  10689. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10690. {
  10691. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10692. {
  10693. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10694. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10695. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10696. {
  10697. //Reserved
  10698. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10699. }
  10700. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10701. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10702. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10703. {
  10704. //Reserved
  10705. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10706. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10707. goto end;
  10708. }
  10709. else
  10710. {
  10711. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10712. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10713. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10714. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10715. {
  10716. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10717. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10718. goto end;
  10719. }
  10720. }//END FOR ELSE
  10721. }
  10722. }// END FOR CHAdeMO_QUANTITY
  10723. }
  10724. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10725. {
  10726. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10727. {
  10728. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10729. }
  10730. else
  10731. {
  10732. tempIndex = connectorIdInt -1;
  10733. }
  10734. for (int index = 0; index < CCS_QUANTITY; index++)
  10735. {
  10736. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10737. {
  10738. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10739. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10740. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10741. {
  10742. //Reserved
  10743. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10744. }
  10745. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10746. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10747. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10748. {
  10749. //Reserved
  10750. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10751. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10752. goto end;
  10753. }
  10754. else
  10755. {
  10756. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10757. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10758. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10759. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10760. {
  10761. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10762. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10763. goto end;
  10764. }
  10765. }// END FOR ELSE
  10766. }
  10767. }// END FOR CCS_QUANTITY
  10768. }
  10769. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10770. {
  10771. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10772. {
  10773. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10774. }
  10775. else
  10776. {
  10777. tempIndex = connectorIdInt -1;
  10778. }
  10779. for (int index = 0; index < GB_QUANTITY; index++)
  10780. {
  10781. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10782. {
  10783. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10784. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10785. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10786. {
  10787. //Reserved
  10788. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10789. }
  10790. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10791. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10792. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10793. {
  10794. //Reserved
  10795. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10796. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10797. goto end;
  10798. }
  10799. else
  10800. {
  10801. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10802. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10803. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10804. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10805. {
  10806. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10807. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10808. goto end;
  10809. }
  10810. }// END FOR ELSE
  10811. }
  10812. } // END FOR GB_QUANTITY
  10813. }
  10814. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10815. {
  10816. tempIndex = connectorIdInt -1;
  10817. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10818. {
  10819. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10820. {
  10821. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10822. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10823. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10824. {
  10825. //Reserved
  10826. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10827. }
  10828. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10829. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10830. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10831. {
  10832. //Reserved
  10833. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10834. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10835. goto end;
  10836. }
  10837. else
  10838. {
  10839. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10840. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10841. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10842. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10843. {
  10844. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10845. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10846. goto end;
  10847. }
  10848. }// END FOR ELSE
  10849. }
  10850. } // END FOR GB_QUANTITY
  10851. }
  10852. else
  10853. {
  10854. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10855. {
  10856. tempIndex = 2;
  10857. }
  10858. else
  10859. {
  10860. tempIndex = connectorIdInt -1;
  10861. }
  10862. for (int index = 0; index < AC_QUANTITY; index++)
  10863. {
  10864. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10865. {
  10866. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10867. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10868. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10869. {
  10870. //Reserved
  10871. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10872. }
  10873. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10874. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10875. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10876. {
  10877. //Reserved
  10878. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10879. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10880. goto end;
  10881. }
  10882. else
  10883. {
  10884. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10885. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10886. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10887. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10888. {
  10889. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10890. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10891. goto end;
  10892. }
  10893. }//END FOR ELSE
  10894. }
  10895. }// END FOR AC_QUANTITY
  10896. }
  10897. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10898. {
  10899. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10900. {
  10901. // Save profile to file
  10902. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10903. system(cmdBuf);
  10904. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10905. fp = fopen(cmdBuf, "w");
  10906. 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));
  10907. fclose(fp);
  10908. }
  10909. else
  10910. {
  10911. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10912. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10913. goto end;
  10914. }
  10915. }
  10916. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10917. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10918. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10919. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10920. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10921. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10922. }
  10923. else
  10924. {
  10925. uint8_t isHasIdleConnector = FALSE;
  10926. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10927. {
  10928. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10929. {
  10930. isHasIdleConnector = TRUE;
  10931. break;
  10932. }
  10933. }
  10934. if(isHasIdleConnector == TRUE)
  10935. {
  10936. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10937. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10938. {
  10939. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10940. {
  10941. // Save profile to file
  10942. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  10943. system(cmdBuf);
  10944. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  10945. fp = fopen(cmdBuf, "w");
  10946. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10947. fclose(fp);
  10948. refreshStartTimer(&clientTime.RemoteStartWait);
  10949. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  10950. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10951. }
  10952. else
  10953. {
  10954. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10955. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10956. }
  10957. }
  10958. else
  10959. {
  10960. refreshStartTimer(&clientTime.RemoteStartWait);
  10961. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  10962. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10963. }
  10964. }
  10965. else
  10966. {
  10967. DEBUG_INFO("There is not any connector is idle.\n");
  10968. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10969. }
  10970. }
  10971. }
  10972. else
  10973. {
  10974. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10975. }
  10976. end:
  10977. json_object_put(RemoteStartTransaction);
  10978. sendRemoteStartConfirmation(uuid, comfirmstr);
  10979. return result;
  10980. }
  10981. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10982. {
  10983. mtrace();
  10984. int result = FAIL;
  10985. int match = FALSE;
  10986. int GunNO = 0;
  10987. int tempIndex = 0;
  10988. int transactionIdInt=0;
  10989. int transactionIdIsNULL= TRUE;
  10990. char comfirmstr[20];
  10991. json_object *RemoteStopTransaction;
  10992. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10993. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10994. if(server_pending == TRUE)
  10995. {
  10996. return 0;
  10997. }
  10998. RemoteStopTransaction = json_tokener_parse(payload);
  10999. if(!is_error(RemoteStopTransaction))
  11000. {
  11001. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11002. {
  11003. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11004. transactionIdIsNULL = FALSE;
  11005. }
  11006. }
  11007. json_object_put(RemoteStopTransaction);
  11008. if(transactionIdIsNULL == FALSE)
  11009. {
  11010. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11011. {
  11012. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11013. {
  11014. //check Transaction active
  11015. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11016. {
  11017. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11018. {
  11019. tempIndex = ((gun_index==2) ? 1: 0);
  11020. }
  11021. else
  11022. {
  11023. tempIndex = gun_index;
  11024. }
  11025. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11026. {
  11027. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11028. {
  11029. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11030. {
  11031. match = TRUE;
  11032. GunNO = gun_index;
  11033. }
  11034. }
  11035. }// END FOR CHAdeMO_QUANTITY
  11036. }
  11037. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11038. {
  11039. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11040. {
  11041. tempIndex = ((gun_index==2) ? 1: 0);
  11042. }
  11043. else
  11044. {
  11045. tempIndex = gun_index;
  11046. }
  11047. for (int index = 0; index < CCS_QUANTITY; index++)
  11048. {
  11049. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11050. {
  11051. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11052. {
  11053. match = TRUE;
  11054. GunNO = gun_index;
  11055. }
  11056. }
  11057. }// END FOR CCS_QUANTITY
  11058. }
  11059. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11060. {
  11061. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11062. {
  11063. tempIndex = ((gun_index==2) ? 1: 0);
  11064. }
  11065. else
  11066. {
  11067. tempIndex = gun_index;
  11068. }
  11069. for (int index = 0; index < GB_QUANTITY; index++)
  11070. {
  11071. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11072. {
  11073. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11074. {
  11075. match = TRUE;
  11076. GunNO = gun_index;
  11077. }
  11078. }
  11079. }// END FOR GB_QUANTITY
  11080. }
  11081. else if(gunType[gun_index] == GUN_TYPE_DO)
  11082. {
  11083. tempIndex = gun_index;
  11084. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11085. {
  11086. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11087. {
  11088. 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
  11089. {
  11090. match = TRUE;
  11091. GunNO = gun_index;
  11092. }
  11093. }
  11094. }// END FOR GB_QUANTITY
  11095. }
  11096. else
  11097. {
  11098. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11099. {
  11100. tempIndex = 2;
  11101. }
  11102. else
  11103. {
  11104. tempIndex = gun_index;
  11105. }
  11106. for (int index = 0; index < AC_QUANTITY; index++)
  11107. {
  11108. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11109. {
  11110. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11111. {
  11112. match = TRUE;
  11113. GunNO = gun_index;
  11114. }
  11115. }
  11116. }// END FOR CHAdeMO_QUANTITY
  11117. } // END FOR AC ELSE
  11118. }// CHECK IF ResponseTransactionId == transactionIdInt
  11119. }//END FOR
  11120. if( match == TRUE)
  11121. {
  11122. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11123. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11124. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11125. }
  11126. else
  11127. {
  11128. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11129. }
  11130. }
  11131. else
  11132. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11133. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11134. return result;
  11135. }
  11136. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11137. {
  11138. mtrace();
  11139. int result = FAIL;
  11140. int connectorIdInt=0, reservationIdInt=0;
  11141. int tempIndex = 0;
  11142. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  11143. char comfirmstr[20]={0};
  11144. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11145. int c = 0;
  11146. char *loc;
  11147. //char *ptr;
  11148. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11149. strcpy(sstrtemp, stringtrimspace(payload));
  11150. //***(1)connectorId ****/
  11151. c=0;
  11152. loc = strstr(sstrtemp, "connectorId");
  11153. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11154. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11155. {
  11156. sstr[c] = loc[strlen("connectorId")+2+c];
  11157. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11158. c++;
  11159. }
  11160. sstr[c] = '\0';
  11161. connectorIdInt = atoi(sstr);
  11162. //***(2)expiryDate ****/
  11163. loc = strstr(sstrtemp, "expiryDate");
  11164. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11165. c = 0;
  11166. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11167. {
  11168. sstr[c] = loc[3+strlen("expiryDate")+c];
  11169. c++;
  11170. }
  11171. sstr[c] = '\0';
  11172. strcpy(expiryDatestr, sstr);
  11173. //***(3)idTag ****/
  11174. loc = strstr(sstrtemp, "idTag");
  11175. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11176. c = 0;
  11177. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11178. {
  11179. sstr[c] = loc[3+strlen("idTag")+c];
  11180. c++;
  11181. }
  11182. sstr[c] = '\0';
  11183. strcpy(idTagstr, sstr);
  11184. //***(4)parentIdTag ****/
  11185. loc = strstr(sstrtemp, "parentIdTag");
  11186. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11187. c = 0;
  11188. if(loc == NULL)
  11189. {
  11190. strcpy(parentIdTagstr, "");
  11191. }
  11192. else
  11193. {
  11194. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11195. {
  11196. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11197. c++;
  11198. }
  11199. sstr[c] = '\0';
  11200. strcpy(parentIdTagstr, sstr);
  11201. }
  11202. //***(5)reservationId ****/
  11203. c=0;
  11204. loc = strstr(sstrtemp, "reservationId");
  11205. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11206. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11207. {
  11208. sstr[c] = loc[strlen("reservationId")+2+c];
  11209. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11210. c++;
  11211. }
  11212. sstr[c] = '\0';
  11213. reservationIdInt = atoi(sstr);
  11214. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11215. /*
  11216. enum SYSTEM_STATUS
  11217. {
  11218. SYS_MODE_BOOTING = 0,
  11219. SYS_MODE_IDLE = 1,
  11220. SYS_MODE_AUTHORIZING = 2,
  11221. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11222. SYS_MODE_REASSIGN = 4,
  11223. SYS_MODE_PREPARING = 5,
  11224. SYS_MODE_PREPARE_FOR_EV = 6,
  11225. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11226. SYS_MODE_CHARGING = 8,
  11227. SYS_MODE_TERMINATING = 9,
  11228. SYS_MODE_COMPLETE = 10,
  11229. SYS_MODE_ALARM = 11,
  11230. SYS_MODE_FAULT = 12,
  11231. SYS_MODE_RESERVATION = 13,
  11232. SYS_MODE_BOOKING = 14,
  11233. SYS_MODE_MAINTAIN = 15,
  11234. SYS_MODE_DEBUG = 16,
  11235. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11236. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11237. SYS_MODE_UPDATE = 19
  11238. };
  11239. */
  11240. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11241. {
  11242. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11243. goto end;
  11244. }
  11245. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11246. {
  11247. //check Transaction active
  11248. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11249. {
  11250. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11251. {
  11252. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11253. }
  11254. else
  11255. {
  11256. tempIndex = connectorIdInt -1;
  11257. }
  11258. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11259. {
  11260. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11261. {
  11262. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11263. {
  11264. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11265. {
  11266. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11267. {
  11268. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11269. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11270. }
  11271. 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'))
  11272. {
  11273. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11274. }
  11275. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11276. {
  11277. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11278. }
  11279. else
  11280. {
  11281. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11282. }
  11283. }
  11284. 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
  11285. {
  11286. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11287. }
  11288. }
  11289. else
  11290. {
  11291. //replace reservation
  11292. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11293. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11294. }
  11295. }
  11296. } // END FOR CHAdeMO_QUANTITY
  11297. }
  11298. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11299. {
  11300. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11301. {
  11302. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11303. }
  11304. else
  11305. {
  11306. tempIndex = connectorIdInt -1;
  11307. }
  11308. for (int index = 0; index < CCS_QUANTITY; index++)
  11309. {
  11310. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11311. {
  11312. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11313. {
  11314. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11315. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11316. {
  11317. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11318. {
  11319. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11320. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11321. }
  11322. 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'))
  11323. {
  11324. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11325. }
  11326. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11327. {
  11328. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11329. }
  11330. else
  11331. {
  11332. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11333. }
  11334. }
  11335. 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
  11336. {
  11337. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11338. }
  11339. }
  11340. else
  11341. {
  11342. //replace reservation
  11343. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11344. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11345. }
  11346. }
  11347. } // END FOR CCS_QUANTITY
  11348. }
  11349. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11350. {
  11351. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11352. {
  11353. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11354. }
  11355. else
  11356. {
  11357. tempIndex = connectorIdInt -1;
  11358. }
  11359. for (int index = 0; index < GB_QUANTITY; index++)
  11360. {
  11361. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11362. {
  11363. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11364. {
  11365. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11366. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11367. {
  11368. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11369. {
  11370. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11371. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11372. }
  11373. 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'))
  11374. {
  11375. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11376. }
  11377. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11378. {
  11379. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11380. }
  11381. else
  11382. {
  11383. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11384. }
  11385. }
  11386. 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
  11387. {
  11388. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11389. }
  11390. }
  11391. else
  11392. {
  11393. //replace reservation
  11394. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11395. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11396. }
  11397. }
  11398. }// END FOR GB_QUANTITY
  11399. }
  11400. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11401. {
  11402. tempIndex = connectorIdInt -1;
  11403. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11404. {
  11405. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11406. {
  11407. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11408. {
  11409. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11410. 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
  11411. {
  11412. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11413. {
  11414. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11415. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11416. }
  11417. 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'))
  11418. {
  11419. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11420. }
  11421. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11422. {
  11423. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11424. }
  11425. else
  11426. {
  11427. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11428. }
  11429. }
  11430. 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
  11431. {
  11432. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11433. }
  11434. }
  11435. else
  11436. {
  11437. //replace reservation
  11438. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11439. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11440. }
  11441. }
  11442. }// END FOR GB_QUANTITY
  11443. }
  11444. else
  11445. {
  11446. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11447. {
  11448. tempIndex = 2;
  11449. }
  11450. else
  11451. {
  11452. tempIndex = (connectorIdInt -1);
  11453. }
  11454. for (int index = 0; index < AC_QUANTITY; index++)
  11455. {
  11456. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11457. {
  11458. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11459. {
  11460. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11461. {
  11462. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11463. {
  11464. 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))
  11465. {
  11466. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11467. }
  11468. else
  11469. {
  11470. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11471. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11472. }
  11473. }
  11474. 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'))
  11475. {
  11476. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11477. }
  11478. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11479. {
  11480. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11481. }
  11482. else
  11483. {
  11484. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11485. }
  11486. }
  11487. 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
  11488. {
  11489. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11490. }
  11491. }
  11492. else
  11493. {
  11494. //replace reservation
  11495. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11496. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11497. }
  11498. }
  11499. } // END FOR AC_QUANTITY
  11500. }
  11501. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11502. }
  11503. else if(connectorIdInt == 0)
  11504. {
  11505. //check Transaction active
  11506. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11507. {
  11508. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11509. {
  11510. 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'))
  11511. {
  11512. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11513. goto end;
  11514. }
  11515. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11516. {
  11517. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11518. goto end;
  11519. }
  11520. 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
  11521. {
  11522. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11523. goto end;
  11524. }
  11525. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11526. {
  11527. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11528. goto end;
  11529. }
  11530. }
  11531. }// END FOR CHAdeMO_QUANTITY
  11532. for (int index = 0; index < CCS_QUANTITY; index++)
  11533. {
  11534. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11535. {
  11536. 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'))
  11537. {
  11538. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11539. goto end;
  11540. }
  11541. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11542. {
  11543. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11544. goto end;
  11545. }
  11546. 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
  11547. {
  11548. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11549. goto end;
  11550. }
  11551. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11552. {
  11553. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11554. goto end;
  11555. }
  11556. }
  11557. } // END FOR CCS_QUANTITY
  11558. for (int index = 0; index < GB_QUANTITY; index++)
  11559. {
  11560. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11561. {
  11562. 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'))
  11563. {
  11564. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11565. goto end;
  11566. }
  11567. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11568. {
  11569. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11570. goto end;
  11571. }
  11572. 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
  11573. {
  11574. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11575. goto end;
  11576. }
  11577. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11578. {
  11579. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11580. goto end;
  11581. }
  11582. }
  11583. } // END FOR GB_QUANTITY
  11584. for (int index = 0; index < AC_QUANTITY; index++)
  11585. {
  11586. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11587. {
  11588. 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'))
  11589. {
  11590. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11591. goto end;
  11592. }
  11593. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11594. {
  11595. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11596. goto end;
  11597. }
  11598. 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
  11599. {
  11600. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11601. goto end;
  11602. }
  11603. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11604. {
  11605. 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))
  11606. {
  11607. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11608. goto end;
  11609. }
  11610. }
  11611. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11612. {
  11613. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11614. goto end;
  11615. }
  11616. }
  11617. }// END FOR AC_QUANTITY
  11618. //The connectorId is 0
  11619. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  11620. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11621. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11622. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  11623. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11624. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  11625. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11626. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  11627. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  11628. result = TRUE;
  11629. return result;
  11630. }
  11631. else
  11632. {
  11633. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11634. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11635. }
  11636. if(strcmp(comfirmstr,"Accepted") == 0)
  11637. {
  11638. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11639. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11640. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11641. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11642. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11643. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  11644. result = TRUE;
  11645. return result;
  11646. }
  11647. end:
  11648. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11649. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11650. return result;
  11651. }
  11652. int handleResetRequest(char *uuid, char *payload)
  11653. {
  11654. mtrace();
  11655. int result = FAIL;
  11656. char sstr[10]={0},sstrtemp[30]={ 0 };
  11657. char typestr[10]={0};
  11658. char comfirmstr[20]={0};
  11659. int c = 0;
  11660. char *loc;
  11661. DEBUG_INFO("handleResetRequest...\n");
  11662. strcpy(sstrtemp, stringtrimspace(payload));
  11663. loc = strstr(sstrtemp, "type");
  11664. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11665. c = 0;
  11666. while (loc[3+strlen("type")+c] != '\"')
  11667. {
  11668. sstr[c] = loc[3+strlen("type")+c];
  11669. c++;
  11670. }
  11671. sstr[c] = '\0';
  11672. strcpy(typestr,sstr);
  11673. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11674. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11675. {
  11676. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11677. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  11678. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11679. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11680. }
  11681. else
  11682. {
  11683. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11684. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11685. result = PASS;
  11686. }
  11687. sendResetConfirmation(uuid, comfirmstr);
  11688. return result;
  11689. }
  11690. int handleSendLocalListRequest(char *uuid, char *payload)
  11691. {
  11692. mtrace();
  11693. int result = FAIL;
  11694. char comfirmstr[20];
  11695. int checkState_Faulted = FALSE;
  11696. json_object *SendLocalList;
  11697. DEBUG_INFO("handleSendLocalListRequest...\n");
  11698. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11699. {
  11700. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11701. goto end;
  11702. }
  11703. //check Charge Point state
  11704. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11705. {
  11706. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11707. {
  11708. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11709. }
  11710. }
  11711. for (int index = 0; index < CCS_QUANTITY; index++)
  11712. {
  11713. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11714. {
  11715. checkState_Faulted = TRUE; //OCPP Status
  11716. }
  11717. }
  11718. for (int index = 0; index < GB_QUANTITY; index++)
  11719. {
  11720. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11721. {
  11722. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11723. }
  11724. }
  11725. //check Charge Point state
  11726. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11727. {
  11728. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11729. {
  11730. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11731. }
  11732. }
  11733. //check Charge Point state
  11734. for (int index = 0; index < AC_QUANTITY; index++)
  11735. {
  11736. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11737. {
  11738. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11739. }
  11740. }
  11741. if(checkState_Faulted == TRUE)
  11742. {
  11743. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11744. goto end;
  11745. }
  11746. // Parsing payload
  11747. SendLocalList = json_tokener_parse(payload);
  11748. if(!is_error(SendLocalList))
  11749. {
  11750. // Required data
  11751. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11752. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11753. // Optional data
  11754. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11755. {
  11756. //Check UpdateType
  11757. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11758. {
  11759. //Local list full update
  11760. DEBUG_INFO("Local list full update.\n");
  11761. OCPP_getListVerion();
  11762. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11763. {
  11764. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11765. goto end;
  11766. }
  11767. OCPP_cleanLocalList();
  11768. }
  11769. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11770. {
  11771. //Local list different update
  11772. DEBUG_INFO("Local list different update.\n");
  11773. OCPP_getListVerion();
  11774. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11775. {
  11776. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11777. goto end;
  11778. }
  11779. }
  11780. else
  11781. {
  11782. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11783. goto end;
  11784. }
  11785. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11786. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11787. {
  11788. 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")));
  11789. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11790. {
  11791. 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")));
  11792. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11793. 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")));
  11794. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11795. 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")));
  11796. }
  11797. // Add to db
  11798. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11799. {
  11800. //Local list full update
  11801. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11802. idx,
  11803. ShmOCPP16Data->SendLocalList.ListVersion,
  11804. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11805. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11806. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11807. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11808. // update list
  11809. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11810. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11811. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11812. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11813. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11814. }
  11815. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11816. {
  11817. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11818. idx,
  11819. ShmOCPP16Data->SendLocalList.ListVersion,
  11820. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11821. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11822. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11823. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11824. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11825. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11826. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11827. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11828. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11829. }
  11830. }
  11831. }
  11832. else
  11833. {
  11834. //Check UpdateType
  11835. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11836. {
  11837. //Local list full update
  11838. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11839. OCPP_cleanLocalList();
  11840. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11841. goto end;
  11842. }
  11843. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11844. {
  11845. //Local list different update
  11846. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11847. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11848. goto end;
  11849. }
  11850. }
  11851. result = PASS;
  11852. }
  11853. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11854. end:
  11855. json_object_put(SendLocalList);
  11856. sendSendLocalListConfirmation(uuid, comfirmstr);
  11857. return result;
  11858. }
  11859. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11860. {
  11861. mtrace();
  11862. int result = FAIL;
  11863. struct StructSetChargingProfile SetProfileReq = {0};
  11864. int tempchargingProfileIdInt;
  11865. int chargingSchedulePeriodCount = 0;
  11866. char comfirmstr[20]={0};
  11867. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  11868. char rmFileCmd[128]={0};
  11869. int profileQuantity = 0;
  11870. json_object *SetChargingProfile;
  11871. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11872. SetChargingProfile = json_tokener_parse(payload);
  11873. if(!is_error(SetChargingProfile))
  11874. {
  11875. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11876. {
  11877. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11878. }
  11879. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11880. {
  11881. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11882. {
  11883. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11884. }
  11885. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11886. {
  11887. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11888. }
  11889. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11890. {
  11891. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11892. }
  11893. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11894. {
  11895. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11896. }
  11897. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11898. {
  11899. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11900. }
  11901. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11902. {
  11903. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11904. }
  11905. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11906. {
  11907. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11908. }
  11909. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11910. {
  11911. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11912. }
  11913. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11914. {
  11915. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11916. {
  11917. 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")));
  11918. }
  11919. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11920. {
  11921. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11922. }
  11923. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11924. {
  11925. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11926. }
  11927. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11928. {
  11929. 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")));
  11930. }
  11931. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11932. {
  11933. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11934. if(chargingSchedulePeriodCount <= 10)
  11935. {
  11936. 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++)
  11937. {
  11938. 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)
  11939. {
  11940. 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"));
  11941. }
  11942. 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)
  11943. {
  11944. 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"));
  11945. }
  11946. 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)
  11947. {
  11948. 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"));
  11949. }
  11950. }
  11951. }
  11952. }
  11953. }
  11954. }
  11955. }
  11956. // Profile periods quantity check
  11957. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11958. {
  11959. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11960. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11961. goto end;
  11962. }
  11963. // Check invalid limit
  11964. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11965. {
  11966. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11967. {
  11968. 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)))) ||
  11969. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11970. {
  11971. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11972. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11973. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11974. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11975. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11976. goto end;
  11977. }
  11978. }
  11979. }
  11980. else
  11981. {
  11982. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11983. {
  11984. 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))
  11985. {
  11986. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11987. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11988. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11989. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11990. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11991. goto end;
  11992. }
  11993. }
  11994. }
  11995. // Profile purpose info check
  11996. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11997. {
  11998. FILE *fp;
  11999. char dataLine[4096]={0};
  12000. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12001. if(SetProfileReq.ConnectorId != 0)
  12002. {
  12003. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12004. DEBUG_WARN("Profile connector id is not 0.\n");
  12005. goto end;
  12006. }
  12007. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12008. if (!fp)
  12009. {
  12010. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12011. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12012. }
  12013. else
  12014. {
  12015. while(fscanf(fp, "%s", dataLine) != EOF)
  12016. {
  12017. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12018. {
  12019. profileQuantity += 1;
  12020. }
  12021. }
  12022. }
  12023. fclose(fp);
  12024. }
  12025. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12026. {
  12027. FILE *fp;
  12028. char dataLine[4096]={0};
  12029. char filename[128]={0};
  12030. int tmpProfileQuantity;
  12031. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12032. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12033. {
  12034. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12035. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12036. goto end;
  12037. }
  12038. if(SetProfileReq.ConnectorId == 0)
  12039. {
  12040. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12041. {
  12042. tmpProfileQuantity = 0;
  12043. memset(filename, 0, ARRAY_SIZE(filename));
  12044. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12045. fp = fopen(filename, "r");
  12046. if (!fp)
  12047. {
  12048. DEBUG_INFO("%s does not create.\n", filename);
  12049. fp = fopen(filename, "w+");
  12050. }
  12051. else
  12052. {
  12053. while(fscanf(fp, "%s", dataLine) != EOF)
  12054. {
  12055. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12056. {
  12057. tmpProfileQuantity += 1;
  12058. }
  12059. }
  12060. }
  12061. fclose(fp);
  12062. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12063. }
  12064. }
  12065. else
  12066. {
  12067. memset(filename, 0, ARRAY_SIZE(filename));
  12068. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12069. fp = fopen(filename, "r");
  12070. if (!fp)
  12071. {
  12072. DEBUG_INFO("%s does not create.\n", filename);
  12073. fp = fopen(filename, "w+");
  12074. }
  12075. else
  12076. {
  12077. while(fscanf(fp, "%s", dataLine) != EOF)
  12078. {
  12079. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12080. {
  12081. profileQuantity += 1;
  12082. }
  12083. }
  12084. }
  12085. fclose(fp);
  12086. }
  12087. }
  12088. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12089. {
  12090. int isMatchTransactiodId= FALSE;
  12091. FILE *fp;
  12092. char dataLine[4096]={0};
  12093. char filename[128]={0};
  12094. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12095. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12096. if(SetProfileReq.ConnectorId == 0)
  12097. {
  12098. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12099. DEBUG_WARN("Profile connector id is 0.\n");
  12100. goto end;
  12101. }
  12102. int tempIndex = 0;
  12103. //check Transaction active
  12104. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12105. {
  12106. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12107. {
  12108. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12109. }
  12110. else
  12111. {
  12112. tempIndex = SetProfileReq.ConnectorId -1;
  12113. }
  12114. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12115. {
  12116. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12117. {
  12118. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12119. {
  12120. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12121. {
  12122. isMatchTransactiodId = TRUE;
  12123. break;
  12124. }
  12125. }
  12126. }
  12127. }
  12128. }
  12129. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12130. {
  12131. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12132. {
  12133. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12134. }
  12135. else
  12136. {
  12137. tempIndex = SetProfileReq.ConnectorId -1;
  12138. }
  12139. for (int index = 0; index < CCS_QUANTITY; index++)
  12140. {
  12141. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12142. {
  12143. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12144. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12145. {
  12146. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12147. {
  12148. isMatchTransactiodId = TRUE;
  12149. break;
  12150. }
  12151. }
  12152. }
  12153. }
  12154. }
  12155. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12156. {
  12157. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12158. {
  12159. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12160. }
  12161. else
  12162. {
  12163. tempIndex = SetProfileReq.ConnectorId -1;
  12164. }
  12165. for (int index = 0; index < GB_QUANTITY; index++)
  12166. {
  12167. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12168. {
  12169. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12170. {
  12171. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12172. {
  12173. isMatchTransactiodId = TRUE;
  12174. break;
  12175. }
  12176. }
  12177. }
  12178. }
  12179. }
  12180. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12181. {
  12182. tempIndex = SetProfileReq.ConnectorId -1;
  12183. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12184. {
  12185. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12186. {
  12187. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12188. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12189. {
  12190. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12191. {
  12192. isMatchTransactiodId = TRUE;
  12193. break;
  12194. }
  12195. }
  12196. }
  12197. }
  12198. }
  12199. else
  12200. {
  12201. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12202. {
  12203. tempIndex = 2;
  12204. }
  12205. else
  12206. {
  12207. tempIndex = (SetProfileReq.ConnectorId -1);
  12208. }
  12209. for (int index = 0; index < AC_QUANTITY; index++)
  12210. {
  12211. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12212. {
  12213. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12214. {
  12215. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12216. {
  12217. isMatchTransactiodId = TRUE;
  12218. break;
  12219. }
  12220. }
  12221. }
  12222. }
  12223. }
  12224. //check Transaction active
  12225. if(isMatchTransactiodId == FALSE)
  12226. {
  12227. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12228. DEBUG_WARN("Tx profile transaction id is not match.\n");
  12229. goto end;
  12230. }
  12231. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12232. {
  12233. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12234. DEBUG_WARN("Connector id is over max gun number.\n");
  12235. goto end;
  12236. }
  12237. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12238. fp = fopen(filename, "r");
  12239. if (!fp)
  12240. {
  12241. DEBUG_INFO("%s does not create.\n", filename);
  12242. fp = fopen(filename, "w+");
  12243. }
  12244. else
  12245. {
  12246. //Check Charging Profile Count
  12247. while(fscanf(fp, "%s", dataLine) != EOF)
  12248. {
  12249. //DEBUG_INFO("word=%s\n",word);
  12250. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12251. {
  12252. profileQuantity += 1;
  12253. }
  12254. }
  12255. }
  12256. fclose(fp);
  12257. }
  12258. // Check ChargeProfileMaxStackLevel
  12259. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12260. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12261. {
  12262. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12263. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12264. goto end;
  12265. }
  12266. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12267. {
  12268. FILE *fp;
  12269. char dataLine[4096]={0};
  12270. char fnametemp[128]={0};
  12271. int tmpProfileQuantity;
  12272. //Check ChargePointMaxProfile.json exit
  12273. profileQuantity = 0;
  12274. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12275. {
  12276. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  12277. //Check Charging Profile Count
  12278. tmpProfileQuantity = 0;
  12279. while(fscanf(fp, "%s", dataLine) != EOF)
  12280. {
  12281. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12282. {
  12283. profileQuantity += 1;
  12284. tmpProfileQuantity += 1;
  12285. }
  12286. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12287. }
  12288. fclose(fp);
  12289. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12290. }
  12291. //Check TxDefaultProfile_%d.json
  12292. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12293. {
  12294. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12295. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12296. if((access(fnametemp,F_OK))!=-1)
  12297. {
  12298. fp = fopen(fnametemp, "r");
  12299. //Check Charging Profile Count
  12300. tmpProfileQuantity = 0;
  12301. while(fscanf(fp, "%s", dataLine) != EOF)
  12302. {
  12303. //DEBUG_INFO("word=%s\n",word);
  12304. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12305. {
  12306. profileQuantity += 1;
  12307. tmpProfileQuantity += 1;
  12308. }
  12309. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12310. }
  12311. fclose(fp);
  12312. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12313. }
  12314. }
  12315. //Check TxProfile_%d.json
  12316. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12317. {
  12318. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12319. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  12320. if((access(fnametemp,F_OK))!=-1)
  12321. {
  12322. fp = fopen(fnametemp, "r");
  12323. //Check Charging Profile Count
  12324. tmpProfileQuantity = 0;
  12325. while(fscanf(fp, "%s", dataLine) != EOF)
  12326. {
  12327. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12328. {
  12329. profileQuantity += 1;
  12330. tmpProfileQuantity += 1;
  12331. }
  12332. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12333. }
  12334. fclose(fp);
  12335. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12336. }
  12337. }
  12338. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12339. if(profileQuantity > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12340. {
  12341. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12342. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12343. goto end;
  12344. }
  12345. }
  12346. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12347. //**********************************Write to File********************************************************/
  12348. {
  12349. FILE *infile;
  12350. FILE *outfile;
  12351. char dataLine[4096]={0};
  12352. char filename[128]={0};
  12353. int chkChar=0;
  12354. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12355. {
  12356. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12357. {
  12358. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12359. }
  12360. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12361. {
  12362. if(SetProfileReq.ConnectorId==0)
  12363. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12364. else
  12365. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12366. }
  12367. else
  12368. {
  12369. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12370. }
  12371. infile = fopen (filename, "r");
  12372. outfile = fopen (tempfile, "w");
  12373. chkChar = fgetc(infile);
  12374. rewind(infile);
  12375. if(chkChar == EOF)
  12376. {
  12377. // Profile is empty
  12378. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12379. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12380. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12381. fclose(infile);
  12382. fclose(outfile);
  12383. sprintf(rmFileCmd,"rm -f %s",filename);
  12384. system(rmFileCmd);
  12385. rename(tempfile, filename);
  12386. }
  12387. else
  12388. {
  12389. // Profile is not empty
  12390. int ChargingProfileAdded = FALSE;
  12391. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12392. {
  12393. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12394. json_object *tmpChargingProfile;
  12395. tmpChargingProfile = json_tokener_parse(dataLine);
  12396. if(!is_error(SetChargingProfile))
  12397. {
  12398. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12399. {
  12400. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12401. {
  12402. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12403. }
  12404. }
  12405. }
  12406. json_object_put(tmpChargingProfile);
  12407. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12408. {
  12409. if(ChargingProfileAdded == FALSE)
  12410. {
  12411. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12412. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12413. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12414. ChargingProfileAdded = TRUE;
  12415. }
  12416. }
  12417. else
  12418. {
  12419. fprintf(outfile,"%s\n",dataLine);
  12420. if(ChargingProfileAdded == FALSE)
  12421. {
  12422. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12423. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12424. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12425. ChargingProfileAdded = TRUE;
  12426. }
  12427. }
  12428. } // end of while loop
  12429. fclose(infile);
  12430. fclose(outfile);
  12431. sprintf(rmFileCmd,"rm -f %s",filename);
  12432. system(rmFileCmd);
  12433. rename(tempfile, filename);
  12434. }
  12435. }
  12436. sleep(1);
  12437. result = TRUE;
  12438. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12439. }
  12440. end:
  12441. json_object_put(SetChargingProfile);
  12442. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12443. {
  12444. if(SetProfileReq.ConnectorId == 0)
  12445. {
  12446. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12447. {
  12448. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  12449. }
  12450. }
  12451. else
  12452. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12453. }
  12454. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12455. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12456. return result;
  12457. }
  12458. int handleTriggerMessageRequest(char *uuid, char *payload)
  12459. {
  12460. mtrace();
  12461. int result = FAIL;
  12462. int connectorIdIsNULL = FALSE;
  12463. int connectorIdInt =0;
  12464. char sstr[40]={0},sstrtemp[100]={ 0 };
  12465. char requestedMessagestr[40]={0};
  12466. char comfirmstr[20]={0};
  12467. int c = 0;
  12468. char *loc;
  12469. DEBUG_INFO("handleTriggerMessageRequest\n");
  12470. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12471. strcpy(sstrtemp, stringtrimspace(payload));
  12472. c = 0;
  12473. loc = strstr(sstrtemp, "requestedMessage");
  12474. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12475. {
  12476. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12477. c++;
  12478. }
  12479. sstr[c] = '\0';
  12480. strcpy(requestedMessagestr, sstr);
  12481. c = 0;
  12482. loc = strstr(sstrtemp, "connectorId");
  12483. if(loc == NULL)
  12484. {
  12485. connectorIdIsNULL = TRUE;
  12486. }
  12487. else
  12488. {
  12489. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12490. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12491. {
  12492. sstr[c] = loc[strlen("connectorId")+2+c];
  12493. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12494. c++;
  12495. }
  12496. sstr[c] = '\0';
  12497. connectorIdInt = atoi(sstr);
  12498. }
  12499. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12500. {
  12501. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12502. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12503. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12504. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12505. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12506. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12507. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12508. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12509. {
  12510. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12511. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12512. return TRUE;
  12513. }
  12514. else
  12515. {
  12516. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12517. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12518. }
  12519. }
  12520. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12521. {
  12522. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12523. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12524. return TRUE;
  12525. }
  12526. //==========================
  12527. // Trigger message
  12528. //==========================
  12529. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12530. {
  12531. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12532. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12533. {
  12534. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12535. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12536. }
  12537. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12538. }
  12539. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12540. {
  12541. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  12542. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12543. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12544. }
  12545. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12546. {
  12547. //sendBootNotificationRequest();
  12548. server_sign = FALSE;
  12549. }
  12550. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12551. {
  12552. refreshStartTimer(&clientTime.Heartbeat);
  12553. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  12554. }
  12555. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12556. {
  12557. if(connectorIdIsNULL == FALSE)
  12558. {
  12559. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12560. {
  12561. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12562. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12563. }
  12564. }
  12565. else
  12566. {
  12567. for(int idx=0;idx< gunTotalNumber;idx++)
  12568. {
  12569. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12570. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12571. }
  12572. }
  12573. }
  12574. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12575. {
  12576. if(connectorIdIsNULL == FALSE)
  12577. {
  12578. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  12579. {
  12580. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12581. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  12582. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12583. }
  12584. }
  12585. else
  12586. {
  12587. for(int idx=0;idx< gunTotalNumber;idx++)
  12588. {
  12589. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  12590. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12591. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12592. }
  12593. }
  12594. }
  12595. return result;
  12596. }
  12597. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12598. {
  12599. mtrace();
  12600. int result = FAIL;
  12601. int connectorIdInt =0;
  12602. char comfirmstr[20]={0};
  12603. int tempIndex = 0;
  12604. json_object *UnlockConnector;
  12605. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12606. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12607. UnlockConnector = json_tokener_parse(payload);
  12608. if(!is_error(UnlockConnector))
  12609. {
  12610. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12611. {
  12612. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12613. }
  12614. }
  12615. json_object_put(UnlockConnector);
  12616. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12617. if(gunTotalNumber == 0)
  12618. {
  12619. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12620. goto end;
  12621. }
  12622. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12623. {
  12624. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12625. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12626. goto end;
  12627. }
  12628. else
  12629. {
  12630. //check Transaction active
  12631. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12632. {
  12633. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12634. {
  12635. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12636. }
  12637. else
  12638. {
  12639. tempIndex = connectorIdInt -1;
  12640. }
  12641. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12642. {
  12643. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12644. {
  12645. //stop Transaction
  12646. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12647. }
  12648. }
  12649. }
  12650. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12651. {
  12652. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12653. {
  12654. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12655. }
  12656. else
  12657. {
  12658. tempIndex = connectorIdInt -1;
  12659. }
  12660. for (int index = 0; index < CCS_QUANTITY; index++)
  12661. {
  12662. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12663. {
  12664. //stop Transaction
  12665. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12666. }
  12667. }
  12668. }
  12669. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12670. {
  12671. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12672. {
  12673. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12674. }
  12675. else
  12676. {
  12677. tempIndex = connectorIdInt -1;
  12678. }
  12679. for (int index = 0; index < GB_QUANTITY; index++)
  12680. {
  12681. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12682. {
  12683. //stop Transaction
  12684. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12685. }
  12686. }
  12687. }
  12688. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12689. {
  12690. tempIndex = connectorIdInt -1;
  12691. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12692. {
  12693. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12694. {
  12695. //stop Transaction
  12696. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12697. }
  12698. }
  12699. }
  12700. else
  12701. {
  12702. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12703. {
  12704. tempIndex = 2;
  12705. }
  12706. else
  12707. {
  12708. tempIndex = connectorIdInt-1;
  12709. }
  12710. for (int index = 0; index < AC_QUANTITY; index++)
  12711. {
  12712. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12713. {
  12714. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12715. }
  12716. }
  12717. }
  12718. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12719. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  12720. result = TRUE;
  12721. return result;
  12722. }
  12723. end:
  12724. //json_object_put(obj); --- remove temporally
  12725. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12726. return result;
  12727. }
  12728. static char UpdateFirmwarepayloadData[300]={0};
  12729. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12730. {
  12731. mtrace();
  12732. int result = FAIL;
  12733. pthread_t t;
  12734. sendUpdateFirmwareConfirmation(uuid);
  12735. memset(UpdateFirmwarepayloadData, 0, 300);
  12736. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12737. if(!interLock.isUpdateFirmwareGoing)
  12738. {
  12739. interLock.isUpdateFirmwareGoing = 1;
  12740. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12741. sleep(1);
  12742. }
  12743. else
  12744. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12745. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  12746. return result;
  12747. }
  12748. void *UpdateFirmwareProcess(void *data)
  12749. {
  12750. pthread_detach(pthread_self());
  12751. mtrace();
  12752. int retriesInt =0, retryIntervalInt=0;
  12753. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  12754. int port=0;
  12755. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  12756. int isSuccess = 0;
  12757. char ftpbuf[1024];
  12758. char temp[1024];
  12759. char * pch;
  12760. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12761. json_object *UpdateFirmware;
  12762. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12763. if(!is_error(UpdateFirmware))
  12764. {
  12765. // Required data
  12766. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12767. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12768. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12769. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12770. // Optional data
  12771. if(json_object_object_get(UpdateFirmware, "retries"))
  12772. {
  12773. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12774. }
  12775. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12776. {
  12777. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12778. }
  12779. }
  12780. json_object_put(UpdateFirmware);
  12781. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12782. memset(path, 0, ARRAY_SIZE(path));
  12783. // Wait retrieveData
  12784. if(strlen(retrieveDatestr) > 10)
  12785. {
  12786. do
  12787. {
  12788. sleep(1);
  12789. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12790. }
  12791. // Ready to download
  12792. system("rm -f /mnt/*");
  12793. if(strncmp(locationstr,"http", 4) == 0)
  12794. {
  12795. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12796. sprintf(ftppath,"/%s", path);
  12797. DEBUG_INFO("locationstr: %s\n", locationstr);
  12798. DEBUG_INFO("protocol: %s\n",protocol);
  12799. DEBUG_INFO("host: %s\n",host);
  12800. DEBUG_INFO("path: %s\n",path);
  12801. DEBUG_INFO("ftppath: %s\n",ftppath);
  12802. int ftppathlen=strlen(ftppath);
  12803. int i=1;
  12804. char filenametemp[50];
  12805. while(i < ftppathlen)
  12806. {
  12807. int len=ftppathlen-i;
  12808. if(ftppath[len]== 47) // '/' ascll code: 47
  12809. {
  12810. DEBUG_INFO("compare '/' all right\n");
  12811. break;
  12812. }
  12813. i=i+1;
  12814. }
  12815. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12816. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12817. filenametemp[i+1] = 0;
  12818. do
  12819. {
  12820. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12821. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12822. sleep(1);
  12823. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12824. if(!isSuccess)
  12825. {
  12826. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12827. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12828. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12829. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12830. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12831. }
  12832. else
  12833. {
  12834. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12835. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12836. }
  12837. retriesInt--;
  12838. }while((isSuccess == 0)&&(retriesInt >= 0));
  12839. }
  12840. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12841. {
  12842. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12843. memset(temp, 0, ARRAY_SIZE(temp));
  12844. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12845. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12846. int ftppathlen=strlen(ftpbuf);
  12847. int i=1;
  12848. char filenametemp[50];
  12849. while(i < ftppathlen)
  12850. {
  12851. int len=ftppathlen-i;
  12852. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12853. {
  12854. DEBUG_INFO(" compare '/' all right\n");
  12855. break;
  12856. }
  12857. i=i+1;
  12858. }
  12859. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12860. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12861. filenametemp[i+1] = 0;
  12862. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12863. pch=strchr(temp,'@');
  12864. if(pch==NULL)
  12865. {
  12866. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12867. protocol, host, &port, path);
  12868. strcpy(user,"anonymous");
  12869. strcpy(password,"");
  12870. }
  12871. else
  12872. {
  12873. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12874. protocol, user, password, host, &port, path);
  12875. }
  12876. sscanf(host,"%[^/]%s",host1, path1);
  12877. sprintf(ftppath,"%s", path1);
  12878. //DEBUG_INFO("protocol =%s\n",protocol);
  12879. //DEBUG_INFO("user =%s\n",user);
  12880. //DEBUG_INFO("password =%s\n",password);
  12881. //DEBUG_INFO("host1 =%s\n",host1);
  12882. //DEBUG_INFO("port =%d\n",port);
  12883. //DEBUG_INFO("path1 =%s\n",path1);
  12884. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12885. //ftpFile(host, user, password, port, ftppath, fname);
  12886. //download firmware pthred
  12887. if(port == 0)
  12888. {
  12889. port = 21;
  12890. }
  12891. do
  12892. {
  12893. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12894. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12895. sleep(1);
  12896. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12897. if(!isSuccess)
  12898. {
  12899. //BulldogUtil.sleepMs(interval*1000);
  12900. DEBUG_INFO("Update firmware request and download file fail.\n");
  12901. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12902. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12903. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12904. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12905. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12906. }
  12907. else
  12908. {
  12909. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12910. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12911. }
  12912. retriesInt--;
  12913. }while((!isSuccess)&&(retriesInt >= 0));
  12914. }
  12915. else
  12916. {
  12917. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12918. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12919. sleep(1);
  12920. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12921. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12922. }
  12923. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12924. interLock.isUpdateFirmwareGoing = 0;
  12925. pthread_exit(NULL);
  12926. }
  12927. int handleCertificateSignedRequest(char *uuid, char *payload)
  12928. {
  12929. mtrace();
  12930. int result = PASS;
  12931. json_object *CertificateSigned;
  12932. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12933. CertificateSigned = json_tokener_parse(payload);
  12934. if(!is_error(CertificateSigned))
  12935. {
  12936. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  12937. }
  12938. json_object_put(CertificateSigned);
  12939. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  12940. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  12941. fclose(fp);
  12942. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12943. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  12944. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  12945. sendCertificateSignedConfirmation(uuid);
  12946. return result;
  12947. }
  12948. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12949. {
  12950. mtrace();
  12951. int result = PASS;
  12952. json_object *DeleteCertificate;
  12953. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12954. DeleteCertificate = json_tokener_parse(payload);
  12955. if(!is_error(DeleteCertificate))
  12956. {
  12957. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12958. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12959. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12960. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12961. }
  12962. json_object_put(DeleteCertificate);
  12963. /*
  12964. * TODO: Delete certificateSigned process
  12965. */
  12966. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  12967. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  12968. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  12969. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  12970. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  12971. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  12972. sendDeleteCertificateConfirmation(uuid);
  12973. return result;
  12974. }
  12975. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12976. {
  12977. mtrace();
  12978. int result = PASS;
  12979. json_object *ExtendedTriggerMessage;
  12980. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12981. ExtendedTriggerMessage = json_tokener_parse(payload);
  12982. if(!is_error(ExtendedTriggerMessage))
  12983. {
  12984. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12985. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12986. {
  12987. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12988. }
  12989. else
  12990. {
  12991. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  12992. }
  12993. }
  12994. json_object_put(ExtendedTriggerMessage);
  12995. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  12996. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  12997. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  12998. {
  12999. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13000. }
  13001. else
  13002. {
  13003. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13004. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13005. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13006. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13007. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13008. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13009. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13010. {
  13011. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13012. }
  13013. else
  13014. {
  13015. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13016. }
  13017. }
  13018. sendExtendedTriggerMessageConfirmation(uuid);
  13019. //==========================
  13020. // Trigger message
  13021. //==========================
  13022. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13023. {
  13024. //sendBootNotificationRequest();
  13025. server_sign = FALSE;
  13026. }
  13027. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13028. {
  13029. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13030. }
  13031. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13032. {
  13033. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13034. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13035. {
  13036. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13037. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13038. }
  13039. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13040. }
  13041. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13042. {
  13043. refreshStartTimer(&clientTime.Heartbeat);
  13044. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13045. }
  13046. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13047. {
  13048. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13049. {
  13050. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13051. }
  13052. else
  13053. {
  13054. for(int idx=0;idx< gunTotalNumber;idx++)
  13055. {
  13056. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13057. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13058. }
  13059. }
  13060. }
  13061. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13062. {
  13063. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  13064. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13065. {
  13066. 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\" &");
  13067. }
  13068. }
  13069. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13070. {
  13071. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13072. {
  13073. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13074. }
  13075. else
  13076. {
  13077. for(int idx=0;idx< gunTotalNumber;idx++)
  13078. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13079. }
  13080. }
  13081. return result;
  13082. }
  13083. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13084. {
  13085. mtrace();
  13086. int result = PASS;
  13087. json_object *GetInstalledCertificateIds;
  13088. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13089. GetInstalledCertificateIds = json_tokener_parse(payload);
  13090. if(!is_error(GetInstalledCertificateIds))
  13091. {
  13092. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13093. }
  13094. json_object_put(GetInstalledCertificateIds);
  13095. /*
  13096. * TODO: Return installed certificate process
  13097. */
  13098. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13099. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  13100. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13101. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13102. sendGetInstalledCertificateIdsConfirmation(uuid);
  13103. return result;
  13104. }
  13105. int handleGetLogRequest(char *uuid, char *payload)
  13106. {
  13107. mtrace();
  13108. int result = PASS;
  13109. json_object *GetLog;
  13110. DEBUG_INFO("handleGetLogRequest...\n");
  13111. GetLog = json_tokener_parse(payload);
  13112. if(!is_error(GetLog))
  13113. {
  13114. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13115. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13116. if(json_object_object_get(GetLog, "retries") != NULL)
  13117. {
  13118. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13119. }
  13120. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13121. {
  13122. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13123. }
  13124. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13125. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13126. {
  13127. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13128. }
  13129. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13130. {
  13131. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13132. }
  13133. }
  13134. json_object_put(GetLog);
  13135. /*
  13136. * TODO: Upload log process
  13137. */
  13138. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  13139. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  13140. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  13141. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  13142. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  13143. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  13144. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  13145. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  13146. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  13147. sendGetLogConfirmation(uuid);
  13148. return result;
  13149. }
  13150. int handleInstallCertificateRequest(char *uuid, char *payload)
  13151. {
  13152. mtrace();
  13153. int result = PASS;
  13154. json_object *InstallCertificate;
  13155. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13156. InstallCertificate = json_tokener_parse(payload);
  13157. if(!is_error(InstallCertificate))
  13158. {
  13159. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13160. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13161. /*
  13162. * TODO: Install certificate process
  13163. */
  13164. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  13165. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  13166. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  13167. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  13168. sendInstallCertificateConfirmation(uuid);
  13169. }
  13170. json_object_put(InstallCertificate);
  13171. return result;
  13172. }
  13173. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13174. {
  13175. mtrace();
  13176. int result = PASS;
  13177. json_object *SignedUpdateFirmware;
  13178. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13179. SignedUpdateFirmware = json_tokener_parse(payload);
  13180. if(!is_error(SignedUpdateFirmware))
  13181. {
  13182. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13183. {
  13184. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13185. }
  13186. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13187. {
  13188. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13189. }
  13190. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13191. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13192. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13193. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13194. {
  13195. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13196. }
  13197. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13198. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13199. }
  13200. json_object_put(SignedUpdateFirmware);
  13201. /*
  13202. * TODO: Upgrade firmware process
  13203. */
  13204. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13205. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  13206. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  13207. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  13208. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  13209. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  13210. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  13211. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  13212. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  13213. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  13214. sendInstallCertificateConfirmation(uuid);
  13215. return result;
  13216. }
  13217. int handleUnknownRequest(char *uuid, char *payload)
  13218. {
  13219. mtrace();
  13220. int result = PASS;
  13221. DEBUG_INFO("handleUnknownRequest...\n");
  13222. sendUnknownConfirmation(uuid);
  13223. result = PASS;
  13224. return result;
  13225. }
  13226. //==========================================
  13227. // Handle server response routine
  13228. //==========================================
  13229. void handleAuthorizeResponse(char *payload, int gun_index)
  13230. {
  13231. mtrace();
  13232. char expiryDatestr[30]={0};
  13233. char parentIdTagstr[20]={0};
  13234. char statusstr[20]={0};
  13235. int expiryDateISNULL=FALSE;
  13236. int parentIdTagISNULL=FALSE;
  13237. DEBUG_INFO("handleAuthorizeResponse...\n");
  13238. json_object *Authorize;
  13239. Authorize = json_tokener_parse(payload);
  13240. if(!is_error(Authorize))
  13241. {
  13242. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13243. {
  13244. // Required data
  13245. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13246. // Optional data
  13247. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13248. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13249. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13250. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13251. }
  13252. }
  13253. json_object_put(Authorize);
  13254. if(expiryDateISNULL == FALSE)
  13255. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13256. if(parentIdTagISNULL == FALSE)
  13257. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13258. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  13259. //Update idTag information to authorization cache if supproted
  13260. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13261. {
  13262. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13263. }
  13264. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  13265. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13266. authorizeRetryTimes = 0;
  13267. }
  13268. void handleBootNotificationResponse(char *payload, int gun_index)
  13269. {
  13270. mtrace();
  13271. char statusStr[12]={0};
  13272. char currentTimeStr[30]={0};
  13273. int intervalInt = 0;
  13274. DEBUG_INFO("handleBootNotificationResponse...\n");
  13275. json_object *BootNotification;
  13276. BootNotification = json_tokener_parse(payload);
  13277. if(!is_error(BootNotification))
  13278. {
  13279. // Required data
  13280. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13281. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13282. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13283. }
  13284. json_object_put(BootNotification);
  13285. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13286. BootNotificationInterval = intervalInt;
  13287. //write back to ShmOCPP16Data->BootNotification
  13288. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  13289. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13290. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  13291. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13292. {
  13293. if((intervalInt == 0) || (intervalInt >= 10))
  13294. {
  13295. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13296. HeartBeatWaitTime = intervalInt;
  13297. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13298. }
  13299. server_sign = TRUE;
  13300. server_pending =FALSE;
  13301. }
  13302. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13303. {
  13304. server_pending = TRUE;
  13305. }
  13306. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  13307. srand(time(NULL));
  13308. refreshStartTimer(&clientTime.Heartbeat);
  13309. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13310. SetOcppConnStatus(TRUE);
  13311. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  13312. }
  13313. void handleDataTransferResponse(char *payload, int gun_index)
  13314. {
  13315. json_object *DataTransfer = json_tokener_parse(payload);
  13316. if(!is_error(DataTransfer))
  13317. {
  13318. // Required data
  13319. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13320. // Optional data
  13321. if(json_object_object_get(DataTransfer, "data") != NULL)
  13322. {
  13323. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13324. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13325. if(!is_error(Data))
  13326. {
  13327. if(json_object_object_get(Data, "msgId") != NULL)
  13328. {
  13329. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13330. {
  13331. 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")));
  13332. }
  13333. }
  13334. }
  13335. json_object_put(Data);
  13336. }
  13337. }
  13338. json_object_put(DataTransfer);
  13339. }
  13340. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13341. {
  13342. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13343. //struct json_object *obj;
  13344. // obj = json_tokener_parse(payload);
  13345. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13346. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13347. //No fields are defined.
  13348. }
  13349. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13350. {
  13351. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13352. //struct json_object *obj;
  13353. // obj = json_tokener_parse(payload);
  13354. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13355. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13356. //No fields are defined.
  13357. }
  13358. void handleHeartbeatResponse(char *payload, int gun_index)
  13359. {
  13360. mtrace();
  13361. DEBUG_INFO("handleHeartbeatResponse...\n");
  13362. json_object *Heartbeat;
  13363. Heartbeat = json_tokener_parse(payload);
  13364. if(!is_error(Heartbeat))
  13365. {
  13366. // Required data
  13367. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13368. }
  13369. json_object_put(Heartbeat);
  13370. if(FirstHeartBeat == 0)
  13371. {
  13372. FirstHeartBeat = 1;
  13373. DEBUG_INFO("FirstHeartBeat \n");
  13374. }
  13375. HeartBeatWithNOResponse = 0;
  13376. refreshStartTimer(&clientTime.Heartbeat);
  13377. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  13378. }
  13379. void handleMeterValuesResponse(char *payload, int gun_index)
  13380. {
  13381. mtrace();
  13382. DEBUG_INFO("handleMeterValuesResponse...\n");
  13383. isQueueSendable = 1;
  13384. }
  13385. void handleStartTransactionResponse(char *payload, int gun_index)
  13386. {
  13387. mtrace();
  13388. //int transactionIdInt = 0;
  13389. FILE *outfile;
  13390. char data[100]={0};
  13391. DEBUG_INFO("handleStartTransactionResponse...\n");
  13392. json_object *StartTransaction;
  13393. StartTransaction = json_tokener_parse(payload);
  13394. if(!is_error(StartTransaction))
  13395. {
  13396. // Required data
  13397. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13398. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13399. // Optional data
  13400. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13401. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13402. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13403. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13404. }
  13405. json_object_put(StartTransaction);
  13406. isQueueSendable = 1;
  13407. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13408. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13409. //-----------Start : write to the Queue TransactionId file -----------------//
  13410. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  13411. {}
  13412. else
  13413. {
  13414. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  13415. if(log == NULL)
  13416. {
  13417. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13418. return ;
  13419. }
  13420. else
  13421. {
  13422. fclose(log);
  13423. }
  13424. }
  13425. // open file for writing
  13426. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13427. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  13428. {
  13429. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  13430. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13431. fputs(data, outfile);
  13432. fclose (outfile);
  13433. }
  13434. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13435. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13436. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13437. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  13438. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13439. }
  13440. void handleStatusNotificationResponse(char *payload, int gun_index)
  13441. {
  13442. mtrace();
  13443. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13444. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13445. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13446. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13447. }
  13448. void handleStopTransactionnResponse(char *payload, int gun_index)
  13449. {
  13450. mtrace();
  13451. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13452. json_object *StopTransaction;
  13453. StopTransaction = json_tokener_parse(payload);
  13454. if(!is_error(StopTransaction))
  13455. {
  13456. // Optional data
  13457. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13458. {
  13459. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13460. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13461. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13462. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13463. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13464. }
  13465. }
  13466. json_object_put(StopTransaction);
  13467. isQueueSendable = 1;
  13468. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13469. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13470. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13471. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13472. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13473. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13474. }
  13475. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13476. {
  13477. mtrace();
  13478. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13479. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  13480. }
  13481. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13482. {
  13483. mtrace();
  13484. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13485. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  13486. }
  13487. void handleSignCertificateResponse(char *payload, int gun_index)
  13488. {
  13489. mtrace();
  13490. DEBUG_INFO("handleSignCertificateResponse...\n");
  13491. json_object *SignCertificate;
  13492. SignCertificate = json_tokener_parse(payload);
  13493. if(!is_error(SignCertificate))
  13494. {
  13495. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13496. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  13497. }
  13498. json_object_put(SignCertificate);
  13499. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  13500. }
  13501. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13502. {
  13503. mtrace();
  13504. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13505. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13506. }
  13507. //==========================================
  13508. // Handle Error routine
  13509. //==========================================
  13510. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13511. {
  13512. mtrace();
  13513. #ifdef SystemLogMessage
  13514. DEBUG_INFO("errorCode: %s\n", errorCode);
  13515. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13516. DEBUG_INFO("errorDetails: %s\n", payload);
  13517. #endif
  13518. }
  13519. //===============================================
  13520. // Common routine
  13521. //===============================================
  13522. int initialConfigurationTable(void)
  13523. {
  13524. //clock_t start_t, end_t, total_t;
  13525. FILE *fp;
  13526. FILE *outfile;
  13527. char str[512]={0};
  13528. char sstr[256]={0};
  13529. int c = 0;
  13530. char *loc;
  13531. int confVersion = 12;
  13532. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13533. //start_t = clock();
  13534. //printf("Starting of the program, start_t = %ld\n", start_t);
  13535. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13536. // Check configuration file size is correct
  13537. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  13538. {
  13539. struct stat st;
  13540. stat("/Storage/OCPP/OCPPConfiguration", &st);
  13541. if(st.st_size < 3100)
  13542. {
  13543. system("rm -f /Storage/OCPP/OCPPConfiguration");
  13544. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13545. }
  13546. }
  13547. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  13548. {
  13549. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13550. if(outfile == NULL)
  13551. {
  13552. DEBUG_INFO("Error opening file\n");
  13553. return FALSE;
  13554. }
  13555. /*Core Profile*/
  13556. //AllowOfflineTxForUnknownId
  13557. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13560. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13561. //AuthorizationCacheEnabled
  13562. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13564. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13565. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13566. //AuthorizeRemoteTxRequests
  13567. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13570. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13571. //BlinkRepeat
  13572. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13575. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13576. //ClockAlignedDataInterval
  13577. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13580. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13581. //ConnectionTimeOut
  13582. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13585. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13586. //GetConfigurationMaxKeys
  13587. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13589. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13590. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13591. // HeartbeatInterval
  13592. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13593. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13595. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13596. // LightIntensity
  13597. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13600. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13601. // LocalAuthorizeOffline
  13602. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13605. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13606. // LocalPreAuthorize
  13607. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13608. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13610. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13611. // MaxEnergyOnInvalidId
  13612. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13613. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13615. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13616. // MeterValuesAlignedData
  13617. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13619. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13620. 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" );
  13621. else
  13622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13623. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13624. // MeterValuesAlignedDataMaxLength
  13625. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13627. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13628. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13629. else
  13630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13631. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13632. // MeterValuesSampledData
  13633. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13635. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13636. 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" );
  13637. else
  13638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13639. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13640. // MeterValuesSampledDataMaxLength
  13641. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13643. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13645. else
  13646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13647. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13648. // MeterValueSampleInterval
  13649. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13652. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13653. // MinimumStatusDuration
  13654. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13657. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13658. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13659. // NumberOfConnectors
  13660. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13662. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13663. {
  13664. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13665. }
  13666. else
  13667. {
  13668. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13669. }
  13670. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13671. // ResetRetries
  13672. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13675. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13676. // ConnectorPhaseRotation
  13677. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13680. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13681. // ConnectorPhaseRotationMaxLength
  13682. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13685. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13686. // StopTransactionOnEVSideDisconnect
  13687. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13690. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13691. // StopTransactionOnInvalidId
  13692. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13693. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13695. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13696. // StopTxnAlignedData
  13697. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13699. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13700. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13701. // StopTxnAlignedDataMaxLength
  13702. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13705. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13706. // StopTxnSampledData
  13707. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13709. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13711. else
  13712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13713. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13714. // StopTxnSampledDataMaxLength
  13715. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13717. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13718. {
  13719. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13720. }
  13721. else
  13722. {
  13723. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13724. }
  13725. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13726. // SupportedFeatureProfiles
  13727. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13728. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13730. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13731. // SupportedFeatureProfilesMaxLength
  13732. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13735. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13736. // TransactionMessageAttempts
  13737. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13740. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13741. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13742. // TransactionMessageRetryInterval
  13743. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13746. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13747. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13748. // UnlockConnectorOnEVSideDisconnect
  13749. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13752. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13753. // WebSocketPingInterval
  13754. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13757. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13758. // QueueOffLineMeterValues
  13759. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13762. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13763. // AuthorizationKey
  13764. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  13767. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13768. // SecurityProfile
  13769. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13771. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  13772. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13773. // DefaultPrice
  13774. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13776. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13778. // CustomDisplayCostAndPrice
  13779. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13782. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13783. // CustomIdleFeeAfterStop
  13784. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13787. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13788. // TimeOffset
  13789. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13791. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  13792. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13793. // NextTimeOffsetTransitionDateTime
  13794. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  13797. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13798. // TimeOffsetNextTransition
  13799. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  13802. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13803. // SystemUptimeSec
  13804. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13805. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13807. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13808. // FreeVend
  13809. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "Free-FreeVend");
  13811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13812. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13813. // OcppServer
  13814. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13816. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13817. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13818. // MaintainServer
  13819. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13821. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13822. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13823. // StatusNotificationPeriodically
  13824. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13826. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13827. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13828. // StatusNotificationInterval
  13829. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13833. // Configuration Version
  13834. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13835. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13836. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13837. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13838. //* Local Auth List Management Profile*/
  13839. #if 0
  13840. //For OCTT Test Case
  13841. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13844. #endif
  13845. #if 1
  13846. //LocalAuthListEnabled
  13847. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13850. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13851. #endif
  13852. //LocalAuthListMaxLength
  13853. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  13856. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13857. //SendLocalListMaxLength
  13858. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13862. //ReserveConnectorZeroSupported
  13863. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13866. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13867. //* Smart Charging Profile */
  13868. //ChargeProfileMaxStackLevel
  13869. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13872. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13873. // ChargingScheduleAllowedChargingRateUnit
  13874. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13875. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13877. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13878. // ChargingScheduleMaxPeriods
  13879. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13883. // ConnectorSwitch3to1PhaseSupported
  13884. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13885. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13887. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13888. // MaxChargingProfilesInstalled
  13889. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13890. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13892. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13893. fclose(outfile);
  13894. }
  13895. else
  13896. {
  13897. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  13898. char keystr[60]={0};
  13899. char readonlystr[10]={0};
  13900. char valuestr[256]={0};
  13901. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  13902. if(fp == NULL) {
  13903. DEBUG_INFO("Error opening file");
  13904. return FALSE;
  13905. }
  13906. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13907. {
  13908. //DEBUG_INFO("Get Configuration \n");
  13909. if(strlen(str) > 0)
  13910. {
  13911. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13912. //*************************key*********************************/
  13913. if(strstr(str, "key") != NULL)
  13914. {
  13915. loc = strstr(str, "key");
  13916. c = 0;
  13917. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13918. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13919. {
  13920. sstr[c] = loc[strlen("key")+3+c];
  13921. c++;
  13922. }
  13923. sstr[c] = '\0';
  13924. strcpy(keystr,sstr);
  13925. }
  13926. //*************************readonly*********************************/
  13927. if(strstr(str, "readonly") != NULL)
  13928. {
  13929. loc = strstr(str, "readonly");
  13930. c = 0;
  13931. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13932. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13933. {
  13934. sstr[c] = loc[strlen("readonly")+2+c];
  13935. c++;
  13936. }
  13937. sstr[c] = '\0';
  13938. strcpy(readonlystr,sstr);
  13939. }
  13940. //*************************value*********************************/
  13941. if(strstr(str, "value") != NULL)
  13942. {
  13943. loc = strstr(str, "value");
  13944. c = 0;
  13945. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13946. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13947. {
  13948. sstr[c] = loc[strlen("value")+3+c];
  13949. c++;
  13950. }
  13951. sstr[c] = '\0';
  13952. strcpy(valuestr,sstr);
  13953. }
  13954. // DEBUG_INFO("keystr=%s\n",keystr);
  13955. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13956. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13957. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13958. {
  13959. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13960. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13961. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13962. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13963. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13964. }
  13965. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13966. {
  13967. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13968. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13969. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13970. }
  13971. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13972. {
  13973. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13974. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13975. }
  13976. if(strcmp(keystr, "BlinkRepeat") == 0)
  13977. {
  13978. //Charger.BlinkRepeat = Integer.parseInt(value);
  13979. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13980. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13981. }
  13982. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13983. {
  13984. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13985. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13986. }
  13987. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13988. {
  13989. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13990. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13991. }
  13992. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13993. {
  13994. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13995. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13996. }
  13997. if(strcmp(keystr, "HeartbeatInterval") == 0)
  13998. {
  13999. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14000. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14001. HeartBeatWaitTime = atoi(valuestr);
  14002. }
  14003. if(strcmp(keystr, "LightIntensity") == 0)
  14004. {
  14005. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14006. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14007. }
  14008. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14009. {
  14010. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14011. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14012. }
  14013. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14014. {
  14015. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14016. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14017. }
  14018. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14019. {
  14020. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14021. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14022. }
  14023. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14024. {
  14025. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14026. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14027. }
  14028. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14029. {
  14030. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14031. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14032. }
  14033. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14034. {
  14035. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14036. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14037. }
  14038. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14039. {
  14040. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14041. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14042. }
  14043. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14044. {
  14045. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14046. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14047. }
  14048. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14049. {
  14050. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14051. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14052. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14053. }
  14054. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14055. {
  14056. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14057. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14058. }
  14059. if(strcmp(keystr, "ResetRetries") == 0)
  14060. {
  14061. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14062. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14063. }
  14064. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14065. {
  14066. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14067. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14068. }
  14069. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14070. {
  14071. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14072. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14073. }
  14074. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14075. {
  14076. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14077. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14078. }
  14079. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14080. {
  14081. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14082. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14083. }
  14084. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14085. {
  14086. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14087. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14088. }
  14089. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14090. {
  14091. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14092. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14093. }
  14094. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14095. {
  14096. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14097. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14098. }
  14099. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14100. {
  14101. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14102. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14103. }
  14104. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14105. {
  14106. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14107. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14108. }
  14109. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14110. {
  14111. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14112. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14113. }
  14114. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14115. {
  14116. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14117. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14118. TransactionMessageAttemptsValue = atoi(valuestr);
  14119. }
  14120. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14121. {
  14122. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14123. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14124. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14125. }
  14126. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14127. {
  14128. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14129. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14130. }
  14131. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14132. {
  14133. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14134. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14135. }
  14136. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14137. {
  14138. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14139. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14140. }
  14141. if(strcmp(keystr, "AuthorizationKey") == 0)
  14142. {
  14143. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14144. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14145. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14146. }
  14147. if(strcmp(keystr, "SecurityProfile") == 0)
  14148. {
  14149. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14150. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14151. }
  14152. if(strcmp(keystr, "DefaultPrice") == 0)
  14153. {
  14154. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14155. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14156. }
  14157. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14158. {
  14159. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14160. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14161. }
  14162. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14163. {
  14164. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14165. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14166. }
  14167. if(strcmp(keystr, "TimeOffset") == 0)
  14168. {
  14169. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14170. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  14171. }
  14172. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  14173. {
  14174. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14175. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  14176. }
  14177. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  14178. {
  14179. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14180. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  14181. }
  14182. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14183. {
  14184. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14185. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  14186. }
  14187. if(strcmp(keystr, "FreeVend") == 0)
  14188. {
  14189. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14190. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14191. }
  14192. if(strcmp(keystr, "OcppServer") == 0)
  14193. {
  14194. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14195. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14196. }
  14197. if(strcmp(keystr, "MaintainServer") == 0)
  14198. {
  14199. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14200. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14201. }
  14202. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14203. {
  14204. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14205. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14206. }
  14207. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14208. {
  14209. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14210. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14211. }
  14212. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14213. {
  14214. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14215. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14216. }
  14217. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14218. {
  14219. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14220. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14221. }
  14222. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14223. {
  14224. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14225. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14226. }
  14227. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14228. {
  14229. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14230. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14231. }
  14232. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14233. {
  14234. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14235. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14236. }
  14237. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14238. {
  14239. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14240. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14241. }
  14242. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14243. {
  14244. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14245. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14246. }
  14247. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14248. {
  14249. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14250. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14251. }
  14252. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14253. {
  14254. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14255. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14256. }
  14257. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14258. {
  14259. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14260. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14261. }
  14262. }
  14263. }
  14264. fclose(fp);
  14265. }
  14266. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14267. {
  14268. return PASS;
  14269. }
  14270. else
  14271. {
  14272. return FAIL;
  14273. }
  14274. }
  14275. void StoreConfigurationTable(void)
  14276. {
  14277. FILE *outfile;
  14278. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14279. if(outfile == NULL)
  14280. {
  14281. DEBUG_INFO("Error opening file");
  14282. return ;
  14283. }
  14284. /*Core Profile*/
  14285. //AllowOfflineTxForUnknownId
  14286. /*
  14287. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14288. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14291. */
  14292. //DEBUG_INFO("data=%s\n",data);
  14293. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14294. //AuthorizationCacheEnabled
  14295. /*
  14296. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14298. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14299. */
  14300. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14301. //AuthorizeRemoteTxRequests
  14302. /*
  14303. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14306. */
  14307. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14308. //BlinkRepeat
  14309. /*
  14310. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14312. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14313. */
  14314. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14315. //ClockAlignedDataInterval
  14316. /*
  14317. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14319. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14320. */
  14321. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14322. //ConnectionTimeOut
  14323. /*
  14324. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14326. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14327. */
  14328. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14329. //GetConfigurationMaxKeys
  14330. /*
  14331. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14333. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14334. */
  14335. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14336. // HeartbeatInterval
  14337. /*
  14338. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14341. */
  14342. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14343. // LightIntensity
  14344. /*
  14345. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14348. */
  14349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14350. // LocalAuthorizeOffline
  14351. /*
  14352. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14354. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14355. */
  14356. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14357. // LocalPreAuthorize
  14358. /*
  14359. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14362. */
  14363. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14364. // MaxEnergyOnInvalidId
  14365. /*
  14366. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14368. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14369. */
  14370. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14371. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14372. // MeterValuesAlignedData
  14373. /*
  14374. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14375. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14377. */
  14378. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14379. // MeterValuesAlignedDataMaxLength
  14380. /*
  14381. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14384. */
  14385. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14386. // MeterValuesSampledData
  14387. /*
  14388. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14389. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14391. */
  14392. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14393. // MeterValuesSampledDataMaxLength
  14394. /*
  14395. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14398. */
  14399. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14400. // MeterValueSampleInterval
  14401. /*
  14402. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14403. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14404. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14405. */
  14406. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14407. // MinimumStatusDuration
  14408. /*
  14409. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14412. */
  14413. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14414. // NumberOfConnectors
  14415. /*
  14416. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14417. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14418. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14419. {
  14420. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14421. }
  14422. else
  14423. {
  14424. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14425. }
  14426. */
  14427. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14428. // ResetRetries
  14429. /*
  14430. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14432. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14433. */
  14434. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14435. // ConnectorPhaseRotation
  14436. /*
  14437. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14438. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14440. */
  14441. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14442. // ConnectorPhaseRotationMaxLength
  14443. /*
  14444. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14445. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14446. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14447. */
  14448. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14449. // StopTransactionOnEVSideDisconnect
  14450. /*
  14451. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14452. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14453. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14454. */
  14455. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14456. // StopTransactionOnInvalidId
  14457. /*
  14458. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14459. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14460. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14461. */
  14462. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14463. // StopTxnAlignedData
  14464. /*
  14465. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14466. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14467. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14468. */
  14469. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14470. // StopTxnAlignedDataMaxLength
  14471. /*
  14472. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14474. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14475. */
  14476. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14477. // StopTxnSampledData
  14478. /*
  14479. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14480. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14481. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14482. */
  14483. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14484. // StopTxnSampledDataMaxLength
  14485. /*
  14486. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14488. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14489. */
  14490. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14491. // SupportedFeatureProfiles
  14492. /*
  14493. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14494. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14495. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14496. */
  14497. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14498. // SupportedFeatureProfilesMaxLength
  14499. /*
  14500. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14503. */
  14504. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14505. // TransactionMessageAttempts
  14506. /*
  14507. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14508. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14510. */
  14511. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14512. // TransactionMessageRetryInterval
  14513. /*
  14514. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14515. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14516. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14517. */
  14518. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14519. // UnlockConnectorOnEVSideDisconnect
  14520. /*
  14521. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14522. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14523. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14524. */
  14525. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14526. // WebSocketPingInterval
  14527. /*
  14528. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14529. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14530. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14531. */
  14532. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14533. // QueueOffLineMeterValues
  14534. /*
  14535. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14537. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14538. */
  14539. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14540. // AuthorizationKey
  14541. /*
  14542. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14543. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14544. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14545. */
  14546. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14547. // SecurityProfile
  14548. /*
  14549. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14551. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14552. */
  14553. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14554. // DefaultPrice
  14555. /*
  14556. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14559. */
  14560. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14561. // CustomDisplayCostAndPrice
  14562. /*
  14563. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14564. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14565. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14566. */
  14567. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14568. // CustomIdleFeeAfterStop
  14569. /*
  14570. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14573. */
  14574. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14575. // TimeOffset
  14576. /*
  14577. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  14580. */
  14581. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14582. // NextTimeOffsetTransitionDateTime
  14583. /*
  14584. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14586. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  14587. */
  14588. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14589. // TimeOffsetNextTransition
  14590. /*
  14591. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14592. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14593. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  14594. */
  14595. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14596. // SystemUptimeSec
  14597. /*
  14598. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14600. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14601. */
  14602. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14603. // FreeVend
  14604. /*
  14605. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14607. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14608. */
  14609. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14610. // OcppServer
  14611. /*
  14612. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14613. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14615. */
  14616. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14617. // MaintainServer
  14618. /*
  14619. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14622. */
  14623. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14624. // StatusNotificationPeriodically
  14625. /*
  14626. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14628. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14629. */
  14630. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14631. // StatusNotificationInterval
  14632. /*
  14633. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14636. */
  14637. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14638. // ConfigurationVersion
  14639. /*
  14640. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14643. */
  14644. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14645. //* Local Auth List Management Profile*/
  14646. //LocalAuthListEnabled
  14647. /*
  14648. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14651. */
  14652. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14653. //LocalAuthListMaxLength
  14654. /*
  14655. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14658. */
  14659. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14660. //SendLocalListMaxLength
  14661. /*
  14662. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14663. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14664. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14665. */
  14666. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14667. //ReserveConnectorZeroSupported
  14668. /*
  14669. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14672. */
  14673. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14674. //* Smart Charging Profile */
  14675. //ChargeProfileMaxStackLevel
  14676. /*
  14677. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14680. */
  14681. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14682. // ChargingScheduleAllowedChargingRateUnit
  14683. /*
  14684. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14687. */
  14688. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14689. // ChargingScheduleMaxPeriods
  14690. /*
  14691. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14693. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14694. */
  14695. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14696. // ConnectorSwitch3to1PhaseSupported
  14697. /*
  14698. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14699. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14701. */
  14702. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14703. // MaxChargingProfilesInstalled
  14704. /*
  14705. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14708. */
  14709. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14710. fclose(outfile);
  14711. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14712. }
  14713. void getKeyValue(char *keyReq)
  14714. {
  14715. int isEmpty = FALSE;
  14716. int isKnowKey = FALSE;
  14717. DEBUG_INFO("keyReq = %s\n", keyReq);
  14718. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14719. isEmpty = TRUE;
  14720. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14721. {
  14722. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14724. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14725. {
  14726. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14727. }
  14728. else
  14729. {
  14730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14731. }
  14732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14733. isKnowKey = TRUE;
  14734. }
  14735. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14736. {
  14737. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14739. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14740. {
  14741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14742. }
  14743. else
  14744. {
  14745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14746. }
  14747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14748. isKnowKey = TRUE;
  14749. }
  14750. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14751. {
  14752. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14754. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14755. {
  14756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14757. }
  14758. else
  14759. {
  14760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14761. }
  14762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14763. isKnowKey = TRUE;
  14764. }
  14765. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14766. {
  14767. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14769. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14770. {
  14771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14772. }
  14773. else
  14774. {
  14775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14776. }
  14777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14778. isKnowKey = TRUE;
  14779. }
  14780. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14781. {
  14782. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14784. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14785. {
  14786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14787. }
  14788. else
  14789. {
  14790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14791. }
  14792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14793. isKnowKey = TRUE;
  14794. }
  14795. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14796. {
  14797. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14799. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14800. {
  14801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14802. }
  14803. else
  14804. {
  14805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14806. }
  14807. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14808. isKnowKey = TRUE;
  14809. }
  14810. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14811. {
  14812. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14813. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14814. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14815. {
  14816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14817. }
  14818. else
  14819. {
  14820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14821. }
  14822. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14823. isKnowKey = TRUE;
  14824. }
  14825. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14826. {
  14827. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14829. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14830. {
  14831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14832. }
  14833. else
  14834. {
  14835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14836. }
  14837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14838. isKnowKey = TRUE;
  14839. }
  14840. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14841. {
  14842. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14844. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14845. {
  14846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14847. }
  14848. else
  14849. {
  14850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14851. }
  14852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14853. isKnowKey = TRUE;
  14854. }
  14855. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14856. {
  14857. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14859. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14860. {
  14861. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14862. }
  14863. else
  14864. {
  14865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14866. }
  14867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14868. isKnowKey = TRUE;
  14869. }
  14870. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14871. {
  14872. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14874. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14875. {
  14876. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14877. }
  14878. else
  14879. {
  14880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14881. }
  14882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14883. isKnowKey = TRUE;
  14884. }
  14885. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14886. {
  14887. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14889. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14890. {
  14891. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14892. }
  14893. else
  14894. {
  14895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14896. }
  14897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14898. isKnowKey = TRUE;
  14899. }
  14900. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14901. {
  14902. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14904. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14905. {
  14906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14907. }
  14908. else
  14909. {
  14910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14911. }
  14912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14913. isKnowKey = TRUE;
  14914. }
  14915. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14916. {
  14917. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14919. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14920. {
  14921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14922. }
  14923. else
  14924. {
  14925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14926. }
  14927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14928. isKnowKey = TRUE;
  14929. }
  14930. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14931. {
  14932. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14934. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14935. {
  14936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14937. }
  14938. else
  14939. {
  14940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14941. }
  14942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14943. isKnowKey = TRUE;
  14944. }
  14945. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14946. {
  14947. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14949. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14950. {
  14951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14952. }
  14953. else
  14954. {
  14955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14956. }
  14957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14958. isKnowKey = TRUE;
  14959. }
  14960. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14961. {
  14962. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14964. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14965. {
  14966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14967. }
  14968. else
  14969. {
  14970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14971. }
  14972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14973. isKnowKey = TRUE;
  14974. }
  14975. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14976. {
  14977. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14979. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14980. {
  14981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14982. }
  14983. else
  14984. {
  14985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14986. }
  14987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  14988. isKnowKey = TRUE;
  14989. }
  14990. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14991. {
  14992. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14993. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14994. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14995. {
  14996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14997. }
  14998. else
  14999. {
  15000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15001. }
  15002. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15004. isKnowKey = TRUE;
  15005. }
  15006. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15007. {
  15008. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15010. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15011. {
  15012. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15013. }
  15014. else
  15015. {
  15016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15017. }
  15018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15019. isKnowKey = TRUE;
  15020. }
  15021. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15022. {
  15023. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15025. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15026. {
  15027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15028. }
  15029. else
  15030. {
  15031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15032. }
  15033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15034. isKnowKey = TRUE;
  15035. }
  15036. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15037. {
  15038. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15040. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15041. {
  15042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15043. }
  15044. else
  15045. {
  15046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15047. }
  15048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15049. isKnowKey = TRUE;
  15050. }
  15051. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15052. {
  15053. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15055. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15056. {
  15057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15058. }
  15059. else
  15060. {
  15061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15062. }
  15063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15064. isKnowKey = TRUE;
  15065. }
  15066. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15067. {
  15068. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15070. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15071. {
  15072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15073. }
  15074. else
  15075. {
  15076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15077. }
  15078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15079. isKnowKey = TRUE;
  15080. }
  15081. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15082. {
  15083. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15085. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15086. {
  15087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15088. }
  15089. else
  15090. {
  15091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15092. }
  15093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15094. isKnowKey = TRUE;
  15095. }
  15096. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15097. {
  15098. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15099. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15100. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15101. {
  15102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15103. }
  15104. else
  15105. {
  15106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15107. }
  15108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15109. isKnowKey = TRUE;
  15110. }
  15111. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15112. {
  15113. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15115. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15116. {
  15117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15118. }
  15119. else
  15120. {
  15121. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15122. }
  15123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15124. isKnowKey = TRUE;
  15125. }
  15126. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15127. {
  15128. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15129. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15130. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15131. {
  15132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15133. }
  15134. else
  15135. {
  15136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15137. }
  15138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15139. isKnowKey = TRUE;
  15140. }
  15141. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15142. {
  15143. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15145. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15146. {
  15147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15148. }
  15149. else
  15150. {
  15151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15152. }
  15153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15154. isKnowKey = TRUE;
  15155. }
  15156. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15157. {
  15158. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15160. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15161. {
  15162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15163. }
  15164. else
  15165. {
  15166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15167. }
  15168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15169. isKnowKey = TRUE;
  15170. }
  15171. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15172. {
  15173. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15175. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15176. {
  15177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15178. }
  15179. else
  15180. {
  15181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15182. }
  15183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15184. isKnowKey = TRUE;
  15185. }
  15186. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15187. {
  15188. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15190. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15191. {
  15192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15193. }
  15194. else
  15195. {
  15196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15197. }
  15198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15199. isKnowKey = TRUE;
  15200. }
  15201. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15202. {
  15203. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15205. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15206. {
  15207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15208. }
  15209. else
  15210. {
  15211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15212. }
  15213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15214. isKnowKey = TRUE;
  15215. }
  15216. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15217. {
  15218. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15220. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15221. {
  15222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15223. }
  15224. else
  15225. {
  15226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15227. }
  15228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15229. isKnowKey = TRUE;
  15230. }
  15231. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15232. {
  15233. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15235. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15236. {
  15237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15238. }
  15239. else
  15240. {
  15241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15242. }
  15243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15244. isKnowKey = TRUE;
  15245. }
  15246. /*
  15247. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15248. {
  15249. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15251. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15252. {
  15253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15254. }
  15255. else
  15256. {
  15257. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15258. }
  15259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15260. isKnowKey = TRUE;
  15261. }*/
  15262. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15263. {
  15264. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15266. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15267. {
  15268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15269. }
  15270. else
  15271. {
  15272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15273. }
  15274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15275. isKnowKey = TRUE;
  15276. }
  15277. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15278. {
  15279. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15281. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15282. {
  15283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15284. }
  15285. else
  15286. {
  15287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15288. }
  15289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15290. isKnowKey = TRUE;
  15291. }
  15292. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15293. {
  15294. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15296. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15297. {
  15298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15299. }
  15300. else
  15301. {
  15302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15303. }
  15304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15305. isKnowKey = TRUE;
  15306. }
  15307. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15308. {
  15309. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15311. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15312. {
  15313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15314. }
  15315. else
  15316. {
  15317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15318. }
  15319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15320. isKnowKey = TRUE;
  15321. }
  15322. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  15323. {
  15324. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  15325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  15326. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15327. {
  15328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  15329. }
  15330. else
  15331. {
  15332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  15333. }
  15334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  15335. isKnowKey = TRUE;
  15336. }
  15337. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  15338. {
  15339. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  15340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  15341. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15342. {
  15343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  15344. }
  15345. else
  15346. {
  15347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  15348. }
  15349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  15350. isKnowKey = TRUE;
  15351. }
  15352. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  15353. {
  15354. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  15355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  15356. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15357. {
  15358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  15359. }
  15360. else
  15361. {
  15362. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  15363. }
  15364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  15365. isKnowKey = TRUE;
  15366. }
  15367. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15368. {
  15369. struct sysinfo s_info;
  15370. int error = sysinfo(&s_info);
  15371. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15373. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15374. {
  15375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15376. }
  15377. else
  15378. {
  15379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15380. }
  15381. if(error != 0)
  15382. {
  15383. DEBUG_WARN("System uptime get error: %d\n", error);
  15384. }
  15385. else
  15386. {
  15387. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15388. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15389. }
  15390. isKnowKey = TRUE;
  15391. }
  15392. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15393. {
  15394. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15396. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15397. {
  15398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15399. }
  15400. else
  15401. {
  15402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15403. }
  15404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  15405. isKnowKey = TRUE;
  15406. }
  15407. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15408. {
  15409. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15411. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15412. {
  15413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15414. }
  15415. else
  15416. {
  15417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15418. }
  15419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15420. isKnowKey = TRUE;
  15421. }
  15422. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15423. {
  15424. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15426. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15427. {
  15428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15429. }
  15430. else
  15431. {
  15432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15433. }
  15434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15435. isKnowKey = TRUE;
  15436. }
  15437. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15438. {
  15439. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15441. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15442. {
  15443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15444. }
  15445. else
  15446. {
  15447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15448. }
  15449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15450. isKnowKey = TRUE;
  15451. }
  15452. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15453. {
  15454. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15456. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15457. {
  15458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15459. }
  15460. else
  15461. {
  15462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15463. }
  15464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15465. isKnowKey = TRUE;
  15466. }
  15467. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15468. {
  15469. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15471. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15472. {
  15473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15474. }
  15475. else
  15476. {
  15477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15478. }
  15479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15480. isKnowKey = TRUE;
  15481. }
  15482. #if 1
  15483. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15484. {
  15485. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15487. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15488. {
  15489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15490. }
  15491. else
  15492. {
  15493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15494. }
  15495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15496. isKnowKey = TRUE;
  15497. }
  15498. #endif
  15499. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15500. {
  15501. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15503. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15504. {
  15505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15506. }
  15507. else
  15508. {
  15509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15510. }
  15511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15512. isKnowKey = TRUE;
  15513. }
  15514. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15515. {
  15516. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15518. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15519. {
  15520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15521. }
  15522. else
  15523. {
  15524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15525. }
  15526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15527. isKnowKey = TRUE;
  15528. }
  15529. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15530. {
  15531. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15533. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15534. {
  15535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15536. }
  15537. else
  15538. {
  15539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15540. }
  15541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15542. isKnowKey = TRUE;
  15543. }
  15544. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15545. {
  15546. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15548. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15549. {
  15550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15551. }
  15552. else
  15553. {
  15554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15555. }
  15556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15557. isKnowKey = TRUE;
  15558. }
  15559. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15560. {
  15561. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15563. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15564. {
  15565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15566. }
  15567. else
  15568. {
  15569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15570. }
  15571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15572. isKnowKey = TRUE;
  15573. }
  15574. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15575. {
  15576. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15578. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15579. {
  15580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15581. }
  15582. else
  15583. {
  15584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15585. }
  15586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15587. isKnowKey = TRUE;
  15588. }
  15589. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15590. {
  15591. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15593. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15594. {
  15595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15596. }
  15597. else
  15598. {
  15599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15600. }
  15601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15602. isKnowKey = TRUE;
  15603. }
  15604. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15605. {
  15606. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15608. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15609. {
  15610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15611. }
  15612. else
  15613. {
  15614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15615. }
  15616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15617. isKnowKey = TRUE;
  15618. }
  15619. //=========================================================
  15620. if(!isEmpty && !isKnowKey)
  15621. {
  15622. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15623. strcpy(unknownkey[UnknownKeynum], keyReq);
  15624. UnknownKeynum = UnknownKeynum + 1;
  15625. }
  15626. }
  15627. void processUnkownKey(void)
  15628. {
  15629. DEBUG_INFO("processUnkownKey...\n");
  15630. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15631. for(int index=0; index < UnknownKeynum; index++)
  15632. {
  15633. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15634. {
  15635. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15636. }
  15637. }
  15638. }
  15639. int setKeyValue(char *key, char *value)
  15640. {
  15641. int isSuccess = NotSupported;
  15642. int check_ascii=0;
  15643. char str[501]={0};
  15644. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15645. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15646. {
  15647. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15648. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15649. {
  15650. strcpy(str, (const char*)value);
  15651. for(int i = 0; str[i]; i++){
  15652. str[i] = tolower(str[i]);
  15653. }
  15654. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15655. isSuccess = ConfigurationStatus_Accepted;
  15656. }
  15657. else
  15658. {
  15659. isSuccess = ConfigurationStatus_Rejected;
  15660. }
  15661. }
  15662. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15663. {
  15664. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15665. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15666. {
  15667. strcpy(str, (const char*)value);
  15668. for(int i = 0; str[i]; i++){
  15669. str[i] = tolower(str[i]);
  15670. }
  15671. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15672. isSuccess = ConfigurationStatus_Accepted;
  15673. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  15674. }
  15675. else
  15676. {
  15677. isSuccess = ConfigurationStatus_Rejected;
  15678. }
  15679. }
  15680. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15681. {
  15682. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15683. {
  15684. strcpy(str, (const char*)value);
  15685. for(int i = 0; str[i]; i++)
  15686. {
  15687. str[i] = tolower(str[i]);
  15688. }
  15689. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15690. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15691. isSuccess = ConfigurationStatus_Accepted;
  15692. }
  15693. else
  15694. {
  15695. isSuccess = ConfigurationStatus_Rejected;
  15696. }
  15697. }
  15698. if(strcmp(key, "BlinkRepeat") == 0)
  15699. {
  15700. //Charger.BlinkRepeat = Integer.parseInt(value);
  15701. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15702. {
  15703. check_ascii = value[0];
  15704. if( (check_ascii < 48) || (check_ascii > 57) )
  15705. {
  15706. isSuccess = ConfigurationStatus_Rejected;
  15707. }
  15708. else
  15709. {
  15710. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15711. isSuccess = ConfigurationStatus_Accepted;
  15712. }
  15713. }
  15714. else
  15715. {
  15716. isSuccess = ConfigurationStatus_Rejected;
  15717. }
  15718. }
  15719. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15720. {
  15721. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15722. {
  15723. check_ascii = value[0];
  15724. if( (check_ascii < 48) || (check_ascii > 57) )
  15725. {
  15726. isSuccess = ConfigurationStatus_Rejected;
  15727. }
  15728. else
  15729. {
  15730. if((atoi(value) == 0) || (atoi(value) >= 5))
  15731. {
  15732. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15733. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15734. isSuccess = ConfigurationStatus_Accepted;
  15735. }
  15736. else
  15737. isSuccess = ConfigurationStatus_Rejected;
  15738. }
  15739. }
  15740. else
  15741. {
  15742. isSuccess = ConfigurationStatus_Rejected;
  15743. }
  15744. }
  15745. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15746. {
  15747. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15748. {
  15749. check_ascii = value[0];
  15750. if( (check_ascii < 48) || (check_ascii > 57) )
  15751. {
  15752. isSuccess = ConfigurationStatus_Rejected;
  15753. }
  15754. else
  15755. {
  15756. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15757. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15758. isSuccess = ConfigurationStatus_Accepted;
  15759. }
  15760. }
  15761. else
  15762. {
  15763. isSuccess = ConfigurationStatus_Rejected;
  15764. }
  15765. }
  15766. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15767. {
  15768. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15769. {
  15770. check_ascii = value[0];
  15771. if( (check_ascii < 48) || (check_ascii > 57) )
  15772. {
  15773. isSuccess = ConfigurationStatus_Rejected;
  15774. }
  15775. else
  15776. {
  15777. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15778. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15779. isSuccess = ConfigurationStatus_Accepted;
  15780. }
  15781. }
  15782. else
  15783. {
  15784. isSuccess = ConfigurationStatus_Rejected;
  15785. }
  15786. }
  15787. if(strcmp(key, "HeartbeatInterval") == 0)
  15788. {
  15789. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15790. {
  15791. check_ascii = value[0];
  15792. if( (check_ascii < 48) || (check_ascii > 57) )
  15793. {
  15794. isSuccess = ConfigurationStatus_Rejected;
  15795. }
  15796. else
  15797. {
  15798. if((atoi(value) == 0) || (atoi(value) >= 10))
  15799. {
  15800. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15801. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15802. HeartBeatWaitTime = atoi(value);
  15803. isSuccess = ConfigurationStatus_Accepted;
  15804. }
  15805. else
  15806. {
  15807. isSuccess = ConfigurationStatus_Rejected;
  15808. }
  15809. }
  15810. }
  15811. else
  15812. {
  15813. isSuccess = ConfigurationStatus_Rejected;
  15814. }
  15815. }
  15816. if(strcmp(key, "LightIntensity") == 0)
  15817. {
  15818. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15819. {
  15820. check_ascii = value[0];
  15821. if( (check_ascii < 48) || (check_ascii > 57) )
  15822. {
  15823. isSuccess = ConfigurationStatus_Rejected;
  15824. }
  15825. else
  15826. {
  15827. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15828. isSuccess = ConfigurationStatus_Accepted;
  15829. }
  15830. }
  15831. else
  15832. {
  15833. isSuccess = ConfigurationStatus_Rejected;
  15834. }
  15835. }
  15836. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15837. {
  15838. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15839. {
  15840. strcpy(str, (const char*)value);
  15841. for(int i = 0; str[i]; i++)
  15842. {
  15843. str[i] = tolower(str[i]);
  15844. }
  15845. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15846. isSuccess = ConfigurationStatus_Accepted;
  15847. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15848. }
  15849. else
  15850. {
  15851. isSuccess = ConfigurationStatus_Rejected;
  15852. }
  15853. }
  15854. if(strcmp(key, "LocalPreAuthorize") == 0)
  15855. {
  15856. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15857. {
  15858. strcpy(str, (const char*)value);
  15859. for(int i = 0; str[i]; i++)
  15860. {
  15861. str[i] = tolower(str[i]);
  15862. }
  15863. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15864. isSuccess = ConfigurationStatus_Accepted;
  15865. }
  15866. else
  15867. {
  15868. isSuccess = ConfigurationStatus_Rejected;
  15869. }
  15870. }
  15871. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15872. {
  15873. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15874. {
  15875. check_ascii = value[0];
  15876. if( (check_ascii < 48) || (check_ascii > 57) )
  15877. {
  15878. isSuccess = ConfigurationStatus_Rejected;
  15879. }
  15880. else
  15881. {
  15882. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15883. isSuccess = ConfigurationStatus_Accepted;
  15884. }
  15885. }
  15886. else
  15887. {
  15888. isSuccess = ConfigurationStatus_Rejected;
  15889. }
  15890. }
  15891. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15892. {
  15893. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15894. {
  15895. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15896. isSuccess = ConfigurationStatus_Accepted;
  15897. }
  15898. else
  15899. {
  15900. isSuccess = ConfigurationStatus_Rejected;
  15901. }
  15902. }
  15903. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15904. {
  15905. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15906. {
  15907. check_ascii = value[0];
  15908. if( (check_ascii < 48) || (check_ascii > 57) )
  15909. {
  15910. isSuccess = ConfigurationStatus_Rejected;
  15911. }
  15912. else
  15913. {
  15914. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15915. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15916. isSuccess = ConfigurationStatus_Accepted;
  15917. }
  15918. }
  15919. else
  15920. {
  15921. isSuccess = ConfigurationStatus_Rejected;
  15922. }
  15923. }
  15924. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15925. {
  15926. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15927. {
  15928. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15929. isSuccess = ConfigurationStatus_Accepted;
  15930. }
  15931. else
  15932. {
  15933. isSuccess = ConfigurationStatus_Rejected;
  15934. }
  15935. }
  15936. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15937. {
  15938. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15939. {
  15940. check_ascii = value[0];
  15941. if( (check_ascii < 48) || (check_ascii > 57) )
  15942. {
  15943. isSuccess = ConfigurationStatus_Rejected;
  15944. }
  15945. else
  15946. {
  15947. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15948. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15949. isSuccess = ConfigurationStatus_Accepted;
  15950. }
  15951. }
  15952. else
  15953. {
  15954. isSuccess = ConfigurationStatus_Rejected;
  15955. }
  15956. }
  15957. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15958. {
  15959. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15960. {
  15961. check_ascii = value[0];
  15962. if( (check_ascii < 48) || (check_ascii > 57) )
  15963. {
  15964. isSuccess = ConfigurationStatus_Rejected;
  15965. }
  15966. else
  15967. {
  15968. if((atoi(value) == 0) || (atoi(value) >= 3))
  15969. {
  15970. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15971. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15972. isSuccess = ConfigurationStatus_Accepted;
  15973. }
  15974. else
  15975. {
  15976. isSuccess = ConfigurationStatus_Rejected;
  15977. }
  15978. }
  15979. }
  15980. else
  15981. {
  15982. isSuccess = ConfigurationStatus_Rejected;
  15983. }
  15984. }
  15985. if(strcmp(key, "MinimumStatusDuration") == 0)
  15986. {
  15987. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15988. {
  15989. check_ascii = value[0];
  15990. if( (check_ascii < 48) || (check_ascii > 57) )
  15991. {
  15992. isSuccess = ConfigurationStatus_Rejected;
  15993. }
  15994. else
  15995. {
  15996. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15997. {
  15998. isSuccess = ConfigurationStatus_Rejected;
  15999. }
  16000. else
  16001. {
  16002. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16003. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16004. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16005. isSuccess = ConfigurationStatus_Accepted;
  16006. }
  16007. }
  16008. }
  16009. else
  16010. {
  16011. isSuccess = ConfigurationStatus_Rejected;
  16012. }
  16013. }
  16014. if(strcmp(key, "NumberOfConnectors") == 0)
  16015. {
  16016. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16017. {
  16018. check_ascii = value[0];
  16019. if( (check_ascii < 48) || (check_ascii > 57) )
  16020. {
  16021. isSuccess = ConfigurationStatus_Rejected;
  16022. }
  16023. else
  16024. {
  16025. //Charger.ResetRetries = Integer.parseInt(value);
  16026. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16027. isSuccess = ConfigurationStatus_Accepted;
  16028. }
  16029. }
  16030. else
  16031. {
  16032. isSuccess = ConfigurationStatus_Rejected;
  16033. }
  16034. }
  16035. if(strcmp(key, "ResetRetries") == 0)
  16036. {
  16037. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16038. {
  16039. check_ascii = value[0];
  16040. if( (check_ascii < 48) || (check_ascii > 57) )
  16041. {
  16042. isSuccess = ConfigurationStatus_Rejected;
  16043. }
  16044. else
  16045. {
  16046. //Charger.ResetRetries = Integer.parseInt(value);
  16047. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16048. isSuccess = ConfigurationStatus_Accepted;
  16049. }
  16050. }
  16051. else
  16052. {
  16053. isSuccess = ConfigurationStatus_Rejected;
  16054. }
  16055. }
  16056. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16057. {
  16058. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16059. {
  16060. strcpy(str, (const char*)value);
  16061. for(int i = 0; str[i]; i++)
  16062. {
  16063. str[i] = tolower(str[i]);
  16064. }
  16065. if(strcmp(str, "notapplicable")== 0)
  16066. {
  16067. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16068. isSuccess = ConfigurationStatus_Accepted;
  16069. }
  16070. else if(strcmp(str, "unknown")== 0)
  16071. {
  16072. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16073. isSuccess = ConfigurationStatus_Accepted;
  16074. }
  16075. else if(strcmp(str, "rst")== 0)
  16076. {
  16077. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16078. isSuccess = ConfigurationStatus_Accepted;
  16079. }
  16080. else if(strcmp(str, "rts")== 0)
  16081. {
  16082. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16083. isSuccess = ConfigurationStatus_Accepted;
  16084. }
  16085. else if(strcmp(str, "srt")== 0)
  16086. {
  16087. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16088. isSuccess = ConfigurationStatus_Accepted;
  16089. }
  16090. else if(strcmp(str, "str")== 0)
  16091. {
  16092. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16093. isSuccess = ConfigurationStatus_Accepted;
  16094. }
  16095. else if(strcmp(str, "trs")== 0)
  16096. {
  16097. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16098. isSuccess = ConfigurationStatus_Accepted;
  16099. }
  16100. else if(strcmp(str, "tsr")== 0)
  16101. {
  16102. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16103. isSuccess = ConfigurationStatus_Accepted;
  16104. }
  16105. else
  16106. {
  16107. isSuccess = ConfigurationStatus_Rejected;
  16108. }
  16109. }
  16110. else
  16111. {
  16112. isSuccess = ConfigurationStatus_Rejected;
  16113. }
  16114. }
  16115. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16116. {
  16117. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16118. {
  16119. check_ascii = value[0];
  16120. if( (check_ascii < 48) || (check_ascii > 57) )
  16121. {
  16122. isSuccess = ConfigurationStatus_Rejected;
  16123. }
  16124. else
  16125. {
  16126. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16127. isSuccess = ConfigurationStatus_Accepted;
  16128. }
  16129. }
  16130. else
  16131. {
  16132. isSuccess = ConfigurationStatus_Rejected;
  16133. }
  16134. }
  16135. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16136. {
  16137. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16138. {
  16139. strcpy(str, (const char*)value);
  16140. for(int i = 0; str[i]; i++)
  16141. {
  16142. str[i] = tolower(str[i]);
  16143. }
  16144. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16145. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16146. isSuccess = ConfigurationStatus_Accepted;
  16147. }
  16148. else
  16149. {
  16150. isSuccess = ConfigurationStatus_Rejected;
  16151. }
  16152. }
  16153. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16154. {
  16155. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16156. {
  16157. strcpy(str, (const char*)value);
  16158. for(int i = 0; str[i]; i++)
  16159. {
  16160. str[i] = tolower(str[i]);
  16161. }
  16162. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16163. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16164. isSuccess = ConfigurationStatus_Accepted;
  16165. }
  16166. else
  16167. {
  16168. isSuccess = ConfigurationStatus_Rejected;
  16169. }
  16170. }
  16171. if(strcmp(key, "StopTxnAlignedData") == 0)
  16172. {
  16173. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16174. {
  16175. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16176. isSuccess = ConfigurationStatus_Accepted;
  16177. }
  16178. else
  16179. {
  16180. isSuccess = ConfigurationStatus_Rejected;
  16181. }
  16182. }
  16183. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16184. {
  16185. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16186. {
  16187. check_ascii = value[0];
  16188. if( (check_ascii < 48) || (check_ascii > 57) )
  16189. {
  16190. isSuccess = ConfigurationStatus_Rejected;
  16191. }
  16192. else
  16193. {
  16194. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16195. isSuccess = ConfigurationStatus_Accepted;
  16196. }
  16197. }
  16198. else
  16199. {
  16200. isSuccess = ConfigurationStatus_Rejected;
  16201. }
  16202. }
  16203. if(strcmp(key, "StopTxnSampledData") == 0)
  16204. {
  16205. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16206. {
  16207. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16208. isSuccess = ConfigurationStatus_Accepted;
  16209. }
  16210. else
  16211. {
  16212. isSuccess = ConfigurationStatus_Rejected;
  16213. }
  16214. }
  16215. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16216. {
  16217. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16218. {
  16219. check_ascii = value[0];
  16220. if( (check_ascii < 48) || (check_ascii > 57) )
  16221. {
  16222. isSuccess = ConfigurationStatus_Rejected;
  16223. }
  16224. else
  16225. {
  16226. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16227. isSuccess = ConfigurationStatus_Accepted;
  16228. }
  16229. }
  16230. else
  16231. {
  16232. isSuccess = ConfigurationStatus_Rejected;
  16233. }
  16234. }
  16235. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16236. {
  16237. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16238. {
  16239. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16240. isSuccess = ConfigurationStatus_Accepted;
  16241. }
  16242. else
  16243. {
  16244. isSuccess = ConfigurationStatus_Rejected;
  16245. }
  16246. }
  16247. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16248. {
  16249. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16250. {
  16251. check_ascii = value[0];
  16252. if( (check_ascii < 48) || (check_ascii > 57) )
  16253. {
  16254. isSuccess = ConfigurationStatus_Rejected;
  16255. }
  16256. else
  16257. {
  16258. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16259. isSuccess = ConfigurationStatus_Accepted;
  16260. }
  16261. }
  16262. else
  16263. {
  16264. isSuccess = ConfigurationStatus_Rejected;
  16265. }
  16266. }
  16267. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16268. {
  16269. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16270. {
  16271. check_ascii = value[0];
  16272. if( (check_ascii < 48) || (check_ascii > 57) )
  16273. {
  16274. isSuccess = ConfigurationStatus_Rejected;
  16275. }
  16276. else
  16277. {
  16278. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16279. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16280. TransactionMessageAttemptsValue = atoi(value);
  16281. isSuccess = ConfigurationStatus_Accepted;
  16282. }
  16283. }
  16284. else
  16285. {
  16286. isSuccess = ConfigurationStatus_Rejected;
  16287. }
  16288. }
  16289. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16290. {
  16291. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16292. {
  16293. check_ascii = value[0];
  16294. if( (check_ascii < 48) || (check_ascii > 57) )
  16295. {
  16296. isSuccess = ConfigurationStatus_Rejected;
  16297. }
  16298. else
  16299. {
  16300. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16301. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16302. TransactionMessageRetryIntervalValue = atoi(value);
  16303. isSuccess = ConfigurationStatus_Accepted;
  16304. }
  16305. }
  16306. else
  16307. {
  16308. isSuccess = ConfigurationStatus_Rejected;
  16309. }
  16310. }
  16311. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16312. {
  16313. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16314. {
  16315. strcpy(str, (const char*)value);
  16316. for(int i = 0; str[i]; i++)
  16317. {
  16318. str[i] = tolower(str[i]);
  16319. }
  16320. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16321. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16322. isSuccess = ConfigurationStatus_Accepted;
  16323. }
  16324. else
  16325. {
  16326. isSuccess = ConfigurationStatus_Rejected;
  16327. }
  16328. }
  16329. if(strcmp(key, "WebSocketPingInterval") == 0)
  16330. {
  16331. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16332. {
  16333. check_ascii = value[0];
  16334. if( (check_ascii < 48) || (check_ascii > 57) )
  16335. {
  16336. isSuccess = ConfigurationStatus_Rejected;
  16337. }
  16338. else
  16339. {
  16340. if((atoi(value) == 0) || (atoi(value) >= 10))
  16341. {
  16342. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16343. isSuccess = ConfigurationStatus_Accepted;
  16344. }
  16345. else
  16346. isSuccess = ConfigurationStatus_Rejected;
  16347. }
  16348. }
  16349. else
  16350. {
  16351. isSuccess = ConfigurationStatus_Rejected;
  16352. }
  16353. }
  16354. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16355. {
  16356. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16357. {
  16358. strcpy(str, (const char*)value);
  16359. for(int i = 0; str[i]; i++)
  16360. {
  16361. str[i] = tolower(str[i]);
  16362. }
  16363. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16364. isSuccess = ConfigurationStatus_Accepted;
  16365. }
  16366. else
  16367. {
  16368. isSuccess = ConfigurationStatus_Rejected;
  16369. }
  16370. }
  16371. if(strcmp(key, "AuthorizationKey") == 0)
  16372. {
  16373. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16374. {
  16375. strcpy(str, (const char*)value);
  16376. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16377. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16378. isSuccess = ConfigurationStatus_Accepted;
  16379. }
  16380. else
  16381. {
  16382. isSuccess = ConfigurationStatus_Rejected;
  16383. }
  16384. }
  16385. if(strcmp(key, "SecurityProfile") == 0)
  16386. {
  16387. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16388. {
  16389. check_ascii = value[0];
  16390. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16391. {
  16392. isSuccess = ConfigurationStatus_Rejected;
  16393. }
  16394. else if(check_ascii == 0x33)
  16395. {
  16396. isSuccess = NotSupported;
  16397. }
  16398. else
  16399. {
  16400. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16401. {
  16402. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16403. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  16404. isSuccess = ConfigurationStatus_Accepted;
  16405. }
  16406. else
  16407. isSuccess = ConfigurationStatus_Rejected;
  16408. }
  16409. }
  16410. else
  16411. {
  16412. isSuccess = ConfigurationStatus_Rejected;
  16413. }
  16414. }
  16415. if(strcmp(key, "DefaultPrice") == 0)
  16416. {
  16417. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16418. {
  16419. strcpy(str, (const char*)value);
  16420. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16421. isSuccess = ConfigurationStatus_Accepted;
  16422. }
  16423. else
  16424. {
  16425. isSuccess = ConfigurationStatus_Rejected;
  16426. }
  16427. }
  16428. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16429. {
  16430. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16431. {
  16432. strcpy(str, (const char*)value);
  16433. for(int i = 0; str[i]; i++)
  16434. {
  16435. str[i] = tolower(str[i]);
  16436. }
  16437. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16438. isSuccess = ConfigurationStatus_Accepted;
  16439. }
  16440. else
  16441. {
  16442. isSuccess = ConfigurationStatus_Rejected;
  16443. }
  16444. }
  16445. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16446. {
  16447. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16448. {
  16449. strcpy(str, (const char*)value);
  16450. for(int i = 0; str[i]; i++)
  16451. {
  16452. str[i] = tolower(str[i]);
  16453. }
  16454. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16455. isSuccess = ConfigurationStatus_Accepted;
  16456. }
  16457. else
  16458. {
  16459. isSuccess = ConfigurationStatus_Rejected;
  16460. }
  16461. }
  16462. if(strcmp(key, "TimeOffset") == 0)
  16463. {
  16464. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16465. {
  16466. strcpy(str, (const char*)value);
  16467. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  16468. isSuccess = ConfigurationStatus_Accepted;
  16469. }
  16470. else
  16471. {
  16472. isSuccess = ConfigurationStatus_Rejected;
  16473. }
  16474. }
  16475. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  16476. {
  16477. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  16478. {
  16479. strcpy(str, (const char*)value);
  16480. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  16481. isSuccess = ConfigurationStatus_Accepted;
  16482. }
  16483. else
  16484. {
  16485. isSuccess = ConfigurationStatus_Rejected;
  16486. }
  16487. }
  16488. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  16489. {
  16490. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  16491. {
  16492. strcpy(str, (const char*)value);
  16493. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  16494. isSuccess = ConfigurationStatus_Accepted;
  16495. }
  16496. else
  16497. {
  16498. isSuccess = ConfigurationStatus_Rejected;
  16499. }
  16500. }
  16501. if(strcmp(key, "SystemUptimeSec") == 0)
  16502. {
  16503. isSuccess = NotSupported;
  16504. }
  16505. if(strcmp(key, "FreeVend") == 0)
  16506. {
  16507. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16508. {
  16509. strcpy(str, (const char*)value);
  16510. for(int i = 0; str[i]; i++)
  16511. {
  16512. str[i] = tolower(str[i]);
  16513. }
  16514. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16515. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16516. isSuccess = ConfigurationStatus_Accepted;
  16517. }
  16518. else
  16519. {
  16520. isSuccess = ConfigurationStatus_Rejected;
  16521. }
  16522. }
  16523. if(strcmp(key, "OcppServer") == 0)
  16524. {
  16525. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16526. {
  16527. strcpy(str, (const char*)value);
  16528. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16529. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16530. isSuccess = ConfigurationStatus_Accepted;
  16531. }
  16532. else
  16533. {
  16534. isSuccess = ConfigurationStatus_Rejected;
  16535. }
  16536. }
  16537. if(strcmp(key, "MaintainServer") == 0)
  16538. {
  16539. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16540. {
  16541. strcpy(str, (const char*)value);
  16542. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16543. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16544. isSuccess = ConfigurationStatus_Accepted;
  16545. }
  16546. else
  16547. {
  16548. isSuccess = ConfigurationStatus_Rejected;
  16549. }
  16550. }
  16551. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16552. {
  16553. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16554. {
  16555. strcpy(str, (const char*)value);
  16556. for(int i = 0; str[i]; i++)
  16557. {
  16558. str[i] = tolower(str[i]);
  16559. }
  16560. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16561. isSuccess = ConfigurationStatus_Accepted;
  16562. }
  16563. else
  16564. {
  16565. isSuccess = ConfigurationStatus_Rejected;
  16566. }
  16567. }
  16568. if(strcmp(key, "StatusNotificationInterval") == 0)
  16569. {
  16570. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16571. {
  16572. check_ascii = value[0];
  16573. if( (check_ascii < 48) || (check_ascii > 57) )
  16574. {
  16575. isSuccess = ConfigurationStatus_Rejected;
  16576. }
  16577. else
  16578. {
  16579. if((atoi(value) == 0) || (atoi(value) >= 10))
  16580. {
  16581. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16582. isSuccess = ConfigurationStatus_Accepted;
  16583. }
  16584. else
  16585. isSuccess = ConfigurationStatus_Rejected;
  16586. }
  16587. }
  16588. else
  16589. {
  16590. isSuccess = ConfigurationStatus_Rejected;
  16591. }
  16592. }
  16593. #if 0
  16594. //For OCPP Test Case
  16595. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16596. {
  16597. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16598. {
  16599. strcpy(str, (const char*)value);
  16600. for(int i = 0; str[i]; i++)
  16601. {
  16602. str[i] = tolower(str[i]);
  16603. }
  16604. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16605. isSuccess = ConfigurationStatus_Accepted;
  16606. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16607. }
  16608. else
  16609. {
  16610. isSuccess = ConfigurationStatus_Rejected;
  16611. }
  16612. }
  16613. #endif
  16614. #if 1
  16615. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16616. {
  16617. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16618. {
  16619. strcpy(str, (const char*)value);
  16620. for(int i = 0; str[i]; i++)
  16621. {
  16622. str[i] = tolower(str[i]);
  16623. }
  16624. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16625. isSuccess = ConfigurationStatus_Accepted;
  16626. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16627. }
  16628. else
  16629. {
  16630. isSuccess = ConfigurationStatus_Rejected;
  16631. }
  16632. }
  16633. #endif
  16634. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16635. {
  16636. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16637. {
  16638. check_ascii = value[0];
  16639. if( (check_ascii < 48) || (check_ascii > 57) )
  16640. {
  16641. isSuccess = ConfigurationStatus_Rejected;
  16642. }
  16643. else
  16644. {
  16645. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16646. isSuccess = ConfigurationStatus_Accepted;
  16647. }
  16648. }
  16649. else
  16650. {
  16651. isSuccess = ConfigurationStatus_Rejected;
  16652. }
  16653. }
  16654. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16655. {
  16656. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16657. {
  16658. check_ascii = value[0];
  16659. if( (check_ascii < 48) || (check_ascii > 57) )
  16660. {
  16661. isSuccess = ConfigurationStatus_Rejected;
  16662. }
  16663. else
  16664. {
  16665. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16666. isSuccess = ConfigurationStatus_Accepted;
  16667. }
  16668. }
  16669. else
  16670. {
  16671. isSuccess = ConfigurationStatus_Rejected;
  16672. }
  16673. }
  16674. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16675. {
  16676. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16677. {
  16678. strcpy(str, (const char*)value);
  16679. for(int i = 0; str[i]; i++)
  16680. {
  16681. str[i] = tolower(str[i]);
  16682. }
  16683. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16684. isSuccess = ConfigurationStatus_Accepted;
  16685. }
  16686. else
  16687. {
  16688. isSuccess = ConfigurationStatus_Rejected;
  16689. }
  16690. }
  16691. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16692. {
  16693. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16694. {
  16695. check_ascii = value[0];
  16696. if( (check_ascii < 48) || (check_ascii > 57) )
  16697. {
  16698. isSuccess = ConfigurationStatus_Rejected;
  16699. }
  16700. else
  16701. {
  16702. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16703. isSuccess = ConfigurationStatus_Accepted;
  16704. }
  16705. }
  16706. else
  16707. {
  16708. isSuccess = ConfigurationStatus_Rejected;
  16709. }
  16710. }
  16711. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16712. {
  16713. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16714. {
  16715. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16716. isSuccess = ConfigurationStatus_Accepted;
  16717. }
  16718. else
  16719. {
  16720. isSuccess = ConfigurationStatus_Rejected;
  16721. }
  16722. }
  16723. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16724. {
  16725. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16726. {
  16727. check_ascii = value[0];
  16728. if( (check_ascii < 48) || (check_ascii > 57) )
  16729. {
  16730. isSuccess = ConfigurationStatus_Rejected;
  16731. }
  16732. else
  16733. {
  16734. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16735. isSuccess = ConfigurationStatus_Accepted;
  16736. }
  16737. }
  16738. else
  16739. {
  16740. isSuccess = ConfigurationStatus_Rejected;
  16741. }
  16742. }
  16743. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16744. {
  16745. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16746. {
  16747. strcpy(str, (const char*)value);
  16748. for(int i = 0; str[i]; i++)
  16749. {
  16750. str[i] = tolower(str[i]);
  16751. }
  16752. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16753. isSuccess = ConfigurationStatus_Accepted;
  16754. }
  16755. else
  16756. {
  16757. isSuccess = ConfigurationStatus_Rejected;
  16758. }
  16759. }
  16760. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16761. {
  16762. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16763. {
  16764. check_ascii = value[0];
  16765. if( (check_ascii < 48) || (check_ascii > 57) )
  16766. {
  16767. isSuccess = ConfigurationStatus_Rejected;
  16768. }
  16769. else
  16770. {
  16771. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16772. isSuccess = ConfigurationStatus_Accepted;
  16773. }
  16774. }
  16775. else
  16776. {
  16777. isSuccess = ConfigurationStatus_Rejected;
  16778. }
  16779. }
  16780. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16781. return isSuccess;
  16782. }
  16783. int TransactionMessageAttemptsGet(void)
  16784. {
  16785. return TransactionMessageAttemptsValue;
  16786. }
  16787. int FirstHeartBeatResponse(void)
  16788. {
  16789. return FirstHeartBeat;
  16790. }
  16791. int TransactionMessageRetryIntervalGet(void)
  16792. {
  16793. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16794. }
  16795. int ReadHttpStatus(int sock)
  16796. {
  16797. //char c;
  16798. char buff[1024]="",*ptr=buff+1;
  16799. int bytes_received, status;
  16800. DEBUG_INFO("Begin Response ..\n");
  16801. while((bytes_received = recv(sock, ptr, 1, 0))){
  16802. if(bytes_received==-1){
  16803. perror("ReadHttpStatus");
  16804. exit(1);
  16805. }
  16806. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16807. ptr++;
  16808. }
  16809. *ptr=0;
  16810. ptr=buff+1;
  16811. sscanf(ptr,"%*s %d ", &status);
  16812. DEBUG_INFO("%s\n",ptr);
  16813. DEBUG_INFO("status=%d\n",status);
  16814. DEBUG_INFO("End Response ..\n");
  16815. return (bytes_received>0)?status:0;
  16816. }
  16817. //the only filed that it parsed is 'Content-Length'
  16818. int ParseHeader(int sock)
  16819. {
  16820. //char c;
  16821. char buff[1024]="",*ptr=buff+4;
  16822. int bytes_received;
  16823. DEBUG_INFO("Begin HEADER ..\n");
  16824. while((bytes_received = recv(sock, ptr, 1, 0))){
  16825. if(bytes_received==-1){
  16826. perror("Parse Header");
  16827. exit(1);
  16828. }
  16829. if(
  16830. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16831. (ptr[-1]=='\r') && (*ptr=='\n' )
  16832. ) break;
  16833. ptr++;
  16834. }
  16835. *ptr=0;
  16836. ptr=buff+4;
  16837. //printf("%s",ptr);
  16838. if(bytes_received){
  16839. ptr=strstr(ptr,"Content-Length:");
  16840. if(ptr){
  16841. sscanf(ptr,"%*s %d",&bytes_received);
  16842. }else
  16843. bytes_received=-1; //unknown size
  16844. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16845. }
  16846. DEBUG_INFO("End HEADER ..\n");
  16847. return bytes_received ;
  16848. }
  16849. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16850. {
  16851. int result = TRUE;
  16852. char rmFileCmd[100]={0};
  16853. char FilePath[100]={0};
  16854. char ftpbuf[200];
  16855. int systemresult;
  16856. sprintf(FilePath,"/mnt/%s",filename);
  16857. system("ping 8.8.8.8 &");
  16858. if((access(FilePath,F_OK))!=-1)
  16859. {
  16860. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16861. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16862. system(rmFileCmd);
  16863. }
  16864. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16865. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16866. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16867. systemresult = system(ftpbuf);
  16868. if(systemresult != 0)
  16869. {
  16870. DEBUG_INFO("http DownLoad error!\n");
  16871. result = FALSE;
  16872. }
  16873. system("pkill ping");
  16874. return result;
  16875. }
  16876. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16877. {
  16878. int result = TRUE;
  16879. char rmFileCmd[100]={0};
  16880. char FilePath[100]={0};
  16881. char ftpbuf[200];
  16882. int systemresult;
  16883. sprintf(FilePath,"/mnt/%s",filename);
  16884. system("ping 8.8.8.8 &");
  16885. if((access(FilePath,F_OK))!=-1)
  16886. {
  16887. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16888. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16889. system(rmFileCmd);
  16890. }
  16891. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16892. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16893. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16894. systemresult = system(ftpbuf);
  16895. if(systemresult != 0)
  16896. {
  16897. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16898. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16899. systemresult = system(ftpbuf);
  16900. if(systemresult != 0)
  16901. {
  16902. DEBUG_WARN("wget error!\n");
  16903. result = FALSE;
  16904. }
  16905. }
  16906. system("pkill ping");
  16907. return result;
  16908. }
  16909. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16910. {
  16911. char rmFileCmd[100]={0};
  16912. char FilePath[100]={0};
  16913. char buf[512];
  16914. int systemresult = 0;
  16915. //DEBUG_INFO("filename=%s\n",filename);
  16916. //DEBUG_INFO("url=%s\n",url);
  16917. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16918. if((access(FilePath,F_OK))!=-1)
  16919. {
  16920. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16921. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16922. system(rmFileCmd);
  16923. }
  16924. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16925. if(fp == NULL)
  16926. {
  16927. DEBUG_INFO("log is NULL\n");
  16928. return FALSE;
  16929. }
  16930. else
  16931. {
  16932. fprintf(fp, "%s\n", url);
  16933. fprintf(fp, "%s\n", filename);
  16934. fclose(fp);
  16935. }
  16936. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16937. if(phpFP == NULL)
  16938. {
  16939. DEBUG_INFO("PHP upload fail.\n");
  16940. return FALSE;
  16941. }
  16942. else
  16943. {
  16944. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16945. {
  16946. if(strstr(buf, "result") != NULL)
  16947. {
  16948. sscanf(buf, "result: %d", &systemresult);
  16949. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16950. }
  16951. }
  16952. pclose(phpFP);
  16953. }
  16954. if(systemresult != 1)
  16955. {
  16956. DEBUG_INFO("HTTP upload error!\n");
  16957. return FALSE;
  16958. }
  16959. return TRUE;
  16960. }
  16961. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16962. {
  16963. int result = FALSE;
  16964. char ftpbuf[200];
  16965. int systemresult;
  16966. /*
  16967. // Domaind name transfer to IP address
  16968. struct hostent* server;
  16969. char *IPbuffer;
  16970. server = gethostbyname(location);
  16971. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16972. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16973. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16974. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16975. systemresult = system(ftpbuf);
  16976. if(systemresult != 0)
  16977. {
  16978. DEBUG_INFO("ftpput error!\n");
  16979. }
  16980. else
  16981. {
  16982. result = TRUE;
  16983. DEBUG_INFO("ftpput OK!\n");
  16984. }
  16985. return result;
  16986. }
  16987. int GetOcppServerURL()
  16988. {
  16989. int result = FALSE;
  16990. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16991. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16992. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16993. struct yuarel url;
  16994. char urlStr[512];
  16995. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  16996. {
  16997. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  16998. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16999. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17000. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  17001. if(yuarel_parse(&url, urlStr) != -1)
  17002. {
  17003. sprintf(OcppProtocol, "%s", url.scheme);
  17004. sprintf(OcppHost, "%s", url.host);
  17005. if(url.path == NULL)
  17006. OcppTempPath[0] = '\0';
  17007. else
  17008. {
  17009. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  17010. {
  17011. sprintf(OcppTempPath, "%s/", url.path);
  17012. }
  17013. else
  17014. {
  17015. sprintf(OcppTempPath, "%s", url.path);
  17016. }
  17017. }
  17018. if(url.port == 0)
  17019. {
  17020. if(strcmp(OcppProtocol, "wss") == 0)
  17021. OcppPort = 443;
  17022. else
  17023. OcppPort = 80;
  17024. }
  17025. else
  17026. OcppPort = url.port;
  17027. result = TRUE;
  17028. }
  17029. }
  17030. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  17031. {
  17032. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  17033. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17034. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17035. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  17036. if(yuarel_parse(&url, urlStr) != -1)
  17037. {
  17038. sprintf(OcppProtocol, "%s", url.scheme);
  17039. sprintf(OcppHost, "%s", url.host);
  17040. if(url.path == NULL)
  17041. OcppTempPath[0] = '\0';
  17042. else
  17043. sprintf(OcppTempPath, "%s", url.path);
  17044. if(url.port == 0)
  17045. {
  17046. if(strcmp(OcppProtocol, "wss") == 0)
  17047. OcppPort = 443;
  17048. else
  17049. OcppPort = 80;
  17050. }
  17051. else
  17052. OcppPort = url.port;
  17053. result = TRUE;
  17054. }
  17055. }
  17056. else
  17057. {
  17058. strcpy(OcppHost,"");
  17059. }
  17060. return result;
  17061. }
  17062. int GetOcppPath()
  17063. {
  17064. int result = FALSE;
  17065. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  17066. {
  17067. if(OcppTempPath == NULL)
  17068. {
  17069. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17070. }
  17071. else
  17072. {
  17073. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17074. }
  17075. result = TRUE;
  17076. goto End;
  17077. }
  17078. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  17079. {
  17080. if(OcppTempPath == NULL)
  17081. {
  17082. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  17083. }
  17084. else
  17085. {
  17086. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  17087. }
  17088. result = TRUE;
  17089. goto End;
  17090. }
  17091. else
  17092. {
  17093. strcpy(OcppPath,"");
  17094. }
  17095. End:
  17096. return result;
  17097. }
  17098. int GetOcppPort()
  17099. {
  17100. return OcppPort;
  17101. }
  17102. int GetOcppConnStatus(void)
  17103. {
  17104. return ShmOCPP16Data->OcppConnStatus;
  17105. }
  17106. void SetOcppConnStatus(uint8_t status)
  17107. {
  17108. ShmOCPP16Data->OcppConnStatus = status;
  17109. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  17110. }
  17111. int GetHeartBeatWithNOResponse(void)
  17112. {
  17113. return HeartBeatWithNOResponse;
  17114. }
  17115. void SetHeartBeatWithNOResponse(void)
  17116. {
  17117. HeartBeatWithNOResponse = 0;
  17118. }
  17119. void GetStartTransactionIdTag(int gun_index)
  17120. {
  17121. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17122. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17123. }
  17124. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17125. {
  17126. char ch;
  17127. FILE *fptr1;
  17128. int temptransactionId;
  17129. char str[100]={0};
  17130. temptransactionId = 0;
  17131. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17132. {
  17133. DEBUG_INFO("IdTag is empty.\n");
  17134. return temptransactionId;
  17135. }
  17136. /*------ Read the file ----------------*/
  17137. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  17138. if (!fptr1)
  17139. {
  17140. DEBUG_INFO("QueueTransactionId file open error.\n");
  17141. //printf(" File not found or unable to open the input file!!\n");
  17142. return temptransactionId;
  17143. }
  17144. ch=fgetc(fptr1);
  17145. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  17146. rewind(fptr1);
  17147. if(ch!=EOF)
  17148. {
  17149. // printf("%c",ch);
  17150. while (fgets(str, 100, fptr1) != NULL)
  17151. {
  17152. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17153. if(str[0]=='\0')
  17154. {
  17155. break;
  17156. }
  17157. char *revbuf[8] = {0}; // Variable store string split
  17158. int num = 0;// Quantity after string split
  17159. DEBUG_INFO("Transaction queue data= %s\n", str);
  17160. splitstring(str,",",revbuf,&num); // String split
  17161. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17162. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17163. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17164. DEBUG_INFO("------------------------------\n");
  17165. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17166. {
  17167. if(isStopTransaction)
  17168. {
  17169. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17170. {
  17171. temptransactionId = atoi(revbuf[2]);
  17172. //break;
  17173. }
  17174. }
  17175. else
  17176. {
  17177. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17178. {
  17179. temptransactionId = atoi(revbuf[2]);
  17180. //break;
  17181. }
  17182. }
  17183. }
  17184. }
  17185. }
  17186. else
  17187. DEBUG_INFO("EOF\n");
  17188. fclose(fptr1);
  17189. /*------- End of reading ---------------*/
  17190. return temptransactionId;
  17191. }
  17192. void SetTransactionIdZero(int transactionId)
  17193. {
  17194. char ch;
  17195. FILE *fptr1, *fptr2;
  17196. int temptransactionId = 0;
  17197. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  17198. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  17199. if (!fptr1)
  17200. {
  17201. //printf(" File not found or unable to open the input file!!\n");
  17202. return ;
  17203. }
  17204. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17205. if (!fptr2)
  17206. {
  17207. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17208. fclose(fptr1);
  17209. return ;
  17210. }
  17211. ch=fgetc(fptr1);
  17212. rewind(fptr1);
  17213. if(ch!=EOF)
  17214. {
  17215. // copy all contents to the temporary file except the specific line
  17216. while (fgets(str, 100, fptr1) != NULL)
  17217. {
  17218. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17219. if(str[0]=='\0')
  17220. {
  17221. break;
  17222. }
  17223. char *revbuf[8] = {0};
  17224. int num = 0;
  17225. strcpy(strtemp, str);
  17226. splitstring(str,",",revbuf,&num);
  17227. if(revbuf[2][0] != '\0')
  17228. {
  17229. temptransactionId = atoi(revbuf[2]);
  17230. if(transactionId != temptransactionId)
  17231. {
  17232. fprintf(fptr2, "%s\n", strtemp);
  17233. }
  17234. }
  17235. }
  17236. }
  17237. fclose(fptr1);
  17238. fclose(fptr2);
  17239. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  17240. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  17241. /*------ Read the file ----------------*/
  17242. }
  17243. int InternetDisconnect(void)
  17244. {
  17245. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17246. }
  17247. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17248. void storeTempStopTransaction(int gun_index)
  17249. {
  17250. char guid[37]={0};
  17251. int tempIndex = 0;
  17252. char TempStopTransaction[256];
  17253. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  17254. DEBUG_INFO("storeTempStopTransaction...\n");
  17255. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17256. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  17257. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17258. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17259. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17260. {
  17261. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17262. {
  17263. tempIndex = ((gun_index==2) ? 1: 0);
  17264. }
  17265. else
  17266. {
  17267. tempIndex = gun_index;
  17268. }
  17269. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17270. {
  17271. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17272. {
  17273. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17274. }
  17275. }// END OF CHAdeMO_QUANTITY
  17276. }
  17277. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17278. {
  17279. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17280. {
  17281. tempIndex = ((gun_index==2) ? 1: 0);
  17282. }
  17283. else
  17284. {
  17285. tempIndex = gun_index;
  17286. }
  17287. for (int index = 0; index < CCS_QUANTITY; index++)
  17288. {
  17289. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17290. {
  17291. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17292. }
  17293. }// END OF CCS_QUANTITY
  17294. }
  17295. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17296. {
  17297. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17298. {
  17299. tempIndex = ((gun_index==2) ? 1: 0);
  17300. }
  17301. else
  17302. {
  17303. tempIndex = gun_index;
  17304. }
  17305. for (int index = 0; index < GB_QUANTITY; index++)
  17306. {
  17307. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17308. {
  17309. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17310. }
  17311. }// END OF GB_QUANTITY
  17312. }
  17313. else if(gunType[gun_index] == GUN_TYPE_DO)
  17314. {
  17315. tempIndex = gun_index;
  17316. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17317. {
  17318. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17319. {
  17320. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17321. }
  17322. }
  17323. }
  17324. else
  17325. {
  17326. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17327. {
  17328. tempIndex = 2;
  17329. }
  17330. else
  17331. {
  17332. tempIndex = gun_index;
  17333. }
  17334. for (int index = 0; index < AC_QUANTITY; index++)
  17335. {
  17336. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17337. {
  17338. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17339. }
  17340. }// END OF AC_QUANTITY
  17341. }
  17342. //Stop Transaction Time
  17343. struct timeval tmnow;
  17344. struct tm *tm;
  17345. char buf[28];//, usec_buf[6];
  17346. gettimeofday(&tmnow, NULL);
  17347. time_t t;
  17348. t = time(NULL);
  17349. /*UTC time and date*/
  17350. tm = gmtime(&t);
  17351. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17352. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  17353. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  17354. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17355. random_uuid(guid);
  17356. /***********************************transactionData******************************************************/
  17357. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17358. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17359. //=================================
  17360. //1. Transaction_Begin
  17361. //=================================
  17362. //============================== Energy.Active.Import.Interval ===========================================
  17363. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17364. {
  17365. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  17366. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17367. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  17368. 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*/]);
  17369. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17370. 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))
  17371. {
  17372. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  17373. }
  17374. else
  17375. {
  17376. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  17377. }
  17378. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  17379. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17380. }
  17381. //=================================
  17382. //2. Transaction_End
  17383. //=================================
  17384. //2.1====================================== Current.Import L1 ==============================================
  17385. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17386. {
  17387. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17388. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17389. {
  17390. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17391. {
  17392. tempIndex = ((gun_index==2) ? 1: 0);
  17393. }
  17394. else
  17395. {
  17396. tempIndex = gun_index;
  17397. }
  17398. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17399. {
  17400. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17401. {
  17402. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17403. }
  17404. }// End of for CHAdeMO_QUANTITY
  17405. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17406. }
  17407. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17408. {
  17409. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17410. {
  17411. tempIndex = ((gun_index==2) ? 1: 0);
  17412. }
  17413. else
  17414. {
  17415. tempIndex = gun_index;
  17416. }
  17417. for (int index = 0; index < CCS_QUANTITY; index++)
  17418. {
  17419. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17420. {
  17421. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17422. }
  17423. }// End of for CCS_QUANTITY
  17424. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17425. }
  17426. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17427. {
  17428. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17429. {
  17430. tempIndex = ((gun_index==2) ? 1: 0);
  17431. }
  17432. else
  17433. {
  17434. tempIndex = gun_index;
  17435. }
  17436. for (int index = 0; index < GB_QUANTITY; index++)
  17437. {
  17438. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17439. {
  17440. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17441. }
  17442. }// End of for GB_QUANTITY
  17443. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17444. }
  17445. else if(gunType[gun_index] == GUN_TYPE_DO)
  17446. {
  17447. tempIndex = gun_index;
  17448. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17449. {
  17450. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17451. {
  17452. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17453. }
  17454. }
  17455. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17456. }
  17457. else
  17458. {
  17459. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17460. {
  17461. tempIndex = 2;
  17462. }
  17463. else
  17464. {
  17465. tempIndex = gun_index;
  17466. }
  17467. for (int index = 0; index < AC_QUANTITY; index++)
  17468. {
  17469. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17470. {
  17471. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17472. }
  17473. }// End of for AC_QUANTITY
  17474. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17475. }
  17476. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17477. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17479. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17480. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17481. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17482. }
  17483. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17484. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17485. {
  17486. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17487. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17488. {
  17489. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17490. {
  17491. tempIndex = ((gun_index==2) ? 1: 0);
  17492. }
  17493. else
  17494. {
  17495. tempIndex = gun_index;
  17496. }
  17497. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17498. {
  17499. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17500. {
  17501. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17502. }
  17503. }// END OF CHAdeMO_QUANTITY
  17504. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17505. }
  17506. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17507. {
  17508. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17509. {
  17510. tempIndex = ((gun_index==2) ? 1: 0);
  17511. }
  17512. else
  17513. {
  17514. tempIndex = gun_index;
  17515. }
  17516. for (int index = 0; index < CCS_QUANTITY; index++)
  17517. {
  17518. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17519. {
  17520. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17521. }
  17522. }// END OF CCS_QUANTITY
  17523. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17524. }
  17525. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17526. {
  17527. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17528. {
  17529. tempIndex = ((gun_index==2) ? 1: 0);
  17530. }
  17531. else
  17532. {
  17533. tempIndex = gun_index;
  17534. }
  17535. for (int index = 0; index < GB_QUANTITY; index++)
  17536. {
  17537. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17538. {
  17539. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17540. }
  17541. }// END OF GB_QUANTITY
  17542. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17543. }
  17544. else if(gunType[gun_index] == GUN_TYPE_DO)
  17545. {
  17546. tempIndex = gun_index;
  17547. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17548. {
  17549. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17550. {
  17551. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17552. }
  17553. }
  17554. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17555. }
  17556. else
  17557. {
  17558. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17559. {
  17560. tempIndex = 2;
  17561. }
  17562. else
  17563. {
  17564. tempIndex = gun_index;
  17565. }
  17566. for (int index = 0; index < AC_QUANTITY; index++)
  17567. {
  17568. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17569. {
  17570. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17571. }
  17572. }// END OF AC_QUANTITY
  17573. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17574. }
  17575. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17576. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17577. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17578. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17579. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17580. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17581. }
  17582. //2.3====================================== Power.Active.Import =========================================
  17583. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17584. {
  17585. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17586. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17587. {
  17588. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17589. {
  17590. tempIndex = ((gun_index==2) ? 1: 0);
  17591. }
  17592. else
  17593. {
  17594. tempIndex = gun_index;
  17595. }
  17596. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17597. {
  17598. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17599. {
  17600. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17601. }
  17602. } // End for CHAdeMO_QUANTITY
  17603. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17604. }
  17605. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17606. {
  17607. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17608. {
  17609. tempIndex = ((gun_index==2) ? 1: 0);
  17610. }
  17611. else
  17612. {
  17613. tempIndex = gun_index;
  17614. }
  17615. for (int index = 0; index < CCS_QUANTITY; index++)
  17616. {
  17617. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17618. {
  17619. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17620. }
  17621. } // END for CCS_QUANTITY
  17622. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17623. }
  17624. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17625. {
  17626. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17627. {
  17628. tempIndex = ((gun_index==2) ? 1: 0);
  17629. }
  17630. else
  17631. {
  17632. tempIndex = gun_index;
  17633. }
  17634. for (int index = 0; index < GB_QUANTITY; index++)
  17635. {
  17636. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17637. {
  17638. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17639. }
  17640. }// END for GB_QUANTITY
  17641. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17642. }
  17643. else if(gunType[gun_index] == GUN_TYPE_DO)
  17644. {
  17645. tempIndex = gun_index;
  17646. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17647. {
  17648. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17649. {
  17650. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17651. }
  17652. }
  17653. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17654. }
  17655. else
  17656. {
  17657. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17658. {
  17659. tempIndex = 2;
  17660. }
  17661. else
  17662. {
  17663. tempIndex = gun_index;
  17664. }
  17665. for (int index = 0; index < AC_QUANTITY; index++)
  17666. {
  17667. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17668. {
  17669. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17670. }
  17671. } // END for AC_QUANTITY
  17672. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17673. }
  17674. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17675. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17676. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17677. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17678. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17679. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17680. }
  17681. //2.4====================================== Voltage L1 ====================================================
  17682. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17683. {
  17684. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17685. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17686. {
  17687. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17688. {
  17689. tempIndex = ((gun_index==2) ? 1: 0);
  17690. }
  17691. else
  17692. {
  17693. tempIndex = gun_index;
  17694. }
  17695. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17696. {
  17697. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17698. {
  17699. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17700. }
  17701. } // END OF FOR CHAdeMO_QUANTITY
  17702. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17703. }
  17704. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17705. {
  17706. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17707. {
  17708. tempIndex = ((gun_index==2) ? 1: 0);
  17709. }
  17710. else
  17711. {
  17712. tempIndex = gun_index;
  17713. }
  17714. for (int index = 0; index < CCS_QUANTITY; index++)
  17715. {
  17716. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17717. {
  17718. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17719. }
  17720. } // END OF FOR CCS_QUANTITY
  17721. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17722. }
  17723. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17724. {
  17725. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17726. {
  17727. tempIndex = ((gun_index==2) ? 1: 0);
  17728. }
  17729. else
  17730. {
  17731. tempIndex = gun_index;
  17732. }
  17733. for (int index = 0; index < GB_QUANTITY; index++)
  17734. {
  17735. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17736. {
  17737. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17738. }
  17739. } // END OF FOR GB_QUANTITY
  17740. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17741. }
  17742. else if(gunType[gun_index] == GUN_TYPE_DO)
  17743. {
  17744. tempIndex = gun_index;
  17745. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17746. {
  17747. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17748. {
  17749. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17750. }
  17751. }
  17752. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17753. }
  17754. else
  17755. {
  17756. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17757. {
  17758. tempIndex = 2;
  17759. }
  17760. else
  17761. {
  17762. tempIndex = gun_index;
  17763. }
  17764. for (int index = 0; index < AC_QUANTITY; index++)
  17765. {
  17766. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17767. {
  17768. 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
  17769. }
  17770. } // END OF FOR AC_QUANTITY
  17771. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17772. }
  17773. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17774. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17775. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17776. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17777. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17778. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17779. }
  17780. //2.5============================================== End SoC =========================================================
  17781. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17782. {
  17783. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17784. 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))
  17785. {
  17786. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17787. {
  17788. tempIndex = ((gun_index==2) ? 1: 0);
  17789. }
  17790. else
  17791. {
  17792. tempIndex = gun_index;
  17793. }
  17794. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17795. {
  17796. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17797. {
  17798. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17799. {
  17800. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17801. }
  17802. }
  17803. }
  17804. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17805. {
  17806. for (int index = 0; index < CCS_QUANTITY; index++)
  17807. {
  17808. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17809. {
  17810. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17811. }
  17812. }
  17813. }
  17814. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17815. {
  17816. for (int index = 0; index < GB_QUANTITY; index++)
  17817. {
  17818. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17819. {
  17820. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17821. }
  17822. }
  17823. }
  17824. else if(gunType[gun_index] == GUN_TYPE_DO)
  17825. {
  17826. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17827. {
  17828. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17829. {
  17830. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17831. }
  17832. }
  17833. }
  17834. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17835. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17836. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17837. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17838. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17839. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17840. } // END FOR DC CASE
  17841. }
  17842. //2.6====================================== Current.Import L2 ==============================================
  17843. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17844. {
  17845. // AC 3 phase L2 current
  17846. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17847. {
  17848. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17849. {
  17850. tempIndex = 2;
  17851. }
  17852. else
  17853. {
  17854. tempIndex = gun_index;
  17855. }
  17856. for (int index = 0; index < AC_QUANTITY; index++)
  17857. {
  17858. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17859. {
  17860. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17861. }
  17862. }// End of for AC_QUANTITY
  17863. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17864. }
  17865. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17866. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17867. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17868. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17869. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17870. }
  17871. //2.7====================================== Current.Import L3 ==============================================
  17872. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17873. {
  17874. // AC 3 phase L3 current
  17875. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17876. {
  17877. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17878. {
  17879. tempIndex = 2;
  17880. }
  17881. else
  17882. {
  17883. tempIndex = gun_index;
  17884. }
  17885. for (int index = 0; index < AC_QUANTITY; index++)
  17886. {
  17887. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17888. {
  17889. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17890. }
  17891. }// End of for AC_QUANTITY
  17892. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17893. }
  17894. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17895. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17896. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17897. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17898. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17899. }
  17900. //2.9====================================== Voltage L2 ====================================================
  17901. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17902. {
  17903. // AC 3 phase L2 volatge
  17904. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17905. {
  17906. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17907. {
  17908. tempIndex = 2;
  17909. }
  17910. else
  17911. {
  17912. tempIndex = gun_index;
  17913. }
  17914. for (int index = 0; index < AC_QUANTITY; index++)
  17915. {
  17916. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17917. {
  17918. 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
  17919. }
  17920. } // END OF FOR AC_QUANTITY
  17921. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  17922. }
  17923. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17924. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17925. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17926. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17927. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17928. }
  17929. //2.10====================================== Voltage L3 ====================================================
  17930. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17931. {
  17932. // AC 3 phase L3 volatge
  17933. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17934. {
  17935. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17936. {
  17937. tempIndex = 2;
  17938. }
  17939. else
  17940. {
  17941. tempIndex = gun_index;
  17942. }
  17943. for (int index = 0; index < AC_QUANTITY; index++)
  17944. {
  17945. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17946. {
  17947. 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
  17948. }
  17949. } // END OF FOR AC_QUANTITY
  17950. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  17951. }
  17952. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17953. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  17954. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  17955. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  17956. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17957. }
  17958. //====================== Start SoC ================================
  17959. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17960. {
  17961. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17962. 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))
  17963. {
  17964. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17965. {
  17966. tempIndex = ((gun_index==2) ? 1: 0);
  17967. }
  17968. else
  17969. {
  17970. tempIndex = gun_index;
  17971. }
  17972. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17973. {
  17974. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17975. {
  17976. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17977. {
  17978. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  17979. }
  17980. }
  17981. }
  17982. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17983. {
  17984. for (int index = 0; index < CCS_QUANTITY; index++)
  17985. {
  17986. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17987. {
  17988. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  17989. }
  17990. }
  17991. }
  17992. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17993. {
  17994. for (int index = 0; index < GB_QUANTITY; index++)
  17995. {
  17996. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17997. {
  17998. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  17999. }
  18000. }
  18001. }
  18002. else if(gunType[gun_index] == GUN_TYPE_DO)
  18003. {
  18004. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18005. {
  18006. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18007. {
  18008. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18009. }
  18010. }
  18011. }
  18012. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18013. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18014. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18015. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18016. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18017. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18018. } // END FOR DC CASE
  18019. }
  18020. //======================================== Message create ==============================================
  18021. json_object *StopTransaction = json_object_new_object();
  18022. json_object *transactionDatas = json_object_new_array();
  18023. json_object *sampledValues = json_object_new_array();
  18024. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  18025. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  18026. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  18027. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  18028. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  18029. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18030. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  18031. {
  18032. json_object *transactionData = json_object_new_object();
  18033. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18034. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18035. {
  18036. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18037. {
  18038. json_object *sampledValue = json_object_new_object();
  18039. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18040. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18041. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18042. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18043. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18044. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18045. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18046. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18047. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18048. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18049. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18050. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18051. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18052. json_object_array_add(sampledValues, sampledValue);
  18053. }
  18054. }
  18055. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18056. json_object_array_add(transactionDatas, transactionData);
  18057. }
  18058. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18059. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18060. ,MESSAGE_TYPE_CALL
  18061. ,guid
  18062. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18063. json_object_put(StopTransaction);
  18064. // Check File "TempStopTransaction" Exist
  18065. if((access(TempStopTransaction,F_OK))!=-1)
  18066. {
  18067. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18068. fclose(fopen(TempStopTransaction, "w"));
  18069. }
  18070. else
  18071. {
  18072. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18073. FILE *log = fopen(TempStopTransaction, "w+");
  18074. if(log == NULL)
  18075. {
  18076. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18077. return ;
  18078. }
  18079. else
  18080. {
  18081. fclose(log);
  18082. }
  18083. }
  18084. //Add TempStopTransaction | Update TempStopTransaction
  18085. // open file for writing
  18086. FILE *outfile;
  18087. outfile = fopen (TempStopTransaction, "a");
  18088. //DEBUG_INFO("data = %s\n", queuedata);
  18089. fputs(queuedata, outfile);
  18090. fputs("\n", outfile);
  18091. fclose (outfile);
  18092. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18093. OCPP_updatePeriodEnergy(gun_index);
  18094. }
  18095. void checkTempStopTransaction(int gun_index)
  18096. {
  18097. FILE *fptr1;
  18098. char ch;
  18099. char str[QUEUE_MESSAGE_LENGTH]={0};
  18100. char guid[37]={0};
  18101. char tempdata[65]={0};
  18102. char connectorStr[2]={0};
  18103. char TempStopTransaction[256];
  18104. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18105. fptr1 = fopen(TempStopTransaction, "r");
  18106. //TempStopTransaction格式: 槍號,StopTransaction封包
  18107. if (!fptr1)
  18108. {
  18109. //printf(" File not found or unable to open the input file!!\n");
  18110. return ;
  18111. }
  18112. ch=fgetc(fptr1);
  18113. //printf(" Now the content of the file %s is : \n",fname);
  18114. rewind(fptr1);
  18115. if(ch!=EOF)
  18116. {
  18117. // copy all contents to the temporary file except the specific line
  18118. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18119. {
  18120. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18121. if(str[0]=='\0')
  18122. {
  18123. break;
  18124. }
  18125. //TempStopTransaction格式: 槍號,StopTransaction封包
  18126. strncpy(connectorStr, str, 1);
  18127. if(atoi(connectorStr) != (gun_index+1))
  18128. {
  18129. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18130. fclose(fptr1);
  18131. return ;
  18132. }
  18133. //random_uuid(guid);
  18134. strncpy(guid, str+6, 36); //copy guid
  18135. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18136. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18137. {
  18138. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18139. }
  18140. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18141. OCPP_insert_transaction_msg(NO, str);
  18142. memset(str,0,ARRAY_SIZE(str));
  18143. }
  18144. }
  18145. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18146. fclose(fptr1);
  18147. remove(TempStopTransaction); // remove the original file
  18148. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18149. }
  18150. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18151. {
  18152. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18153. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18154. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18155. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18156. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18157. }
  18158. int GetWebSocketPingInterval(void)
  18159. {
  18160. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18161. }
  18162. int GetServerSign(void)
  18163. {
  18164. return server_sign;
  18165. }
  18166. uint8_t GetOcppSecurityProfile()
  18167. {
  18168. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18169. }
  18170. void GetOcppChargerBoxId(uint8_t *data)
  18171. {
  18172. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18173. }
  18174. void GetOcppSecurityPassword(uint8_t *data)
  18175. {
  18176. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18177. }
  18178. void SetOcppVersion(uint8_t *version)
  18179. {
  18180. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18181. DEBUG_INFO("ocpp version: %s\n", version);
  18182. if(strstr((char*)version, "ocpp1.6") != NULL)
  18183. {
  18184. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18185. }
  18186. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18187. {
  18188. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18189. system("pkill OcppBackend");
  18190. }
  18191. }
  18192. void SetServerSign(int value)
  18193. {
  18194. server_sign = value;
  18195. }
  18196. int GetBootNotificationInterval(void)
  18197. {
  18198. return BootNotificationInterval;
  18199. }
  18200. int GetInternetConn(void)
  18201. {
  18202. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18203. }
  18204. int GetBackendConnectionTimeout(void)
  18205. {
  18206. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18207. }
  18208. int isConnectorInitMode(int gun_index)
  18209. {
  18210. int tempIndex = 0;
  18211. int result = TRUE;
  18212. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18213. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18214. {
  18215. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18216. {
  18217. tempIndex = ((gun_index==2) ? 1: 0);
  18218. }
  18219. else
  18220. {
  18221. tempIndex = gun_index;
  18222. }
  18223. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18224. {
  18225. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18226. {
  18227. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18228. } //end of the same index
  18229. }//end of for CHAdeMO_QUANTITY
  18230. }
  18231. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18232. {
  18233. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18234. {
  18235. tempIndex = ((gun_index==2) ? 1: 0);
  18236. }
  18237. else
  18238. {
  18239. tempIndex = gun_index;
  18240. }
  18241. for (int index = 0; index < CCS_QUANTITY; index++)
  18242. {
  18243. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18244. {
  18245. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18246. } //end of the same index
  18247. } // end of for CCS_QUANTITY
  18248. }
  18249. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18250. {
  18251. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18252. {
  18253. tempIndex = ((gun_index==2) ? 1: 0);
  18254. }
  18255. else
  18256. {
  18257. tempIndex = gun_index;
  18258. }
  18259. for (int index = 0; index < GB_QUANTITY; index++)
  18260. {
  18261. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18262. {
  18263. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18264. } //end of the same index
  18265. } // end of for GB_QUANTITY
  18266. }
  18267. else if(gunType[gun_index] == GUN_TYPE_DO)
  18268. {
  18269. tempIndex = gun_index;
  18270. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18271. {
  18272. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18273. {
  18274. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18275. } //end of the same index
  18276. }
  18277. }
  18278. else
  18279. {
  18280. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18281. {
  18282. tempIndex = 2;
  18283. }
  18284. else
  18285. {
  18286. tempIndex = gun_index;
  18287. }
  18288. for (int index = 0; index < AC_QUANTITY; index++)
  18289. {
  18290. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18291. {
  18292. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18293. }//end of the same index
  18294. }//end of for AC_QUANTITY
  18295. }
  18296. return result;
  18297. }
  18298. void refreshProcDogTimer()
  18299. {
  18300. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  18301. }
  18302. void InitialSystemValue(void)
  18303. {
  18304. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18305. locallistVersion=0;
  18306. BootNotificationInterval = 0;
  18307. authorizeRetryTimes = 0;
  18308. GunStatusInterval = 10;
  18309. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18310. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18311. //Hear Beat
  18312. HeartBeatWithNOResponse = 0;
  18313. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18314. FirstHeartBeat = 0;
  18315. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18316. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18317. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18318. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18319. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18320. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18321. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18322. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18323. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18324. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18325. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18326. //Status && ConnectorPlugIn Setting
  18327. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18328. {
  18329. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18330. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18331. }
  18332. for (int index = 0; index < CCS_QUANTITY; index++)
  18333. {
  18334. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18335. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18336. }
  18337. for (int index = 0; index < GB_QUANTITY; index++)
  18338. {
  18339. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18340. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18341. }
  18342. for (int index = 0; index < AC_QUANTITY; index++)
  18343. {
  18344. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18345. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18346. }
  18347. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18348. {
  18349. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18350. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18351. }
  18352. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18353. {
  18354. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18355. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18356. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18357. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18358. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18359. }
  18360. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18361. refreshStartTimer(&clientTime.Heartbeat);
  18362. sleep(1);
  18363. }
  18364. void LWS_Send(char *str)
  18365. {
  18366. //=====================================================
  18367. // Check InternetConn 0: disconnected, 1: connected
  18368. //====================================================
  18369. if(GetOcppConnStatus() == 0)
  18370. {
  18371. DEBUG_INFO("offline now !!!\n");
  18372. return;
  18373. }
  18374. // Only disable isWebsocketSendable operation initiated by charger
  18375. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18376. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18377. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18378. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18379. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18380. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18381. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18382. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18383. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18384. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18385. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18386. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18387. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18388. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18389. {
  18390. isWebsocketSendable = 0;
  18391. }
  18392. pthread_mutex_lock(&lock_send);
  18393. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18394. sprintf((char *)SendBuffer, "%s", str);
  18395. SendBufLen = strlen(str);
  18396. pthread_mutex_unlock(&lock_send);
  18397. lws_callback_on_writable(wsi_client);
  18398. //lws_service(context, 0);
  18399. //sleep(1);
  18400. }
  18401. void LWS_SendNow(char *str)
  18402. {
  18403. //=====================================================
  18404. // Check InternetConn 0: disconnected, 1: connected
  18405. //====================================================
  18406. if(GetOcppConnStatus() == 0)
  18407. {
  18408. DEBUG_INFO("offline now !!!\n");
  18409. return;
  18410. }
  18411. // Only disable isWebsocketSendable operation initiated by charger
  18412. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18413. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18414. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18415. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18416. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18417. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18418. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18419. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18420. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18421. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18422. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18423. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18424. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18425. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18426. {
  18427. isWebsocketSendable = 0;
  18428. }
  18429. pthread_mutex_lock(&lock_send);
  18430. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18431. sprintf((char *)SendBuffer, "%s", str);
  18432. SendBufLen = strlen(str);
  18433. pthread_mutex_unlock(&lock_send);
  18434. lws_callback_on_writable(wsi_client);
  18435. lws_service(context, 0);
  18436. //sleep(1);
  18437. }