MessageHandler.c 925 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknown key
  21. //===============================
  22. static char unknownkey[10][36] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static ParsingRatedCur modelnameInfo = {0};
  28. static int gunTotalNumber = 0;
  29. static uint8_t gunType[4] = {0};
  30. //===============================
  31. // Local List Version
  32. //===============================
  33. static int locallistVersion=0;
  34. static char idTagAuthorization[32] = {0};
  35. //===============================
  36. // OCPP sign variable
  37. //===============================
  38. static int server_sign = FALSE;
  39. int server_pending = FALSE;
  40. static int BootNotificationInterval = 0;
  41. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  42. //===============================
  43. // OCPP auth variable
  44. //===============================
  45. static int authorizeRetryTimes = 0; //number of Retry times
  46. //===============================
  47. // OCPP other variables
  48. //===============================
  49. static int HeartBeatWaitTime = 10;
  50. static int FirstHeartBeat = 0;
  51. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  52. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  53. static char CurrentChargingProfileScheduleStr[30] = {0};
  54. //========================================
  55. // OCPP status/previous related variables
  56. //========================================
  57. static int GunStatusInterval = 10;
  58. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  59. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  60. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  61. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  62. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  63. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  64. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  65. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  66. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  67. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  68. static int TransactionMessageAttemptsValue = 0;
  69. static int TransactionMessageRetryIntervalValue = 0;
  70. static int TempMeterValueInterval = 0;
  71. static struct OCPPAuthLocalElemet
  72. {
  73. int listVersionInt;
  74. char idTagstr[21];
  75. char parentIdTag[21];
  76. char expiryDate[36];
  77. char idTagstatus[16];
  78. }idTagQuery;
  79. //============================================
  80. // OCPP MeterValue request flag
  81. //============================================
  82. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  83. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  84. //=============================================
  85. // OCPP HeartBeat Response Not Receive Counts
  86. //============================================
  87. static int HeartBeatWithNOResponse = 0;
  88. extern sqlite3 *db;
  89. int TransactionMessageAttemptsGet(void);
  90. int TransactionMessageRetryIntervalGet(void);
  91. int GetOcppConnStatus(void);
  92. void SetOcppConnStatus(uint8_t status);
  93. int setKeyValue(char *key, char *value);
  94. void OCPP_get_TableAuthlocalAllData(void);
  95. void processUnkownKey(void);
  96. struct InterLock
  97. {
  98. unsigned char isGetDiagnosticGoing:1;
  99. unsigned char isUpdateFirmwareGoing:1;
  100. }interLock;
  101. struct ClientTime
  102. {
  103. struct timespec Heartbeat;
  104. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  105. struct timespec StartTransaction;
  106. struct timespec StopTransaction;
  107. struct timespec MeterValues[CONNECTOR_QUANTITY];
  108. struct timespec RemoteStartWait;
  109. struct timespec TcciQueryDeduct;
  110. }clientTime;
  111. typedef union
  112. {
  113. //Operations Initiated by Central System
  114. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  115. struct
  116. {
  117. //CsMsgValue[0]
  118. unsigned char StatusNotificationReq:1; //bit 0,
  119. unsigned char StatusNotificationConf:1; //bit 1,
  120. unsigned char TriggerMeterValue:1; //bit 2,
  121. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  122. unsigned char isOnCharging:1; //bit 4,
  123. unsigned char :3; //bit5~7
  124. }bits[CONNECTOR_QUANTITY];
  125. }CpinitiateMsg;
  126. CpinitiateMsg cpinitateMsg;
  127. //GetConfiguration Array
  128. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  129. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  130. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  131. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  132. #if 0
  133. static char *ChargePointErrorCodeStr[] = {
  134. MACROSTR(ConnectorLockFailure),
  135. MACROSTR(EVCommunicationError),
  136. MACROSTR(GroundFailure),
  137. MACROSTR(HighTemperature),
  138. MACROSTR(InternalError),
  139. MACROSTR(LocalListConflict),
  140. MACROSTR(NoError),
  141. MACROSTR(OtherError),
  142. MACROSTR(OverCurrentFailure),
  143. MACROSTR(OverVoltage),
  144. MACROSTR(PowerMeterFailure),
  145. MACROSTR(PowerSwitchFailure),
  146. MACROSTR(ReaderFailure),
  147. MACROSTR(ResetFailure),
  148. MACROSTR(UnderVoltage),
  149. MACROSTR(WeakSignal)
  150. };
  151. #endif
  152. static char * ChargePointStatusStr[] = {
  153. MACROSTR(Available),
  154. MACROSTR(Preparing),
  155. MACROSTR(Charging),
  156. MACROSTR(SuspendedEVSE),
  157. MACROSTR(SuspendedEV),
  158. MACROSTR(Finishing),
  159. MACROSTR(Reserved),
  160. MACROSTR(Unavailable),
  161. MACROSTR(Faulted)
  162. };
  163. static char *RegistrationStatusStr[] = {
  164. MACROSTR(Accepted),
  165. MACROSTR(Pending),
  166. MACROSTR(Rejected)
  167. };
  168. static char *AvailabilityTypeStr[] = {
  169. MACROSTR(Inoperative),
  170. MACROSTR(Operative)
  171. };
  172. static char *AvailabilityStatusStr[] = {
  173. MACROSTR(Accepted),
  174. MACROSTR(Rejected),
  175. MACROSTR(Scheduled)
  176. };
  177. static char *ConfigurationStatusStr[] = {
  178. MACROSTR(Accepted),
  179. MACROSTR(Rejected),
  180. MACROSTR(RebootRequired),
  181. MACROSTR(NotSupported)
  182. };
  183. static char *ClearCacheStatusStr[] = {
  184. MACROSTR(Accepted),
  185. MACROSTR(Rejected)
  186. };
  187. static char *ChargingProfilePurposeTypeStr[] = {
  188. MACROSTR(ChargePointMaxProfile),
  189. MACROSTR(TxDefaultProfile),
  190. MACROSTR(TxProfile)
  191. };
  192. static char *ChargingProfileStatusStr[] = {
  193. MACROSTR(Accepted),
  194. MACROSTR(Rejected),
  195. MACROSTR(NotSupported)
  196. };
  197. static char *ClearChargingProfileStatusStr[] = {
  198. MACROSTR(Accepted),
  199. MACROSTR(Unknown)
  200. };
  201. static char *GetCompositeScheduleStatusStr[] = {
  202. MACROSTR(Accepted),
  203. MACROSTR(Rejected)
  204. };
  205. static char *UpdateTypeStr[] = {
  206. MACROSTR(Differential),
  207. MACROSTR(Full)
  208. };
  209. static char *UpdateStatusStr[] = {
  210. MACROSTR(Accepted),
  211. MACROSTR(Failed),
  212. MACROSTR(NotSupported),
  213. MACROSTR(VersionMismatch)
  214. };
  215. static char *RemoteStartStopStatusStr[] = {
  216. MACROSTR(Accepted),
  217. MACROSTR(Rejected)
  218. };
  219. static char *ReservationStatusStr[] = {
  220. MACROSTR(Accepted),
  221. MACROSTR(Faulted),
  222. MACROSTR(Occupied),
  223. MACROSTR(Rejected),
  224. MACROSTR(Unavailable)
  225. };
  226. static char *ResetTypeStr[] = {
  227. MACROSTR(Hard),
  228. MACROSTR(Soft)
  229. };
  230. static char *ResetStatusStr[] = {
  231. MACROSTR(Accepted),
  232. MACROSTR(Rejected)
  233. };
  234. static char * DiagnosticsStatusStr[] = {
  235. MACROSTR(Idle),
  236. MACROSTR(Uploaded),
  237. MACROSTR(UploadFailed),
  238. MACROSTR(Uploading)
  239. };
  240. static char * FirmwareStatusStr[] = {
  241. MACROSTR(Downloaded),
  242. MACROSTR(DownloadFailed),
  243. MACROSTR(Downloading),
  244. MACROSTR(Idle),
  245. MACROSTR(InstallationFailed),
  246. MACROSTR(Installing),
  247. MACROSTR(Installed)
  248. };
  249. static char * MessageTriggerStr[] = {
  250. MACROSTR(BootNotification),
  251. MACROSTR(DiagnosticsStatusNotification),
  252. MACROSTR(FirmwareStatusNotification),
  253. MACROSTR(Heartbeat),
  254. MACROSTR(MeterValues),
  255. MACROSTR(StatusNotification)
  256. };
  257. static char * TriggerMessageStatusStr[] = {
  258. MACROSTR(Accepted),
  259. MACROSTR(Rejected),
  260. MACROSTR(NotImplemented)
  261. };
  262. static char * UnlockStatusStr[] = {
  263. MACROSTR(Unlocked),
  264. MACROSTR(UnlockFailed),
  265. MACROSTR(NotSupported)
  266. };
  267. #if 0
  268. static char * StopTransactionReasonStr[] = {
  269. MACROSTR(EmergencyStop),
  270. MACROSTR(EVDisconnected),
  271. MACROSTR(HardReset),
  272. MACROSTR(Local),
  273. MACROSTR(Other),
  274. MACROSTR(PowerLoss),
  275. MACROSTR(Reboot),
  276. MACROSTR(Remote),
  277. MACROSTR(SoftReset),
  278. MACROSTR(UnlockCommand),
  279. MACROSTR(DeAuthorized)
  280. };
  281. #endif
  282. static char * CancelReservationStatusStr[] = {
  283. MACROSTR(Accepted),
  284. MACROSTR(Rejected)
  285. };
  286. static char * ReadingContextStr[] = {
  287. MACROSTR(Interruption.Begin),
  288. MACROSTR(Interruption.End),
  289. MACROSTR(Other),
  290. MACROSTR(Sample.Clock),
  291. MACROSTR(Sample.Periodic),
  292. MACROSTR(Transaction.Begin),
  293. MACROSTR(Transaction.End),
  294. MACROSTR(Trigger)
  295. };
  296. static char * ValueFormatStr[] = {
  297. MACROSTR(Raw),
  298. MACROSTR(SignedData)
  299. };
  300. static char * MeasurandStr[] = {
  301. MACROSTR(Current.Export),
  302. MACROSTR(Current.Import),
  303. MACROSTR(Current.Offered),
  304. MACROSTR(Energy.Active.Export.Register),
  305. MACROSTR(Energy.Active.Import.Register),
  306. MACROSTR(Energy.Reactive.Export.Register),
  307. MACROSTR(Energy.Reactive.Import.Register),
  308. MACROSTR(Energy.Active.Export.Interval),
  309. MACROSTR(Energy.Active.Import.Interval),
  310. MACROSTR(Energy.Reactive.Export.Interval),
  311. MACROSTR(Energy.Reactive.Import.Interval),
  312. MACROSTR(Frequency),
  313. MACROSTR(Power.Active.Export),
  314. MACROSTR(Power.Active.Import),
  315. MACROSTR(Power.Factor),
  316. MACROSTR(Power.Offered),
  317. MACROSTR(Power.Reactive.ExportMACROSTR),
  318. MACROSTR(Power.Reactive.Import),
  319. MACROSTR(RPM),
  320. MACROSTR(SoC),
  321. MACROSTR(Temperature),
  322. MACROSTR(Voltage)
  323. };
  324. static char * LocationStr[] = {
  325. MACROSTR(Body),
  326. MACROSTR(Cable),
  327. MACROSTR(EV),
  328. MACROSTR(Inlet),
  329. MACROSTR(Outlet)
  330. };
  331. static char * PhaseStr[] = {
  332. MACROSTR(L1),
  333. MACROSTR(L2),
  334. MACROSTR(L3),
  335. MACROSTR(N),
  336. MACROSTR(L1-N),
  337. MACROSTR(L2-N),
  338. MACROSTR(L3-N),
  339. MACROSTR(L1-L2),
  340. MACROSTR(L2-L3),
  341. MACROSTR(L3-L1)
  342. };
  343. static char * UnitOfMeasureStr[] = {
  344. MACROSTR(Wh),
  345. MACROSTR(kWh),
  346. MACROSTR(varh),
  347. MACROSTR(kvarh),
  348. MACROSTR(W),
  349. MACROSTR(kW),
  350. MACROSTR(VA),
  351. MACROSTR(kVA),
  352. MACROSTR(var),
  353. MACROSTR(kvar),
  354. MACROSTR(A),
  355. MACROSTR(V),
  356. MACROSTR(Celsius),
  357. MACROSTR(Fahrenheit),
  358. MACROSTR(K),
  359. MACROSTR(Percent)
  360. };
  361. //=========================================
  362. // TTIA routine
  363. //=========================================
  364. int sendTTIAInfo(uint8_t gun_index)
  365. {
  366. static int sn = 0;
  367. int result = FAIL;
  368. struct hostent *server;
  369. int udp_socket_fd;
  370. struct sockaddr_in dest_addr = {0};
  371. uint8_t tx_buf[80] = {0};
  372. uint8_t logBuf[256]= {0};
  373. uint8_t tx_len, tempIndex, socStart, socEnd;
  374. uint16_t PresentChargedEnergy;
  375. struct tm tmStart, tmEnd;
  376. DEBUG_INFO("sendTTIAInfo...\n");
  377. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  378. {
  379. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  380. {
  381. tempIndex = ((gun_index==2) ? 1: 0);
  382. }
  383. else
  384. {
  385. tempIndex = gun_index;
  386. }
  387. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  388. {
  389. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  390. {
  391. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  392. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  393. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  394. }
  395. }
  396. }
  397. else if(gunType[gun_index] == GUN_TYPE_CCS)
  398. {
  399. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  400. {
  401. tempIndex = ((gun_index==2) ? 1: 0);
  402. }
  403. else
  404. {
  405. tempIndex = gun_index;
  406. }
  407. for (int index = 0; index < CCS_QUANTITY; index++)
  408. {
  409. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  410. {
  411. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  412. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  413. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  414. }
  415. }
  416. }
  417. else if(gunType[gun_index] == GUN_TYPE_GBT)
  418. {
  419. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  420. {
  421. tempIndex = ((gun_index==2) ? 1: 0);
  422. }
  423. else
  424. {
  425. tempIndex = gun_index;
  426. }
  427. for (int index = 0; index < GB_QUANTITY; index++)
  428. {
  429. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  430. {
  431. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  432. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  433. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  434. }
  435. }
  436. }
  437. else if(gunType[gun_index] == GUN_TYPE_DO)
  438. {
  439. tempIndex = gun_index;
  440. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  441. {
  442. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  443. {
  444. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  445. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  446. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  447. }
  448. }
  449. }
  450. else
  451. {
  452. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  453. {
  454. tempIndex = 2;
  455. }
  456. else
  457. {
  458. tempIndex = gun_index;
  459. }
  460. for (int index = 0; index < AC_QUANTITY; index++)
  461. {
  462. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  463. {
  464. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  465. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  466. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  467. }
  468. }// END
  469. }
  470. // Message assembly
  471. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  472. tx_buf[4] = 0x02; // Protocol Version
  473. tx_buf[5] = 0xb0; // Message ID
  474. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  475. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  476. tx_buf[8] = 0x00; // CarID low byte
  477. tx_buf[9] = 0x00; // CarID high byte
  478. tx_buf[10] = 0x00; // ID Storage
  479. tx_buf[11] = 0x00; // Driver lowest byte
  480. tx_buf[12] = 0x00; // Driver 2nd byte
  481. tx_buf[13] = 0x00; // Driver 3rd byte
  482. tx_buf[14] = 0x00; // Driver highest byte
  483. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  484. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  485. tx_buf[17] = 0x00; // Reserve
  486. tx_buf[18] = 60 & 0xff; // Payload length low byte
  487. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  488. // EVSE provider
  489. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  490. // EVSE provider
  491. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  492. // EVSE id
  493. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  494. // Connector id
  495. tx_buf[37] = gun_index;
  496. // EVSE station
  497. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  498. // Vehicle SN
  499. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  500. // Mileage
  501. tx_buf[61] = 0x00; // lowest byte
  502. tx_buf[62] = 0x00; // 2nd byte
  503. tx_buf[63] = 0x00; // highest byte
  504. // Start date time 6 bytes
  505. if((sscanf((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6))
  506. {
  507. struct tm *tmTarget;
  508. struct timeb tbTarget;
  509. tmStart.tm_year -= 1900;
  510. tmStart.tm_mon -= 1;
  511. tmStart.tm_gmtoff = 0;
  512. tbTarget.time = mktime(&tmStart);
  513. tbTarget.timezone = 0;
  514. tbTarget.time += (8*3600);
  515. tmTarget = gmtime(&tbTarget.time);
  516. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  517. tx_buf[65] = (tmTarget->tm_mon+1);
  518. tx_buf[66] = tmTarget->tm_mday;
  519. tx_buf[67] = tmTarget->tm_hour;
  520. tx_buf[68] = tmTarget->tm_min;
  521. tx_buf[69] = tmTarget->tm_sec;
  522. }
  523. // Stop date time 6 bytes
  524. if((sscanf((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmEnd.tm_year, &tmEnd.tm_mon, &tmEnd.tm_mday, &tmEnd.tm_hour, &tmEnd.tm_min, &tmEnd.tm_sec) == 6))
  525. {
  526. struct tm *tmTarget;
  527. struct timeb tbTarget;
  528. tmEnd.tm_year -= 1900;
  529. tmEnd.tm_mon -= 1;
  530. tmEnd.tm_gmtoff = 0;
  531. tbTarget.time = mktime(&tmEnd);
  532. tbTarget.timezone = 0;
  533. tbTarget.time += (8*3600);
  534. tmTarget = gmtime(&tbTarget.time);
  535. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  536. tx_buf[71] = (tmTarget->tm_mon+1);
  537. tx_buf[72] = tmTarget->tm_mday;
  538. tx_buf[73] = tmTarget->tm_hour;
  539. tx_buf[74] = tmTarget->tm_min;
  540. tx_buf[75] = tmTarget->tm_sec;
  541. }
  542. // Session energy 2 bytes
  543. tx_buf[76] = PresentChargedEnergy & 0xff;
  544. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  545. // Start SOC 1 byte
  546. tx_buf[78] = socStart;
  547. // Stop SOC 1 byte
  548. tx_buf[79] = socEnd;
  549. // Open socket
  550. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  551. if(udp_socket_fd == -1)
  552. {
  553. DEBUG_ERROR("UDP socket create failed!\n");
  554. }
  555. else
  556. {
  557. // Get server DNS entry
  558. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  559. if (server == NULL)
  560. {
  561. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  562. }
  563. else
  564. {
  565. // Build the server's Internet address
  566. bzero((char *) &dest_addr, sizeof(dest_addr));
  567. dest_addr.sin_family = AF_INET;
  568. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  569. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  570. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  571. {
  572. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  573. {
  574. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  575. }
  576. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  577. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  578. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  579. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  580. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  581. DEBUG_TTIA_INFO("---------- Header ----------\n");
  582. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  583. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  584. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  585. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  586. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  587. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  588. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  589. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  590. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  591. DEBUG_TTIA_INFO("Len: 0x3C\n");
  592. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  593. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  594. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  595. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  596. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  597. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  598. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  599. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  600. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  601. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  602. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  603. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  604. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  605. DEBUG_TTIA_INFO("=========================================\n");
  606. sn++;
  607. result = PASS;
  608. }
  609. else
  610. {
  611. DEBUG_ERROR("UDP sent out fail.\n");
  612. }
  613. }
  614. }
  615. return result;
  616. }
  617. //=========================================
  618. // Save configuration
  619. //=========================================
  620. int runShellCmd(const char*cmd)
  621. {
  622. int result = FAIL;
  623. char buf[256];
  624. FILE *fp;
  625. fp = popen(cmd, "r");
  626. if(fp != NULL)
  627. {
  628. while(fgets(buf, sizeof(buf), fp) != NULL)
  629. {
  630. DEBUG_INFO("%s\n", buf);
  631. }
  632. result = PASS;
  633. }
  634. pclose(fp);
  635. return result;
  636. }
  637. int StoreUsrConfigData(struct SysConfigData *UsrData)
  638. {
  639. int result = PASS;
  640. int fd,wrd;
  641. unsigned int i,Chk;
  642. unsigned char *ptr, *BufTmp;
  643. int MtdBlockSize = 0x300000;
  644. Chk=0;
  645. ptr=(unsigned char *)UsrData;
  646. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  647. {
  648. memset(BufTmp,0,MtdBlockSize);
  649. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  650. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  651. Chk+=*(BufTmp+i);
  652. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  653. // Output configuration to file.
  654. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  655. if (fd < 0)
  656. {
  657. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  658. free(BufTmp);
  659. return 0;
  660. }
  661. wrd=write(fd, BufTmp, MtdBlockSize);
  662. close(fd);
  663. if(wrd<MtdBlockSize)
  664. {
  665. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  666. free(BufTmp);
  667. return 0;
  668. }
  669. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  670. DEBUG_INFO("Erase /dev/mtd10.\n");
  671. runShellCmd("flash_erase /dev/mtd10 0 0");
  672. DEBUG_INFO("Write /dev/mtd10.\n");
  673. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  674. DEBUG_INFO("Erase /dev/mtd11.\n");
  675. runShellCmd("flash_erase /dev/mtd11 0 0");
  676. DEBUG_INFO("Write /dev/mtd11.\n");
  677. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  678. system("rm -f /mnt/EvseConfig.bin");
  679. DEBUG_INFO("EvseConfig write to flash OK\n");
  680. }
  681. else
  682. {
  683. DEBUG_ERROR("alloc BlockSize NG\r\n");
  684. result = FAIL;
  685. }
  686. if(BufTmp!=NULL)
  687. free(BufTmp);
  688. return result;
  689. }
  690. //=========================================
  691. // Sqlite3 related function
  692. //=========================================
  693. static int selectSqlCount = 0;
  694. static int callback(void *data, int argc, char **argv, char **azColName){
  695. int i;
  696. //printf("%s: ", (const char*)data);
  697. selectSqlCount = argc;
  698. for(i = 0; i<argc; i++){
  699. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  700. }
  701. //printf("\n");
  702. return 0;
  703. }
  704. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  705. //int i;
  706. //printf("%s:\n", (const char*)data);
  707. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  708. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  709. return 0;
  710. }
  711. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  712. //printf("%s:\n", (const char*)data);
  713. //idTag
  714. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  715. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  716. //parentIdTag
  717. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  718. //expir_date
  719. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  720. //status
  721. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  722. //version
  723. if(columenCount > 5)
  724. idTagQuery.listVersionInt = atoi(columnValue[5]);
  725. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  726. return 0;
  727. }
  728. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  729. {
  730. // localversion = argv[5] ? atoi(argv[5]) : 0;
  731. // printf("localversion=%d\n", localversion);
  732. return 0;
  733. }
  734. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  735. {
  736. for (int i = 0; i < n_columns; i++)
  737. {
  738. DEBUG_INFO("%s\t", col_values[i]);
  739. }
  740. DEBUG_INFO("\n");
  741. return 0;
  742. }
  743. int OCPP_cleanLocalCache()
  744. {
  745. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  746. char *errMsg = 0;
  747. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  748. if (SQLITE_OK != rc)
  749. {
  750. DEBUG_INFO("SQL error: %s\n",errMsg);
  751. return FALSE;
  752. }
  753. return TRUE;
  754. }
  755. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  756. {
  757. int isSuccess = TRUE;
  758. int ret = 0;
  759. //const char* data = "Callback function called";
  760. char sql[300];
  761. char zErrMsg[200];
  762. memset(sql, 0, 300);
  763. memset(zErrMsg, 0, 200);
  764. sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
  765. //* Execute SQL statement */
  766. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  767. if( ret != SQLITE_OK )
  768. {
  769. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  770. isSuccess = FALSE;
  771. }
  772. return isSuccess;
  773. }
  774. void OCPP_getIdTagFromLocalCache(char idTag[])
  775. {
  776. int rc = 0;
  777. char sql[100];
  778. char zErrMsg[100];
  779. memset(sql, 0, 100);
  780. memset(zErrMsg, 0, 100);
  781. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  782. memset(&idTagQuery, 0, sizeof(idTagQuery));
  783. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  784. /* Execute SQL statement */
  785. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  786. if( rc != SQLITE_OK )
  787. {
  788. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  789. }
  790. }
  791. void OCPP_getListVerion()
  792. {
  793. int rc = 0;
  794. // const char* data = "Callback function called";
  795. char sql[100];
  796. char zErrMsg[100];
  797. memset(sql, 0, 100);
  798. memset(zErrMsg, 0, 100);
  799. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  800. /* Execute SQL statement */
  801. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  802. if( rc != SQLITE_OK )
  803. {
  804. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  805. }
  806. }
  807. void OCPP_get_TableAuthlocalAllData(void)
  808. {
  809. int rc = 0;
  810. char sql[100];
  811. char zErrMsg[100];
  812. memset(sql, 0, 100);
  813. memset(zErrMsg, 0, 100);
  814. sprintf(sql,"select * from ocpp_auth_local ");
  815. /* Execute SQL statement */
  816. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  817. if( rc != SQLITE_OK )
  818. {
  819. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  820. }
  821. //return ver;
  822. }
  823. int OCPP_cleanLocalList()
  824. {
  825. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  826. char *errMsg = 0;
  827. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  828. if (SQLITE_OK != rc)
  829. {
  830. DEBUG_INFO("%s\n",errMsg);
  831. return FALSE;
  832. }
  833. return TRUE;
  834. }
  835. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  836. {
  837. int isSuccess = FALSE;
  838. int ret = 0;
  839. //const char* data = "Callback function called";
  840. char sql[300];
  841. char zErrMsg[200];
  842. memset(sql, 0, 300);
  843. memset(zErrMsg, 0, 200);
  844. sprintf(sql,"insert or replace into ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ""SELECT * from ocpp_auth_local", idTag, parentTage, expiryDate, status, version);
  845. //* Execute SQL statement */
  846. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  847. if( ret != SQLITE_OK )
  848. {
  849. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  850. return isSuccess;
  851. }
  852. memset(sql, 0, 300);
  853. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  854. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  855. if( ret != SQLITE_OK )
  856. {
  857. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  858. return isSuccess;
  859. }
  860. isSuccess = TRUE;
  861. return isSuccess;
  862. }
  863. void OCPP_getIdTagFromLocalList(char idTag[])
  864. {
  865. int rc = 0;
  866. // const char* data = "Callback function called";
  867. char sql[100];
  868. char zErrMsg[100];
  869. memset(sql, 0, 100);
  870. memset(zErrMsg, 0, 100);
  871. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  872. memset(&idTagQuery, 0, sizeof(idTagQuery));
  873. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  874. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  875. /* Execute SQL statement */
  876. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  877. if( rc != SQLITE_OK )
  878. {
  879. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  880. }
  881. //return ver;
  882. }
  883. void OCPP_deleteIdTagFromLocalList(char idTag[])
  884. {
  885. //int ver = 0;
  886. //int isSuccess = FALSE;
  887. int rc = 0;
  888. char sql[100];
  889. char zErrMsg[100];
  890. memset(sql, 0, 100);
  891. memset(zErrMsg, 0, 100);
  892. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  893. //* Execute SQL statement */
  894. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  895. if( rc != SQLITE_OK )
  896. {
  897. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  898. }
  899. }
  900. int getCurrentYear()
  901. {
  902. int result = 0;
  903. time_t CurrentTime;
  904. struct tm *tm;
  905. CurrentTime = time(NULL);
  906. tm=localtime(&CurrentTime);
  907. result = (tm->tm_year + 1900);
  908. return result;
  909. }
  910. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  911. {
  912. int result = PASS;
  913. char* errMsg = NULL;
  914. char sqlStr[8192];
  915. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  916. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  917. {
  918. result = FAIL;
  919. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  920. }
  921. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  922. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  923. {
  924. result = FAIL;
  925. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  926. }
  927. return result;
  928. }
  929. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  930. {
  931. int isSuccess = TRUE;
  932. int tempIndex;
  933. json_object *EnergyDataTransfer = json_object_new_object();
  934. json_object *periodEnergys = json_object_new_object();
  935. char sql[1024];
  936. char zErrMsg[200];
  937. memset(sql, 0, ARRAY_SIZE(sql));
  938. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  939. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  940. {
  941. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  942. {
  943. tempIndex = ((gun_index==2) ? 1: 0);
  944. }
  945. else
  946. {
  947. tempIndex = gun_index;
  948. }
  949. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  950. {
  951. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  952. {
  953. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  954. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  955. {
  956. uint8_t period[3];
  957. sprintf((char*)period, "%d", idxPeriod);
  958. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  959. }
  960. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  961. } //end of the same index
  962. }//end of for CHAdeMO_QUANTITY
  963. }
  964. else if(gunType[gun_index] == GUN_TYPE_CCS)
  965. {
  966. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  967. {
  968. tempIndex = ((gun_index==2) ? 1: 0);
  969. }
  970. else
  971. {
  972. tempIndex = gun_index;
  973. }
  974. for (int index = 0; index < CCS_QUANTITY; index++)
  975. {
  976. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  977. {
  978. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  979. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  980. {
  981. uint8_t period[3];
  982. sprintf((char*)period, "%d", idxPeriod);
  983. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  984. }
  985. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  986. } //end of the same index
  987. } // end of for CCS_QUANTITY
  988. }
  989. else if(gunType[gun_index] == GUN_TYPE_GBT)
  990. {
  991. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  992. {
  993. tempIndex = ((gun_index==2) ? 1: 0);
  994. }
  995. else
  996. {
  997. tempIndex = gun_index;
  998. }
  999. for (int index = 0; index < GB_QUANTITY; index++)
  1000. {
  1001. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1002. {
  1003. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1004. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1005. {
  1006. uint8_t period[3];
  1007. sprintf((char*)period, "%d", idxPeriod);
  1008. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1009. }
  1010. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1011. } //end of the same index
  1012. } // end of for GB_QUANTITY
  1013. }
  1014. else if(gunType[gun_index] == GUN_TYPE_DO)
  1015. {
  1016. tempIndex = gun_index;
  1017. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1018. {
  1019. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1020. {
  1021. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1022. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1023. {
  1024. uint8_t period[3];
  1025. sprintf((char*)period, "%d", idxPeriod);
  1026. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1027. }
  1028. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1029. } //end of the same index
  1030. }
  1031. }
  1032. else
  1033. {
  1034. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1035. {
  1036. tempIndex = 2;
  1037. }
  1038. else
  1039. {
  1040. tempIndex = gun_index;
  1041. }
  1042. for (int index = 0; index < AC_QUANTITY; index++)
  1043. {
  1044. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1045. {
  1046. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1047. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1048. {
  1049. uint8_t period[3];
  1050. sprintf((char*)period, "%d", idxPeriod);
  1051. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1052. }
  1053. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1054. }//end of the same index
  1055. }//end of for AC_QUANTITY
  1056. }
  1057. sprintf(sql, "insert or replace into ocpp_period_energy (transactionId, connectorId, occurDatetime, periodEnergy) VALUES ('%d', '%d', CURRENT_TIMESTAMP, '%s');", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, (gun_index+1), json_object_to_json_string_ext(EnergyDataTransfer, JSON_C_TO_STRING_PLAIN));
  1058. json_object_put(EnergyDataTransfer);
  1059. //* Execute SQL statement */
  1060. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1061. {
  1062. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1063. isSuccess = FALSE;
  1064. }
  1065. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1066. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1067. {
  1068. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1069. isSuccess = FALSE;
  1070. }
  1071. return isSuccess;
  1072. }
  1073. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1074. {
  1075. int isSuccess = TRUE;
  1076. char sql[512];
  1077. char zErrMsg[200];
  1078. int rows, cols;
  1079. char **resultData;
  1080. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1081. /* Execute SQL statement */
  1082. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1083. {
  1084. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1085. isSuccess = FALSE;
  1086. }
  1087. else
  1088. {
  1089. if((rows > 0) && (atoi(resultData[4]) > 0))
  1090. {
  1091. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1092. }
  1093. else
  1094. {
  1095. DEBUG_WARN("There is not match transaction data.\n");
  1096. isSuccess = FALSE;
  1097. }
  1098. }
  1099. return isSuccess;
  1100. }
  1101. int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice)
  1102. {
  1103. int result = PASS;
  1104. char* errMsg = NULL;
  1105. char sqlStr[8192];
  1106. sprintf(sqlStr, "insert into report_deduct_info(transactionId, creditNo, deductResult, isDonateInvoice, isUploaded) values('%d', '%s', '%d', '%d', '0');", txId, creditNo, deductResult, isDonateInvoice);
  1107. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1108. {
  1109. result = FAIL;
  1110. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  1111. }
  1112. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  1113. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1114. {
  1115. result = FAIL;
  1116. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  1117. }
  1118. return result;
  1119. }
  1120. int OCPP_update_deduct_info(int txId, char *creditNo)
  1121. {
  1122. int result = PASS;
  1123. char* errMsg = NULL;
  1124. char sqlStr[8192];
  1125. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  1126. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1127. {
  1128. result = FAIL;
  1129. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  1130. }
  1131. return result;
  1132. }
  1133. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1134. {
  1135. json_object *deductData = json_object_new_object();
  1136. json_object_object_add(deductData, "txId", json_object_new_int(atoi(columnValue[1])));
  1137. json_object_object_add(deductData, "creditNo", json_object_new_string(columnValue[2]));
  1138. json_object_object_add(deductData, "deductResult", json_object_new_boolean(atoi(columnValue[3])));
  1139. json_object_object_add(deductData, "isDonateInvoice", json_object_new_boolean(atoi(columnValue[4])));
  1140. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1141. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"ID_CreditDeductResult");
  1142. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(deductData, JSON_C_TO_STRING_PLAIN));
  1143. json_object_put(deductData);
  1144. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1145. return 0;
  1146. }
  1147. void OCPP_query_deduct_info()
  1148. {
  1149. int rc = 0;
  1150. char sql[100];
  1151. char zErrMsg[100];
  1152. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1153. /* Execute SQL statement */
  1154. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1155. if( rc != SQLITE_OK )
  1156. {
  1157. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1158. }
  1159. }
  1160. //==========================================
  1161. // Check time passed since today
  1162. //==========================================
  1163. long long DiffTimebWithNow(struct timeb ST)
  1164. {
  1165. //return milli-second
  1166. struct timeb ET;
  1167. long long StartTime,StopTime;
  1168. ftime(&ET);
  1169. StartTime=(long long)ST.time;
  1170. StopTime=(long long)ET.time;
  1171. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1172. }
  1173. int getTimePassSinceToday(uint8_t gun_index)
  1174. {
  1175. int result = -1;
  1176. static time_t lastTime[4];
  1177. time_t t;
  1178. struct tm *tmStartToday;
  1179. struct timeb tbStartToday;
  1180. t=time(NULL);
  1181. if(difftime(t, lastTime[gun_index])>0)
  1182. {
  1183. tmStartToday=localtime(&t);
  1184. tmStartToday->tm_hour = 0;
  1185. tmStartToday->tm_min = 0;
  1186. tmStartToday->tm_sec = 0;
  1187. tbStartToday.time = mktime(tmStartToday);
  1188. tbStartToday.millitm = 0;
  1189. result = DiffTimebWithNow(tbStartToday)/1000;
  1190. lastTime[gun_index] = t;
  1191. }
  1192. return result;
  1193. }
  1194. void getNowDatetime(uint8_t *data)
  1195. {
  1196. time_t t = time(NULL);
  1197. struct tm tm = *localtime(&t);
  1198. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  1199. }
  1200. int syncDateTimeRTC(uint8_t *data)
  1201. {
  1202. struct ParsingResult
  1203. {
  1204. int result;
  1205. int scanedElement;
  1206. int year;
  1207. int month;
  1208. int mday;
  1209. int hour;
  1210. int min;
  1211. int sec;
  1212. int tz_hour;
  1213. int tz_min;
  1214. float minSec;
  1215. }result;
  1216. struct tm tmOrg;
  1217. struct tm *tmTarget;
  1218. struct timeb tbTarget;
  1219. char buf[128];
  1220. memset(&result, 0x00, sizeof(struct ParsingResult));
  1221. result.result = PASS;
  1222. if(strstr((char*)data, ".") != NULL)
  1223. {
  1224. // Original data with mini second
  1225. if(strstr((char*)data, "Z") != NULL)
  1226. {
  1227. // Original data with Z
  1228. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1229. &result.year,
  1230. &result.month,
  1231. &result.mday,
  1232. &result.hour,
  1233. &result.min,
  1234. &result.sec,
  1235. &result.minSec);
  1236. }
  1237. else
  1238. {
  1239. // Original data without Z
  1240. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1241. &result.year,
  1242. &result.month,
  1243. &result.mday,
  1244. &result.hour,
  1245. &result.min,
  1246. &result.sec,
  1247. &result.minSec,
  1248. &result.tz_hour,
  1249. &result.tz_min);
  1250. }
  1251. }
  1252. else
  1253. {
  1254. // Original data without mini second
  1255. if(strstr((char*)data, "Z") != NULL)
  1256. {
  1257. // Original data with Z
  1258. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1259. &result.year,
  1260. &result.month,
  1261. &result.mday,
  1262. &result.hour,
  1263. &result.min,
  1264. &result.sec);
  1265. }
  1266. else
  1267. {
  1268. // Original data without Z
  1269. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1270. &result.year,
  1271. &result.month,
  1272. &result.mday,
  1273. &result.hour,
  1274. &result.min,
  1275. &result.sec,
  1276. &result.tz_hour,
  1277. &result.tz_min);
  1278. }
  1279. }
  1280. tmOrg.tm_year = result.year - 1900;
  1281. tmOrg.tm_mon = result.month - 1;
  1282. tmOrg.tm_mday = result.mday;
  1283. tmOrg.tm_hour = result.hour;
  1284. tmOrg.tm_min = result.min;
  1285. tmOrg.tm_sec = result.sec;
  1286. tmOrg.tm_gmtoff = 0;
  1287. tbTarget.time = mktime(&tmOrg);
  1288. tbTarget.timezone = 0;
  1289. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1290. tmTarget = gmtime(&tbTarget.time);
  1291. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  1292. //DEBUG_INFO(" org date time: %s\n", data);
  1293. //DEBUG_INFO("parse date time: %s\n", buf);
  1294. system(buf);
  1295. system("/sbin/hwclock -w --systohc");
  1296. if(result.scanedElement < 6)
  1297. result.result = FAIL;
  1298. return result.result;
  1299. }
  1300. //==========================================
  1301. // GetCompositeSchedule logic related function
  1302. //==========================================
  1303. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1304. {
  1305. //return milli-second
  1306. unsigned int StartTime,StopTime;
  1307. StartTime=(unsigned int)ST.time;
  1308. StopTime=(unsigned int)ET.time;
  1309. return (StopTime-StartTime);
  1310. }
  1311. int DiffTimebWithNowSec(struct timeb ST)
  1312. {
  1313. //return milli-second
  1314. struct timeb ET;
  1315. unsigned int StartTime,StopTime;
  1316. ftime(&ET);
  1317. StartTime=(unsigned int)ST.time;
  1318. StopTime=(unsigned int)ET.time;
  1319. return (StopTime-StartTime);
  1320. }
  1321. int getStartStop(uint8_t *start, uint8_t *stop)
  1322. {
  1323. int result = -1;
  1324. struct tm tmStart;
  1325. struct timeb tbStart;
  1326. struct tm tmStop;
  1327. struct timeb tbStop;
  1328. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  1329. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  1330. {
  1331. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  1332. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  1333. tmStart.tm_year -= 1900;
  1334. tmStart.tm_mon -= 1;
  1335. tbStart.time = mktime(&tmStart);
  1336. tbStart.millitm = 0;
  1337. tmStop.tm_year -= 1900;
  1338. tmStop.tm_mon -= 1;
  1339. tbStop.time = mktime(&tmStop);
  1340. tbStop.millitm = 0;
  1341. result = DiffTimebSec(tbStart, tbStop);
  1342. //DEBUG_INFO("getStartStop(): %d\n", result);
  1343. }
  1344. else
  1345. {
  1346. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1347. }
  1348. return result;
  1349. }
  1350. int isOvertNow(uint8_t *start)
  1351. {
  1352. int result = NO;
  1353. struct ParsingResult
  1354. {
  1355. int result;
  1356. int scanedElement;
  1357. int year;
  1358. int month;
  1359. int mday;
  1360. int hour;
  1361. int min;
  1362. int sec;
  1363. int tz_hour;
  1364. int tz_min;
  1365. float minSec;
  1366. }parsingResult;
  1367. struct tm tmStart;
  1368. struct timeb tbStart;
  1369. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1370. if(strstr((char*)start, ".") != NULL)
  1371. {
  1372. // Original data with mini second
  1373. if(strstr((char*)start, "Z") != NULL)
  1374. {
  1375. // Original data with Z
  1376. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1377. &parsingResult.year,
  1378. &parsingResult.month,
  1379. &parsingResult.mday,
  1380. &parsingResult.hour,
  1381. &parsingResult.min,
  1382. &parsingResult.sec,
  1383. &parsingResult.minSec);
  1384. }
  1385. else
  1386. {
  1387. // Original data without Z
  1388. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1389. &parsingResult.year,
  1390. &parsingResult.month,
  1391. &parsingResult.mday,
  1392. &parsingResult.hour,
  1393. &parsingResult.min,
  1394. &parsingResult.sec,
  1395. &parsingResult.minSec,
  1396. &parsingResult.tz_hour,
  1397. &parsingResult.tz_min);
  1398. }
  1399. }
  1400. else
  1401. {
  1402. // Original data without mini second
  1403. if(strstr((char*)start, "Z") != NULL)
  1404. {
  1405. // Original data with Z
  1406. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1407. &parsingResult.year,
  1408. &parsingResult.month,
  1409. &parsingResult.mday,
  1410. &parsingResult.hour,
  1411. &parsingResult.min,
  1412. &parsingResult.sec);
  1413. }
  1414. else
  1415. {
  1416. // Original data without Z
  1417. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1418. &parsingResult.year,
  1419. &parsingResult.month,
  1420. &parsingResult.mday,
  1421. &parsingResult.hour,
  1422. &parsingResult.min,
  1423. &parsingResult.sec,
  1424. &parsingResult.tz_hour,
  1425. &parsingResult.tz_min);
  1426. }
  1427. }
  1428. if(parsingResult.scanedElement >= 6)
  1429. {
  1430. tmStart.tm_year = parsingResult.year - 1900;
  1431. tmStart.tm_mon = parsingResult.month - 1;
  1432. tmStart.tm_mday = parsingResult.mday;
  1433. tmStart.tm_hour = parsingResult.hour;
  1434. tmStart.tm_min = parsingResult.min;
  1435. tmStart.tm_sec = parsingResult.sec;
  1436. tmStart.tm_gmtoff = 0;
  1437. tbStart.time = mktime(&tmStart);
  1438. tbStart.timezone = 0;
  1439. tbStart.millitm = 0;
  1440. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1441. if(DiffTimebWithNowSec(tbStart) <= 0)
  1442. result = NO;
  1443. else
  1444. result = YES;
  1445. }
  1446. else
  1447. {
  1448. DEBUG_WARN("Start date parsing error.\n");
  1449. }
  1450. return result;
  1451. }
  1452. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1453. {
  1454. int result = -1;
  1455. struct tm tmStart;
  1456. struct timeb tbStart;
  1457. struct tm tmStop;
  1458. struct timeb tbStop;
  1459. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  1460. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  1461. {
  1462. tmStart.tm_year -= 1900;
  1463. tmStart.tm_mon -= 1;
  1464. tbStart.time = mktime(&tmStart);
  1465. tbStart.millitm = 0;
  1466. tmStop.tm_year -= 1900;
  1467. tmStop.tm_mon -= 1;
  1468. tbStop.time = mktime(&tmStop);
  1469. tbStop.millitm = 0;
  1470. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1471. }
  1472. return result;
  1473. }
  1474. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1475. {
  1476. FILE *fp;
  1477. char profileFileName[128];
  1478. char *line = NULL;
  1479. size_t len = 0;
  1480. time_t CurrentTime;
  1481. struct tm *tmComposite;
  1482. struct StructChargingProfile maxProfile;
  1483. uint8_t limitMax=0;
  1484. int compositePeriodIdx = 0;
  1485. CurrentTime = time(NULL);
  1486. tmComposite=localtime(&CurrentTime);
  1487. sprintf((char*)compositeProfile->ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  1488. if(isUnitA)
  1489. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1490. else
  1491. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1492. compositeProfile->ChargingSchedule.Duration = durationReq;
  1493. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1494. {
  1495. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1496. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1497. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1498. }
  1499. compositeProfile->ChargingProfileId = 0;
  1500. compositeProfile->StackLevel = 99 ;
  1501. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1502. maxProfile.ChargingProfileId = -1;
  1503. maxProfile.ChargingSchedule.Duration = -1;
  1504. system("rm -f /tmp/*.json");
  1505. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1506. // Search max profile
  1507. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1508. if((access(profileFileName, F_OK))!=-1)
  1509. {
  1510. fp = fopen(profileFileName, "r");
  1511. while(getline(&line, &len, fp) != -1)
  1512. {
  1513. json_object *obj = NULL;
  1514. obj = json_tokener_parse(line);
  1515. if(is_error(obj))
  1516. {
  1517. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1518. }
  1519. else
  1520. {
  1521. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1522. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1523. )
  1524. {
  1525. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1526. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1527. )
  1528. {
  1529. struct tm tmFrom, tmTo;
  1530. struct timeb tbFrom, tbTo;
  1531. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1532. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1533. {
  1534. tmFrom.tm_year -= 1900;
  1535. tmFrom.tm_mon -= 1;
  1536. tbFrom.time = mktime(&tmFrom);
  1537. tmTo.tm_year -= 1900;
  1538. tmTo.tm_mon -= 1;
  1539. tbTo.time = mktime(&tmTo);
  1540. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1541. {
  1542. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1543. {
  1544. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1545. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1546. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1547. }
  1548. maxProfile.ChargingProfileId = -1;
  1549. maxProfile.StackLevel = -1;
  1550. if(maxProfile.ChargingProfileId == -1)
  1551. DEBUG_INFO("MaxProfile found.\n");
  1552. else
  1553. DEBUG_INFO("MaxProfile updated.\n");
  1554. // Required item
  1555. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1556. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1557. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1558. if(isUnitA)
  1559. {
  1560. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1561. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1562. {
  1563. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1564. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1565. 3:
  1566. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1567. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1568. }
  1569. }
  1570. else
  1571. {
  1572. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1573. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1574. {
  1575. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1576. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1577. 3:
  1578. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1579. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1580. }
  1581. }
  1582. // Optional item
  1583. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1584. {
  1585. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1586. }
  1587. else
  1588. {
  1589. sprintf((char*)maxProfile.ValidFrom, " ");
  1590. }
  1591. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1592. {
  1593. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1594. }
  1595. else
  1596. {
  1597. sprintf((char*)maxProfile.ValidTo, " ");
  1598. }
  1599. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1600. {
  1601. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1602. }
  1603. else
  1604. {
  1605. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1606. }
  1607. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1608. {
  1609. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1610. }
  1611. else
  1612. {
  1613. maxProfile.TransactionId = -1;
  1614. }
  1615. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1616. {
  1617. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1618. }
  1619. else
  1620. {
  1621. maxProfile.ChargingSchedule.Duration = 86400;
  1622. }
  1623. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1624. {
  1625. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1626. }
  1627. else
  1628. {
  1629. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1630. }
  1631. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1632. {
  1633. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1634. }
  1635. else
  1636. {
  1637. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1638. }
  1639. }
  1640. }
  1641. }
  1642. else
  1643. {
  1644. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1645. {
  1646. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1647. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1648. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1649. }
  1650. maxProfile.ChargingProfileId = -1;
  1651. maxProfile.StackLevel = -1;
  1652. if(maxProfile.ChargingProfileId == -1)
  1653. DEBUG_INFO("MaxProfile found.\n");
  1654. else
  1655. DEBUG_INFO("MaxProfile updated.\n");
  1656. // Required item
  1657. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1658. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1659. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1660. if(isUnitA)
  1661. {
  1662. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1663. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1664. {
  1665. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1666. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1667. 3:
  1668. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1669. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1670. }
  1671. }
  1672. else
  1673. {
  1674. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1675. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1676. {
  1677. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1678. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1679. 3:
  1680. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1681. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1682. }
  1683. }
  1684. // Optional item
  1685. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1686. {
  1687. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1688. }
  1689. else
  1690. {
  1691. sprintf((char*)maxProfile.ValidFrom, " ");
  1692. }
  1693. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1694. {
  1695. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1696. }
  1697. else
  1698. {
  1699. sprintf((char*)maxProfile.ValidTo, " ");
  1700. }
  1701. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1702. {
  1703. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1704. }
  1705. else
  1706. {
  1707. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1708. }
  1709. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1710. {
  1711. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1712. }
  1713. else
  1714. {
  1715. maxProfile.TransactionId = -1;
  1716. }
  1717. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1718. {
  1719. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1720. }
  1721. else
  1722. {
  1723. maxProfile.ChargingSchedule.Duration = 86400;
  1724. }
  1725. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1726. {
  1727. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1728. }
  1729. else
  1730. {
  1731. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1732. }
  1733. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1734. {
  1735. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1736. }
  1737. else
  1738. {
  1739. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1740. }
  1741. }
  1742. }
  1743. }
  1744. json_object_put(obj);
  1745. }
  1746. fclose(fp);
  1747. /*
  1748. if(maxProfile.ChargingProfileId !=-1)
  1749. {
  1750. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1751. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1752. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1753. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1754. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1755. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1756. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1757. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1758. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1759. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1760. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1761. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1762. {
  1763. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1764. {
  1765. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1766. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1767. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1768. }
  1769. }
  1770. }
  1771. else
  1772. DEBUG_INFO("MaxProfile not found.\n");
  1773. DEBUG_INFO("------------------------------------\n");*/
  1774. }
  1775. if(maxProfile.ChargingProfileId != -1)
  1776. {
  1777. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1778. {
  1779. if(maxProfile.ChargingSchedule.Duration != -1)
  1780. {
  1781. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1782. 0:
  1783. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1784. }
  1785. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1786. {
  1787. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1788. {
  1789. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1790. 0:
  1791. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1792. if(idxPeriod > 0)
  1793. {
  1794. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1795. {
  1796. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1797. }
  1798. }
  1799. }
  1800. }
  1801. }
  1802. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1803. {
  1804. if(maxProfile.ChargingSchedule.Duration != -1)
  1805. {
  1806. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1807. }
  1808. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1809. {
  1810. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1811. {
  1812. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1813. if(idxPeriod > 0)
  1814. {
  1815. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1816. {
  1817. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1818. }
  1819. }
  1820. }
  1821. }
  1822. }
  1823. else
  1824. {
  1825. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1826. {
  1827. if(maxProfile.ChargingSchedule.Duration != -1)
  1828. {
  1829. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1830. 0:
  1831. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1832. }
  1833. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1834. {
  1835. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1836. {
  1837. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1838. 0:
  1839. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1840. if(idxPeriod > 0)
  1841. {
  1842. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1843. {
  1844. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1845. }
  1846. }
  1847. }
  1848. }
  1849. }
  1850. else
  1851. {
  1852. if(maxProfile.ChargingSchedule.Duration != -1)
  1853. {
  1854. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1855. 0:
  1856. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1857. }
  1858. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1859. {
  1860. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1861. {
  1862. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1863. 0:
  1864. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1865. if(idxPeriod > 0)
  1866. {
  1867. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1868. {
  1869. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1870. }
  1871. }
  1872. }
  1873. }
  1874. }
  1875. }
  1876. /*
  1877. DEBUG_INFO("MaxProfile after align.\n");
  1878. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1879. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1880. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1881. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1882. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1883. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1884. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1885. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1886. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1887. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1888. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1889. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1890. {
  1891. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1892. {
  1893. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1894. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1895. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1896. }
  1897. }
  1898. DEBUG_INFO("------------------------------------\n");*/
  1899. }
  1900. // Find each profile period quantity
  1901. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1902. {
  1903. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1904. limitMax = idx+1;
  1905. }
  1906. if(maxProfile.ChargingProfileId != -1)
  1907. {
  1908. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1909. {
  1910. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1911. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1912. (maxProfile.ChargingSchedule.Duration > 0))
  1913. {
  1914. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1915. {
  1916. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1917. compositePeriodIdx++;
  1918. }
  1919. else
  1920. {
  1921. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1922. }
  1923. }
  1924. }
  1925. }
  1926. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1927. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1928. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1929. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1930. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1931. {
  1932. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1933. {
  1934. compositeProfile->ChargingProfileId = 1;
  1935. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1936. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1937. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1938. }
  1939. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1940. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1941. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1942. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1943. }
  1944. if(line)
  1945. free(line);
  1946. }
  1947. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1948. {
  1949. FILE *fp;
  1950. char profileFileName[128];
  1951. char *line = NULL;
  1952. size_t len = 0;
  1953. time_t CurrentTime;
  1954. struct tm *tmComposite;
  1955. struct StructChargingProfile maxProfile;
  1956. struct StructChargingProfile defaultTxProfile;
  1957. struct StructChargingProfile txProfile;
  1958. struct StructChargingSchedulePeriod tmpPeriod;
  1959. uint8_t limitMax=0;
  1960. uint8_t limitDef=0;
  1961. uint8_t limitTx=0;
  1962. int compositePeriodIdx = 0;
  1963. CurrentTime = time(NULL);
  1964. tmComposite=localtime(&CurrentTime);
  1965. sprintf((char*)compositeProfile->ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  1966. if(isUnitA)
  1967. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1968. else
  1969. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1970. compositeProfile->ChargingSchedule.Duration = durationReq;
  1971. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1972. {
  1973. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1974. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1975. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1976. }
  1977. compositeProfile->ChargingProfileId = 0;
  1978. compositeProfile->StackLevel = 99 ;
  1979. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1980. maxProfile.ChargingProfileId = -1;
  1981. defaultTxProfile.ChargingProfileId = -1;
  1982. txProfile.ChargingProfileId = -1;
  1983. maxProfile.ChargingSchedule.Duration = -1;
  1984. defaultTxProfile.ChargingSchedule.Duration = -1;
  1985. txProfile.ChargingSchedule.Duration = -1;
  1986. system("rm -f /tmp/*.json");
  1987. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1988. /*
  1989. * Search valid charging profile
  1990. */
  1991. //DEBUG_INFO("====================================\n");
  1992. // Search tx profile
  1993. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1994. if((access(profileFileName, F_OK))!=-1)
  1995. {
  1996. fp = fopen(profileFileName, "r");
  1997. while(getline(&line, &len, fp) != -1)
  1998. {
  1999. json_object *obj = NULL;
  2000. obj = json_tokener_parse(line);
  2001. if(is_error(obj))
  2002. {
  2003. DEBUG_ERROR("Parse txProfile from file error.\n");
  2004. }
  2005. else
  2006. {
  2007. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2008. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2009. )
  2010. {
  2011. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2012. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2013. )
  2014. {
  2015. struct tm tmFrom, tmTo;
  2016. struct timeb tbFrom, tbTo;
  2017. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  2018. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  2019. {
  2020. tmFrom.tm_year -= 1900;
  2021. tmFrom.tm_mon -= 1;
  2022. tbFrom.time = mktime(&tmFrom);
  2023. tmTo.tm_year -= 1900;
  2024. tmTo.tm_mon -= 1;
  2025. tbTo.time = mktime(&tmTo);
  2026. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2027. {
  2028. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2029. {
  2030. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2031. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2032. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2033. }
  2034. txProfile.ChargingProfileId = -1;
  2035. txProfile.StackLevel = -1;
  2036. if(txProfile.ChargingProfileId == -1)
  2037. DEBUG_INFO("TxProfile found.\n");
  2038. else
  2039. DEBUG_INFO("TxProfile updated.\n");
  2040. // Required item
  2041. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2042. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2043. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2044. if(isUnitA)
  2045. {
  2046. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2047. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2048. {
  2049. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2050. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2051. 3:
  2052. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2053. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2054. }
  2055. }
  2056. else
  2057. {
  2058. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2059. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2060. {
  2061. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2062. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2063. 3:
  2064. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2065. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2066. }
  2067. }
  2068. // Optional item
  2069. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2070. {
  2071. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2072. }
  2073. else
  2074. {
  2075. sprintf((char*)txProfile.ValidFrom, " ");
  2076. }
  2077. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2078. {
  2079. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2080. }
  2081. else
  2082. {
  2083. sprintf((char*)txProfile.ValidTo, " ");
  2084. }
  2085. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2086. {
  2087. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2088. }
  2089. else
  2090. {
  2091. sprintf((char*)txProfile.RecurrencyKind, " ");
  2092. }
  2093. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2094. {
  2095. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2096. }
  2097. else
  2098. {
  2099. txProfile.TransactionId = -1;
  2100. }
  2101. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2102. {
  2103. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2104. }
  2105. else
  2106. {
  2107. txProfile.ChargingSchedule.Duration = 86400;
  2108. }
  2109. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2110. {
  2111. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2112. }
  2113. else
  2114. {
  2115. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2116. }
  2117. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2118. {
  2119. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2120. }
  2121. else
  2122. {
  2123. txProfile.ChargingSchedule.MinChargingRate = -1;
  2124. }
  2125. }
  2126. }
  2127. }
  2128. else
  2129. {
  2130. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2131. {
  2132. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2133. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2134. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2135. }
  2136. txProfile.ChargingProfileId = -1;
  2137. txProfile.StackLevel = -1;
  2138. if(txProfile.ChargingProfileId == -1)
  2139. DEBUG_INFO("TxProfile found.\n");
  2140. else
  2141. DEBUG_INFO("TxProfile updated.\n");
  2142. // Required item
  2143. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2144. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2145. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2146. if(isUnitA)
  2147. {
  2148. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2149. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2150. {
  2151. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2152. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2153. 3:
  2154. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2155. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2156. }
  2157. }
  2158. else
  2159. {
  2160. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2161. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2162. {
  2163. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2164. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2165. 3:
  2166. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2167. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2168. }
  2169. }
  2170. // Optional item
  2171. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2172. {
  2173. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2174. }
  2175. else
  2176. {
  2177. sprintf((char*)txProfile.ValidFrom, " ");
  2178. }
  2179. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2180. {
  2181. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2182. }
  2183. else
  2184. {
  2185. sprintf((char*)txProfile.ValidTo, " ");
  2186. }
  2187. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2188. {
  2189. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2190. }
  2191. else
  2192. {
  2193. sprintf((char*)txProfile.RecurrencyKind, " ");
  2194. }
  2195. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2196. {
  2197. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2198. }
  2199. else
  2200. {
  2201. txProfile.TransactionId = -1;
  2202. }
  2203. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2204. {
  2205. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2206. }
  2207. else
  2208. {
  2209. txProfile.ChargingSchedule.Duration = 86400;
  2210. }
  2211. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2212. {
  2213. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2214. }
  2215. else
  2216. {
  2217. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2218. }
  2219. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2220. {
  2221. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2222. }
  2223. else
  2224. {
  2225. txProfile.ChargingSchedule.MinChargingRate = -1;
  2226. }
  2227. }
  2228. }
  2229. }
  2230. json_object_put(obj);
  2231. }
  2232. fclose(fp);
  2233. /*
  2234. if(txProfile.ChargingProfileId != -1)
  2235. {
  2236. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2237. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2238. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2239. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2240. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2241. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2242. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2243. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2244. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2245. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2246. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2247. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2248. {
  2249. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2250. {
  2251. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2252. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2253. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2254. }
  2255. }
  2256. }
  2257. else
  2258. DEBUG_INFO("TxProfile not found.\n");*/
  2259. }
  2260. // Search default tx profile
  2261. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2262. if((access(profileFileName, F_OK))==-1)
  2263. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2264. if((access(profileFileName, F_OK))!=-1)
  2265. {
  2266. fp = fopen(profileFileName, "r");
  2267. while(getline(&line, &len, fp) != -1)
  2268. {
  2269. json_object *obj = NULL;
  2270. obj = json_tokener_parse(line);
  2271. if(is_error(obj))
  2272. {
  2273. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2274. }
  2275. else
  2276. {
  2277. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2278. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2279. )
  2280. {
  2281. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2282. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2283. )
  2284. {
  2285. struct tm tmFrom, tmTo;
  2286. struct timeb tbFrom, tbTo;
  2287. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  2288. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  2289. {
  2290. tmFrom.tm_year -= 1900;
  2291. tmFrom.tm_mon -= 1;
  2292. tbFrom.time = mktime(&tmFrom);
  2293. tmTo.tm_year -= 1900;
  2294. tmTo.tm_mon -= 1;
  2295. tbTo.time = mktime(&tmTo);
  2296. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2297. {
  2298. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2299. {
  2300. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2301. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2302. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2303. }
  2304. defaultTxProfile.ChargingProfileId = -1;
  2305. defaultTxProfile.StackLevel = -1;
  2306. if(defaultTxProfile.ChargingProfileId == -1)
  2307. DEBUG_INFO("TxDefaultProfile found.\n");
  2308. else
  2309. DEBUG_INFO("TxDefaultProfile updated.\n");
  2310. // Required item
  2311. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2312. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2313. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2314. if(isUnitA)
  2315. {
  2316. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2317. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2318. {
  2319. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2320. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2321. 3:
  2322. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2323. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2324. }
  2325. }
  2326. else
  2327. {
  2328. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2329. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2330. {
  2331. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2332. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2333. 3:
  2334. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2335. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2336. }
  2337. }
  2338. // Optional item
  2339. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2340. {
  2341. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2342. }
  2343. else
  2344. {
  2345. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2346. }
  2347. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2348. {
  2349. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2350. }
  2351. else
  2352. {
  2353. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2354. }
  2355. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2356. {
  2357. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2358. }
  2359. else
  2360. {
  2361. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2362. }
  2363. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2364. {
  2365. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2366. }
  2367. else
  2368. {
  2369. defaultTxProfile.TransactionId = -1;
  2370. }
  2371. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2372. {
  2373. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2374. }
  2375. else
  2376. {
  2377. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2378. }
  2379. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2380. {
  2381. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2382. }
  2383. else
  2384. {
  2385. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2386. }
  2387. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2388. {
  2389. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2390. }
  2391. else
  2392. {
  2393. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2394. }
  2395. }
  2396. }
  2397. }
  2398. else
  2399. {
  2400. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2401. {
  2402. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2403. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2404. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2405. }
  2406. defaultTxProfile.ChargingProfileId = -1;
  2407. defaultTxProfile.StackLevel = -1;
  2408. if(defaultTxProfile.ChargingProfileId == -1)
  2409. DEBUG_INFO("TxDefaultProfile found.\n");
  2410. else
  2411. DEBUG_INFO("TxDefaultProfile updated.\n");
  2412. // Required item
  2413. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2414. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2415. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2416. if(isUnitA)
  2417. {
  2418. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2419. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2420. {
  2421. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2422. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2423. 3:
  2424. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2425. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2426. }
  2427. }
  2428. else
  2429. {
  2430. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2431. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2432. {
  2433. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2434. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2435. 3:
  2436. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2437. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2438. }
  2439. }
  2440. // Optional item
  2441. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2442. {
  2443. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2444. }
  2445. else
  2446. {
  2447. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2448. }
  2449. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2450. {
  2451. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2452. }
  2453. else
  2454. {
  2455. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2456. }
  2457. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2458. {
  2459. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2460. }
  2461. else
  2462. {
  2463. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2464. }
  2465. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2466. {
  2467. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2468. }
  2469. else
  2470. {
  2471. defaultTxProfile.TransactionId = -1;
  2472. }
  2473. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2474. {
  2475. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2476. }
  2477. else
  2478. {
  2479. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2480. }
  2481. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2482. {
  2483. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2484. }
  2485. else
  2486. {
  2487. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2488. }
  2489. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2490. {
  2491. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2492. }
  2493. else
  2494. {
  2495. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2496. }
  2497. }
  2498. }
  2499. }
  2500. json_object_put(obj);
  2501. }
  2502. fclose(fp);
  2503. /*
  2504. if(defaultTxProfile.ChargingProfileId != -1)
  2505. {
  2506. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2507. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2508. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2509. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2510. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2511. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2512. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2513. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2514. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2515. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2516. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2517. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2518. {
  2519. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2520. {
  2521. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2522. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2523. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2524. }
  2525. }
  2526. }
  2527. else
  2528. DEBUG_INFO("TxDefaultProfile not found.\n");
  2529. DEBUG_INFO("------------------------------------\n");*/
  2530. }
  2531. // Search max profile
  2532. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2533. if((access(profileFileName, F_OK))!=-1)
  2534. {
  2535. fp = fopen(profileFileName, "r");
  2536. while(getline(&line, &len, fp) != -1)
  2537. {
  2538. json_object *obj = NULL;
  2539. obj = json_tokener_parse(line);
  2540. if(is_error(obj))
  2541. {
  2542. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2543. }
  2544. else
  2545. {
  2546. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2547. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2548. )
  2549. {
  2550. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2551. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2552. )
  2553. {
  2554. struct tm tmFrom, tmTo;
  2555. struct timeb tbFrom, tbTo;
  2556. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  2557. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  2558. {
  2559. tmFrom.tm_year -= 1900;
  2560. tmFrom.tm_mon -= 1;
  2561. tbFrom.time = mktime(&tmFrom);
  2562. tmTo.tm_year -= 1900;
  2563. tmTo.tm_mon -= 1;
  2564. tbTo.time = mktime(&tmTo);
  2565. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2566. {
  2567. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2568. {
  2569. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2570. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2571. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2572. }
  2573. maxProfile.ChargingProfileId = -1;
  2574. maxProfile.StackLevel = -1;
  2575. if(maxProfile.ChargingProfileId == -1)
  2576. DEBUG_INFO("MaxProfile found.\n");
  2577. else
  2578. DEBUG_INFO("MaxProfile updated.\n");
  2579. // Required item
  2580. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2581. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2582. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2583. if(isUnitA)
  2584. {
  2585. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2586. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2587. {
  2588. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2589. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2590. 3:
  2591. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2592. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2593. }
  2594. }
  2595. else
  2596. {
  2597. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2598. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2599. {
  2600. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2601. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2602. 3:
  2603. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2604. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2605. }
  2606. }
  2607. // Optional item
  2608. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2609. {
  2610. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2611. }
  2612. else
  2613. {
  2614. sprintf((char*)maxProfile.ValidFrom, " ");
  2615. }
  2616. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2617. {
  2618. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2619. }
  2620. else
  2621. {
  2622. sprintf((char*)maxProfile.ValidTo, " ");
  2623. }
  2624. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2625. {
  2626. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2627. }
  2628. else
  2629. {
  2630. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2631. }
  2632. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2633. {
  2634. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2635. }
  2636. else
  2637. {
  2638. maxProfile.TransactionId = -1;
  2639. }
  2640. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2641. {
  2642. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2643. }
  2644. else
  2645. {
  2646. maxProfile.ChargingSchedule.Duration = 86400;
  2647. }
  2648. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2649. {
  2650. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2651. }
  2652. else
  2653. {
  2654. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2655. }
  2656. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2657. {
  2658. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2659. }
  2660. else
  2661. {
  2662. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2663. }
  2664. }
  2665. }
  2666. }
  2667. else
  2668. {
  2669. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2670. {
  2671. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2672. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2673. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2674. }
  2675. maxProfile.ChargingProfileId = -1;
  2676. maxProfile.StackLevel = -1;
  2677. if(maxProfile.ChargingProfileId == -1)
  2678. DEBUG_INFO("MaxProfile found.\n");
  2679. else
  2680. DEBUG_INFO("MaxProfile updated.\n");
  2681. // Required item
  2682. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2683. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2684. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2685. if(isUnitA)
  2686. {
  2687. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2688. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2689. {
  2690. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2691. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2692. 3:
  2693. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2694. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2695. }
  2696. }
  2697. else
  2698. {
  2699. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2700. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2701. {
  2702. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2703. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2704. 3:
  2705. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2706. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2707. }
  2708. }
  2709. // Optional item
  2710. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2711. {
  2712. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2713. }
  2714. else
  2715. {
  2716. sprintf((char*)maxProfile.ValidFrom, " ");
  2717. }
  2718. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2719. {
  2720. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2721. }
  2722. else
  2723. {
  2724. sprintf((char*)maxProfile.ValidTo, " ");
  2725. }
  2726. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2727. {
  2728. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2729. }
  2730. else
  2731. {
  2732. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2733. }
  2734. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2735. {
  2736. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2737. }
  2738. else
  2739. {
  2740. maxProfile.TransactionId = -1;
  2741. }
  2742. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2743. {
  2744. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2745. }
  2746. else
  2747. {
  2748. maxProfile.ChargingSchedule.Duration = 86400;
  2749. }
  2750. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2751. {
  2752. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2753. }
  2754. else
  2755. {
  2756. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2757. }
  2758. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2759. {
  2760. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2761. }
  2762. else
  2763. {
  2764. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2765. }
  2766. }
  2767. }
  2768. }
  2769. json_object_put(obj);
  2770. }
  2771. fclose(fp);
  2772. /*
  2773. if(maxProfile.ChargingProfileId !=-1)
  2774. {
  2775. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2776. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2777. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2778. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2779. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2780. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2781. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2782. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2783. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2784. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2785. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2786. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2787. {
  2788. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2789. {
  2790. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2791. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2792. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2793. }
  2794. }
  2795. }
  2796. else
  2797. DEBUG_INFO("MaxProfile not found.\n");
  2798. DEBUG_INFO("------------------------------------\n");*/
  2799. }
  2800. /*
  2801. * Align found profile start schedule & periods
  2802. */
  2803. //DEBUG_INFO("====================================\n");
  2804. /*
  2805. // For local test usage, force modify found profile start schedule info
  2806. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-10);
  2807. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-5);
  2808. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-3);
  2809. */
  2810. if(txProfile.ChargingProfileId != -1)
  2811. {
  2812. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2813. {
  2814. if(txProfile.ChargingSchedule.Duration != -1)
  2815. {
  2816. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2817. 0:
  2818. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2819. }
  2820. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2821. {
  2822. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2823. {
  2824. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2825. 0:
  2826. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2827. if(idxPeriod > 0)
  2828. {
  2829. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2830. {
  2831. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2832. }
  2833. }
  2834. }
  2835. }
  2836. }
  2837. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2838. {
  2839. if(txProfile.ChargingSchedule.Duration != -1)
  2840. {
  2841. txProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2842. 0:
  2843. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2844. }
  2845. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2846. {
  2847. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2848. {
  2849. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2850. 0:
  2851. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2852. if(idxPeriod > 0)
  2853. {
  2854. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2855. {
  2856. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2857. }
  2858. }
  2859. }
  2860. }
  2861. }
  2862. else
  2863. {
  2864. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2865. {
  2866. if(txProfile.ChargingSchedule.Duration != -1)
  2867. {
  2868. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2869. 0:
  2870. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2871. }
  2872. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2873. {
  2874. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2875. {
  2876. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2877. 0:
  2878. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2879. if(idxPeriod > 0)
  2880. {
  2881. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2882. {
  2883. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2884. }
  2885. }
  2886. }
  2887. }
  2888. }
  2889. else
  2890. {
  2891. if(txProfile.ChargingSchedule.Duration != -1)
  2892. {
  2893. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2894. 0:
  2895. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2896. }
  2897. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2898. {
  2899. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2900. {
  2901. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2902. 0:
  2903. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2904. if(idxPeriod > 0)
  2905. {
  2906. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2907. {
  2908. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2909. }
  2910. }
  2911. }
  2912. }
  2913. }
  2914. }
  2915. /*
  2916. DEBUG_INFO("txProfile after align.\n");
  2917. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2918. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2919. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2920. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2921. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2922. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2923. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2924. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2925. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2926. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2927. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2928. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2929. {
  2930. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2931. {
  2932. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2933. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2934. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2935. }
  2936. }*/
  2937. }
  2938. if(defaultTxProfile.ChargingProfileId != -1)
  2939. {
  2940. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2941. {
  2942. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2943. {
  2944. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2945. 0:
  2946. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2947. }
  2948. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2949. {
  2950. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2951. {
  2952. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2953. 0:
  2954. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2955. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2956. {
  2957. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2958. }
  2959. if(idxPeriod > 0)
  2960. {
  2961. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2962. {
  2963. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2964. }
  2965. }
  2966. }
  2967. }
  2968. }
  2969. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2970. {
  2971. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2972. {
  2973. defaultTxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2974. 0:
  2975. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2976. }
  2977. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2978. {
  2979. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2980. {
  2981. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2982. 0:
  2983. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2984. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2985. {
  2986. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2987. }
  2988. if(idxPeriod > 0)
  2989. {
  2990. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2991. {
  2992. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2993. }
  2994. }
  2995. }
  2996. }
  2997. }
  2998. else
  2999. {
  3000. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3001. {
  3002. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3003. {
  3004. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  3005. 0:
  3006. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  3007. }
  3008. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3009. {
  3010. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3011. {
  3012. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  3013. 0:
  3014. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  3015. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  3016. {
  3017. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3018. }
  3019. if(idxPeriod > 0)
  3020. {
  3021. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3022. {
  3023. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3024. }
  3025. }
  3026. }
  3027. }
  3028. }
  3029. else
  3030. {
  3031. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3032. {
  3033. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  3034. 0:
  3035. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  3036. }
  3037. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3038. {
  3039. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3040. {
  3041. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  3042. 0:
  3043. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  3044. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  3045. {
  3046. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3047. }
  3048. if(idxPeriod > 0)
  3049. {
  3050. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3051. {
  3052. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3053. }
  3054. }
  3055. }
  3056. }
  3057. }
  3058. }
  3059. /*
  3060. DEBUG_INFO("defaultTxProfile after align.\n");
  3061. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3062. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3063. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3064. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3065. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3066. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3067. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3068. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3069. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3070. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3071. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3072. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3073. {
  3074. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3075. {
  3076. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3077. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3078. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3079. }
  3080. }
  3081. DEBUG_INFO("------------------------------------\n");*/
  3082. }
  3083. if(maxProfile.ChargingProfileId != -1)
  3084. {
  3085. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3086. {
  3087. if(maxProfile.ChargingSchedule.Duration != -1)
  3088. {
  3089. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  3090. 0:
  3091. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  3092. }
  3093. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3094. {
  3095. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3096. {
  3097. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  3098. 0:
  3099. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  3100. if(idxPeriod > 0)
  3101. {
  3102. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3103. {
  3104. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3105. }
  3106. }
  3107. }
  3108. }
  3109. }
  3110. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3111. {
  3112. if(maxProfile.ChargingSchedule.Duration != -1)
  3113. {
  3114. maxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  3115. 0:
  3116. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  3117. }
  3118. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3119. {
  3120. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3121. {
  3122. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  3123. 0:
  3124. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  3125. if(idxPeriod > 0)
  3126. {
  3127. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3128. {
  3129. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3130. }
  3131. }
  3132. }
  3133. }
  3134. }
  3135. else
  3136. {
  3137. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3138. {
  3139. if(maxProfile.ChargingSchedule.Duration != -1)
  3140. {
  3141. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  3142. 0:
  3143. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  3144. }
  3145. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3146. {
  3147. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3148. {
  3149. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  3150. 0:
  3151. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  3152. if(idxPeriod > 0)
  3153. {
  3154. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3155. {
  3156. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3157. }
  3158. }
  3159. }
  3160. }
  3161. }
  3162. else
  3163. {
  3164. if(maxProfile.ChargingSchedule.Duration != -1)
  3165. {
  3166. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  3167. 0:
  3168. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  3169. }
  3170. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3171. {
  3172. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3173. {
  3174. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  3175. 0:
  3176. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  3177. if(idxPeriod > 0)
  3178. {
  3179. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3180. {
  3181. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3182. }
  3183. }
  3184. }
  3185. }
  3186. }
  3187. }
  3188. /*
  3189. DEBUG_INFO("MaxProfile after align.\n");
  3190. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3191. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3192. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3193. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3194. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3195. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3196. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3197. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3198. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3199. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3200. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3201. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3202. {
  3203. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3204. {
  3205. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3206. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3207. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3208. }
  3209. }
  3210. DEBUG_INFO("------------------------------------\n");*/
  3211. }
  3212. /*
  3213. * Merge to conposite schedule
  3214. */
  3215. //DEBUG_INFO("====================================\n");
  3216. // Find each profile period quantity
  3217. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3218. {
  3219. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3220. limitMax = idx+1;
  3221. }
  3222. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3223. {
  3224. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3225. limitDef = idx+1;
  3226. }
  3227. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3228. {
  3229. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3230. limitTx = idx+1;
  3231. }
  3232. // TxProfile found, composite schedule based on it
  3233. if(txProfile.ChargingProfileId != -1)
  3234. {
  3235. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3236. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3237. {
  3238. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3239. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3240. (txProfile.ChargingSchedule.Duration > 0))
  3241. {
  3242. if(maxProfile.ChargingProfileId != -1)
  3243. {
  3244. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3245. {
  3246. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3247. {
  3248. if((maxProfile.ChargingSchedule.Duration > 0))
  3249. {
  3250. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3251. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3252. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3253. }
  3254. else
  3255. {
  3256. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3257. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3258. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3259. }
  3260. }
  3261. if(idxMaxPeriod == (limitMax-1))
  3262. {
  3263. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3264. {
  3265. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3266. {
  3267. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3268. compositePeriodIdx++;
  3269. }
  3270. else
  3271. {
  3272. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3273. }
  3274. }
  3275. }
  3276. }
  3277. }
  3278. else
  3279. {
  3280. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3281. {
  3282. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3283. compositePeriodIdx++;
  3284. }
  3285. else
  3286. {
  3287. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3288. }
  3289. }
  3290. }
  3291. if(idxTxPeriod == (limitTx-1))
  3292. {
  3293. if(defaultTxProfile.ChargingProfileId != -1)
  3294. {
  3295. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  3296. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3297. {
  3298. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3299. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3300. (defaultTxProfile.ChargingSchedule.Duration>0))
  3301. {
  3302. if(maxProfile.ChargingProfileId != -1)
  3303. {
  3304. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3305. {
  3306. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3307. {
  3308. if((maxProfile.ChargingSchedule.Duration > 0))
  3309. {
  3310. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3311. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3312. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3313. }
  3314. else
  3315. {
  3316. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3317. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3318. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3319. }
  3320. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3321. {
  3322. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3323. {
  3324. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3325. compositePeriodIdx++;
  3326. }
  3327. else
  3328. {
  3329. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3330. }
  3331. }
  3332. // Delete duplicate period
  3333. if(compositePeriodIdx > 1)
  3334. {
  3335. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3336. {
  3337. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3338. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3339. compositePeriodIdx -= 1;
  3340. }
  3341. }
  3342. }
  3343. else
  3344. {
  3345. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3346. {
  3347. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3348. compositePeriodIdx++;
  3349. }
  3350. else
  3351. {
  3352. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3353. }
  3354. break;
  3355. }
  3356. }
  3357. }
  3358. else
  3359. {
  3360. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3361. {
  3362. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3363. compositePeriodIdx++;
  3364. }
  3365. else
  3366. {
  3367. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3368. }
  3369. }
  3370. }
  3371. }
  3372. }
  3373. }
  3374. }
  3375. }
  3376. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3377. else if(defaultTxProfile.ChargingProfileId != -1)
  3378. {
  3379. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3380. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3381. {
  3382. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3383. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3384. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3385. {
  3386. if(maxProfile.ChargingProfileId != -1)
  3387. {
  3388. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3389. {
  3390. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3391. {
  3392. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3393. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3394. if((maxProfile.ChargingSchedule.Duration > 0))
  3395. {
  3396. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3397. }
  3398. else
  3399. {
  3400. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3401. }
  3402. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3403. {
  3404. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3405. {
  3406. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3407. compositePeriodIdx++;
  3408. }
  3409. else
  3410. {
  3411. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3412. }
  3413. }
  3414. // Delete duplicate period
  3415. if(compositePeriodIdx > 1)
  3416. {
  3417. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3418. {
  3419. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3420. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3421. compositePeriodIdx -= 1;
  3422. }
  3423. }
  3424. }
  3425. else
  3426. {
  3427. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3428. {
  3429. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3430. compositePeriodIdx++;
  3431. }
  3432. else
  3433. {
  3434. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3435. }
  3436. break;
  3437. }
  3438. }
  3439. }
  3440. else
  3441. {
  3442. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3443. {
  3444. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3445. compositePeriodIdx++;
  3446. }
  3447. else
  3448. {
  3449. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3450. }
  3451. }
  3452. }
  3453. }
  3454. }
  3455. // Fill other period by MaxProfile
  3456. if(maxProfile.ChargingProfileId != -1)
  3457. {
  3458. if(compositePeriodIdx==0)
  3459. {
  3460. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3461. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3462. {
  3463. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3464. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3465. (maxProfile.ChargingSchedule.Duration > 0))
  3466. {
  3467. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3468. {
  3469. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3470. compositePeriodIdx++;
  3471. }
  3472. else
  3473. {
  3474. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3475. }
  3476. }
  3477. }
  3478. }
  3479. else
  3480. {
  3481. int lastCompositePeriodIdx = compositePeriodIdx;
  3482. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3483. {
  3484. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3485. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3486. (maxProfile.ChargingSchedule.Duration > 0))
  3487. {
  3488. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3489. {
  3490. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3491. {
  3492. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3493. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3494. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3495. }
  3496. else
  3497. {
  3498. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3499. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3500. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3501. }
  3502. }
  3503. if(tmpPeriod.Limit != -1)
  3504. {
  3505. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3506. {
  3507. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3508. {
  3509. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3510. compositePeriodIdx++;
  3511. }
  3512. else
  3513. {
  3514. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3515. }
  3516. }
  3517. // Delete duplicate period
  3518. if(compositePeriodIdx > 1)
  3519. {
  3520. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3521. {
  3522. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3523. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3524. compositePeriodIdx -= 1;
  3525. }
  3526. }
  3527. }
  3528. }
  3529. }
  3530. }
  3531. }
  3532. compositeProfile->ChargingSchedule.Duration = durationReq;
  3533. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3534. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3535. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3536. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3537. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3538. {
  3539. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3540. {
  3541. compositeProfile->ChargingProfileId = 1;
  3542. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3543. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3544. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3545. }
  3546. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3547. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3548. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3549. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3550. }
  3551. if(line)
  3552. free(line);
  3553. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3554. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3555. }
  3556. //==========================================
  3557. // Init all share memory
  3558. //==========================================
  3559. int InitShareMemory()
  3560. {
  3561. int result = PASS;
  3562. int MeterSMId;
  3563. //creat ShmSysConfigAndInfo
  3564. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3565. {
  3566. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3567. result = FAIL;
  3568. }
  3569. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3570. {
  3571. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3572. result = FAIL;
  3573. }
  3574. else
  3575. {}
  3576. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3577. {
  3578. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3579. result = FAIL;
  3580. }
  3581. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3582. {
  3583. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3584. result = FAIL;
  3585. }
  3586. else
  3587. {}
  3588. //creat ShmPsuData
  3589. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3590. {
  3591. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3592. result = FAIL;
  3593. }
  3594. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3595. {
  3596. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3597. result = FAIL;
  3598. }
  3599. else
  3600. {}
  3601. //creat ShmOCPP16Data
  3602. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3603. {
  3604. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3605. result = FAIL;
  3606. }
  3607. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3608. {
  3609. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3610. result = FAIL;
  3611. }
  3612. else
  3613. {}
  3614. /****************************** For Initial Settings************************************************/
  3615. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3616. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3617. // allocate Configuration memory address
  3618. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3619. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3620. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3621. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3622. //offline MeterValue Interval
  3623. TempMeterValueInterval = 0;
  3624. return result;
  3625. }
  3626. int ProcessShareMemory()
  3627. {
  3628. int result = PASS;
  3629. if(InitShareMemory() == FAIL)
  3630. {
  3631. DEBUG_ERROR("InitShareMemory NG\n");
  3632. if(ShmStatusCodeData!=NULL)
  3633. {
  3634. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3635. }
  3636. result = FAIL;
  3637. }
  3638. // Model name parsing
  3639. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3640. {
  3641. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3642. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3643. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3644. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3645. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3646. ) // 'D' means DC
  3647. {
  3648. // DO series
  3649. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3650. {
  3651. SystemInitial += 1;
  3652. gunTotalNumber += 1;
  3653. gunType[gun_index] = GUN_TYPE_DO;
  3654. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3655. {
  3656. case Gun_Type_Chademo:
  3657. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3658. break;
  3659. case Gun_Type_CCS_2:
  3660. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3661. break;
  3662. case Gun_Type_GB:
  3663. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3664. break;
  3665. case Gun_Type_AC:
  3666. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3667. break;
  3668. default:
  3669. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3670. break;
  3671. }
  3672. }
  3673. }
  3674. else
  3675. {
  3676. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3677. {
  3678. SystemInitial += 1;
  3679. gunTotalNumber += 1;
  3680. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3681. {
  3682. case Gun_Type_Chademo:
  3683. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3684. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3685. break;
  3686. case Gun_Type_CCS_2:
  3687. gunType[gun_index] = GUN_TYPE_CCS;
  3688. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3689. break;
  3690. case Gun_Type_GB:
  3691. gunType[gun_index] = GUN_TYPE_GBT;
  3692. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3693. break;
  3694. case Gun_Type_AC:
  3695. gunType[gun_index] = GUN_TYPE_AC;
  3696. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3697. break;
  3698. default:
  3699. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3700. break;
  3701. }
  3702. }
  3703. }
  3704. }
  3705. else
  3706. {
  3707. DEBUG_ERROR("Model name parsing fail.\n");
  3708. result = FAIL;
  3709. }
  3710. if(result != PASS)sleep(5);
  3711. return result;
  3712. }
  3713. void checkRemoteStart(uint8_t connectorIdInt)
  3714. {
  3715. uint8_t tempIndex;
  3716. int result = PASS;
  3717. char cmdBuf[512];
  3718. //check Transaction active
  3719. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3720. {
  3721. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3722. {
  3723. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3724. }
  3725. else
  3726. {
  3727. tempIndex = connectorIdInt -1;
  3728. }
  3729. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3730. {
  3731. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3732. {
  3733. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3734. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3735. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3736. {
  3737. //Reserved
  3738. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3739. }
  3740. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3741. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3742. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3743. {
  3744. //Reserved
  3745. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3746. result = FAIL;
  3747. goto end;
  3748. }
  3749. else
  3750. {
  3751. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3752. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3753. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3754. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3755. {
  3756. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  3757. result = FAIL;
  3758. goto end;
  3759. }
  3760. }//END FOR ELSE
  3761. }
  3762. }// END FOR CHAdeMO_QUANTITY
  3763. }
  3764. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3765. {
  3766. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3767. {
  3768. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3769. }
  3770. else
  3771. {
  3772. tempIndex = connectorIdInt -1;
  3773. }
  3774. for (int index = 0; index < CCS_QUANTITY; index++)
  3775. {
  3776. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3777. {
  3778. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3779. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3780. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3781. {
  3782. //Reserved
  3783. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3784. }
  3785. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3786. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3787. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3788. {
  3789. //Reserved
  3790. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3791. result = FAIL;
  3792. goto end;
  3793. }
  3794. else
  3795. {
  3796. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3797. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3798. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3799. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3800. {
  3801. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3802. result = FAIL;
  3803. goto end;
  3804. }
  3805. }// END FOR ELSE
  3806. }
  3807. }// END FOR CCS_QUANTITY
  3808. }
  3809. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3810. {
  3811. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3812. {
  3813. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3814. }
  3815. else
  3816. {
  3817. tempIndex = connectorIdInt -1;
  3818. }
  3819. for (int index = 0; index < GB_QUANTITY; index++)
  3820. {
  3821. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3822. {
  3823. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3824. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3825. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3826. {
  3827. //Reserved
  3828. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3829. }
  3830. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3831. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3832. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3833. {
  3834. //Reserved
  3835. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3836. result = FAIL;
  3837. goto end;
  3838. }
  3839. else
  3840. {
  3841. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3842. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3843. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3844. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3845. {
  3846. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  3847. result = FAIL;
  3848. goto end;
  3849. }
  3850. }// END FOR ELSE
  3851. }
  3852. } // END FOR GB_QUANTITY
  3853. }
  3854. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3855. {
  3856. tempIndex = connectorIdInt -1;
  3857. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3858. {
  3859. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3860. {
  3861. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3862. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3863. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3864. {
  3865. //Reserved
  3866. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3867. }
  3868. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3869. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3870. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3871. {
  3872. //Reserved
  3873. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3874. result = FAIL;
  3875. goto end;
  3876. }
  3877. else
  3878. {
  3879. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3880. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3881. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3882. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3883. {
  3884. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  3885. result = FAIL;
  3886. goto end;
  3887. }
  3888. }// END FOR ELSE
  3889. }
  3890. } // END FOR GB_QUANTITY
  3891. }
  3892. else
  3893. {
  3894. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3895. {
  3896. tempIndex = 2;
  3897. }
  3898. else
  3899. {
  3900. tempIndex = connectorIdInt -1;
  3901. }
  3902. for (int index = 0; index < AC_QUANTITY; index++)
  3903. {
  3904. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3905. {
  3906. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3907. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3908. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3909. {
  3910. //Reserved
  3911. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3912. }
  3913. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3914. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3915. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3916. {
  3917. //Reserved
  3918. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3919. result = FAIL;
  3920. goto end;
  3921. }
  3922. else
  3923. {
  3924. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3925. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3926. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3927. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3928. {
  3929. DEBUG_WARN("AC connector not allow start cause busy.\n");
  3930. result = FAIL;
  3931. goto end;
  3932. }
  3933. }//END FOR ELSE
  3934. }
  3935. }// END FOR AC_QUANTITY
  3936. }
  3937. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3938. {
  3939. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3940. {
  3941. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  3942. {
  3943. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3944. system(cmdBuf);
  3945. }
  3946. }
  3947. else
  3948. {
  3949. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3950. result = FAIL;
  3951. }
  3952. }
  3953. end:
  3954. if(result == PASS)
  3955. {
  3956. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3957. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3958. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3959. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3960. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3961. }
  3962. }
  3963. void CheckSystemValue(void)
  3964. {
  3965. char filenmae[100]={0};
  3966. char str[100]={0};
  3967. int tempIndex = 0;
  3968. //===============================
  3969. // send Heartbeat
  3970. //===============================
  3971. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3972. {
  3973. //parameter for test
  3974. sendHeartbeatRequest(0);
  3975. //===========================
  3976. // Reset Waiting Time
  3977. //===========================
  3978. HeartBeatWithNOResponse += 1;
  3979. }
  3980. //===============================
  3981. // Credit deduct report
  3982. //===============================
  3983. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  3984. {
  3985. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo, ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice);
  3986. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  3987. }
  3988. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3989. {
  3990. OCPP_query_deduct_info();
  3991. refreshStartTimer(&clientTime.TcciQueryDeduct);
  3992. }
  3993. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3994. {
  3995. // ClockAlign MeterValue
  3996. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3997. {
  3998. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3999. {
  4000. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4001. {
  4002. tempIndex = ((gun_index==2) ? 1: 0);
  4003. }
  4004. else
  4005. {
  4006. tempIndex = gun_index;
  4007. }
  4008. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4009. {
  4010. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4011. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4012. {
  4013. reqClockAlignMeter[gun_index] = 1;
  4014. }
  4015. }// End for CHAdeMO
  4016. }
  4017. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4018. {
  4019. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4020. {
  4021. tempIndex = ((gun_index==2) ? 1: 0);
  4022. }
  4023. else
  4024. {
  4025. tempIndex = gun_index;
  4026. }
  4027. for (int index = 0; index < CCS_QUANTITY; index++)
  4028. {
  4029. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4030. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4031. {
  4032. reqClockAlignMeter[gun_index] = 1;
  4033. }
  4034. } // End for CCS
  4035. }
  4036. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4037. {
  4038. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4039. {
  4040. tempIndex = ((gun_index==2) ? 1: 0);
  4041. }
  4042. else
  4043. {
  4044. tempIndex = gun_index;
  4045. }
  4046. for (int index = 0; index < GB_QUANTITY; index++)
  4047. {
  4048. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4049. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4050. {
  4051. reqClockAlignMeter[gun_index] = 1;
  4052. }
  4053. }// End for GB
  4054. }
  4055. else if(gunType[gun_index] == GUN_TYPE_DO)
  4056. {
  4057. tempIndex = gun_index;
  4058. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4059. {
  4060. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4061. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4062. {
  4063. reqClockAlignMeter[gun_index] = 1;
  4064. }
  4065. }
  4066. }
  4067. else
  4068. {
  4069. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4070. {
  4071. tempIndex = 2;
  4072. }
  4073. else
  4074. {
  4075. tempIndex = gun_index;
  4076. }
  4077. for (int index = 0; index < AC_QUANTITY; index++)
  4078. {
  4079. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4080. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4081. {
  4082. reqClockAlignMeter[gun_index] = 1;
  4083. }
  4084. }//End for AC
  4085. }
  4086. }
  4087. }
  4088. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4089. {
  4090. //==========================================
  4091. // Check remote start without connector id
  4092. //==========================================
  4093. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4094. {
  4095. int connectorIdInt = -1;
  4096. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4097. {
  4098. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4099. {
  4100. connectorIdInt = (gun_index+1);
  4101. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4102. checkRemoteStart(connectorIdInt);
  4103. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4104. break;
  4105. }
  4106. }
  4107. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4108. {
  4109. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4110. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4111. }
  4112. }
  4113. //==========================================
  4114. // csu trigger DataTransferReq
  4115. //==========================================
  4116. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4117. {
  4118. sendDataTransferRequest(gun_index);
  4119. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4120. }
  4121. //==========================================
  4122. // CSU Trigger Authorize Request
  4123. //==========================================
  4124. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4125. {
  4126. sendAuthorizeRequest(0);
  4127. authorizeRetryTimes = authorizeRetryTimes + 1;
  4128. if(authorizeRetryTimes < 3)
  4129. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4130. }
  4131. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4132. {
  4133. authorizeRetryTimes = 0;
  4134. SetOcppConnStatus(FALSE);
  4135. server_sign = FALSE;
  4136. }
  4137. else if((server_sign == FALSE) && (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0)&& (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1))
  4138. {
  4139. sendAuthorizeRequest(0);
  4140. }
  4141. //==========================================
  4142. // Charger start transaction
  4143. //==========================================
  4144. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4145. {
  4146. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4147. sendStartTransactionRequest(gun_index);
  4148. refreshStartTimer(&clientTime.StartTransaction);
  4149. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4150. storeTempStopTransaction(gun_index);
  4151. }
  4152. //==========================================
  4153. // Charger stop transaction
  4154. //==========================================
  4155. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4156. {
  4157. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4158. sendStopTransactionRequest(gun_index);
  4159. OCPP_updatePeriodEnergy(gun_index);
  4160. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4161. refreshStartTimer(&clientTime.StopTransaction);
  4162. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4163. }
  4164. //==========================================
  4165. // Charger status report
  4166. //==========================================
  4167. //--- Check Mode Change ---//
  4168. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4169. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4170. {
  4171. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4172. {
  4173. tempIndex = ((gun_index==2) ? 1: 0);
  4174. }
  4175. else
  4176. {
  4177. tempIndex = gun_index;
  4178. }
  4179. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4180. {
  4181. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4182. {
  4183. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4184. {
  4185. // Sent unplug message for California pricing logic
  4186. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  4187. {
  4188. uint8_t ts[20];
  4189. getNowDatetime(ts);
  4190. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4191. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4192. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4193. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4194. }
  4195. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4196. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4197. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4198. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4199. {
  4200. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4201. if((access(filenmae,F_OK))!=-1)
  4202. {
  4203. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4204. sprintf(str,"rm -f %s",filenmae);
  4205. system(str);
  4206. }
  4207. }
  4208. }
  4209. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4210. #if 1 // for TempStopTransaction
  4211. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4212. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4213. {
  4214. checkTempStopTransaction(gun_index);
  4215. }
  4216. #endif
  4217. }
  4218. }
  4219. }
  4220. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4221. {
  4222. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4223. {
  4224. tempIndex = ((gun_index==2) ? 1: 0);
  4225. }
  4226. else
  4227. {
  4228. tempIndex = gun_index;
  4229. }
  4230. for (int index = 0; index < CCS_QUANTITY; index++)
  4231. {
  4232. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4233. {
  4234. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  4235. {
  4236. // Sent unplug message for California pricing logic
  4237. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  4238. {
  4239. uint8_t ts[20];
  4240. getNowDatetime(ts);
  4241. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4242. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4243. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4244. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4245. }
  4246. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4247. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4248. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4249. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4250. {
  4251. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4252. if((access(filenmae,F_OK))!=-1)
  4253. {
  4254. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4255. sprintf(str,"rm -f %s",filenmae);
  4256. system(str);
  4257. }
  4258. }
  4259. }
  4260. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4261. #if 1 // for TempStopTransaction
  4262. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4263. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4264. {
  4265. checkTempStopTransaction(gun_index);
  4266. }
  4267. #endif
  4268. }
  4269. }
  4270. }
  4271. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4272. {
  4273. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4274. {
  4275. tempIndex = ((gun_index==2) ? 1: 0);
  4276. }
  4277. else
  4278. {
  4279. tempIndex = gun_index;
  4280. }
  4281. for (int index = 0; index < GB_QUANTITY; index++)
  4282. {
  4283. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4284. {
  4285. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4286. {
  4287. // Sent unplug message for California pricing logic
  4288. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  4289. {
  4290. uint8_t ts[20];
  4291. getNowDatetime(ts);
  4292. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4293. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4294. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4295. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4296. }
  4297. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4298. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4299. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4300. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4301. {
  4302. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4303. if((access(filenmae,F_OK))!=-1)
  4304. {
  4305. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4306. sprintf(str,"rm -f %s",filenmae);
  4307. system(str);
  4308. }
  4309. }
  4310. }
  4311. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4312. #if 1 // for TempStopTransaction
  4313. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4314. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4315. {
  4316. checkTempStopTransaction(gun_index);
  4317. }
  4318. #endif
  4319. }
  4320. }
  4321. }
  4322. else if(gunType[gun_index] == GUN_TYPE_DO)
  4323. {
  4324. tempIndex = gun_index;
  4325. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4326. {
  4327. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4328. {
  4329. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4330. {
  4331. // Sent unplug message for California pricing logic
  4332. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  4333. {
  4334. uint8_t ts[20];
  4335. getNowDatetime(ts);
  4336. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4337. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4338. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4339. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4340. }
  4341. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4342. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4343. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4344. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_IDLE))) // complete
  4345. {
  4346. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4347. if((access(filenmae,F_OK))!=-1)
  4348. {
  4349. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4350. sprintf(str,"rm -f %s",filenmae);
  4351. system(str);
  4352. }
  4353. }
  4354. }
  4355. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4356. #if 1 // for TempStopTransaction
  4357. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4358. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4359. {
  4360. checkTempStopTransaction(gun_index);
  4361. }
  4362. #endif
  4363. }
  4364. }
  4365. }
  4366. else
  4367. {
  4368. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4369. {
  4370. tempIndex = 2;
  4371. }
  4372. else
  4373. {
  4374. tempIndex = gun_index;
  4375. }
  4376. for (int index = 0; index < AC_QUANTITY; index++)
  4377. {
  4378. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4379. {
  4380. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4381. {
  4382. // Sent unplug message for California pricing logic
  4383. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  4384. {
  4385. uint8_t ts[20];
  4386. getNowDatetime(ts);
  4387. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4388. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4389. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4390. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4391. }
  4392. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4393. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4394. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4395. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4396. {
  4397. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4398. if((access(filenmae,F_OK))!=-1)
  4399. {
  4400. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4401. sprintf(str,"rm -f %s",filenmae);
  4402. system(str);
  4403. }
  4404. }
  4405. }
  4406. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4407. #if 1 // for TempStopTransaction
  4408. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4409. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4410. {
  4411. checkTempStopTransaction(gun_index);
  4412. }
  4413. #endif
  4414. }
  4415. }// END
  4416. }
  4417. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  4418. (
  4419. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4420. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4421. )
  4422. )
  4423. {
  4424. if(SystemInitial > 0)
  4425. SystemInitial -= 1;
  4426. sendStatusNotificationRequest(gun_index);
  4427. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4428. }
  4429. //==============================================
  4430. // CSU Trigger Smart Charging Profile
  4431. //==============================================
  4432. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4433. {
  4434. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4435. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4436. }
  4437. //==============================================
  4438. // Meter report
  4439. //==============================================
  4440. // Trigger MeterValue
  4441. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4442. {
  4443. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4444. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4445. }
  4446. // Clock-aligned Meter value
  4447. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4448. {
  4449. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4450. reqClockAlignMeter[gun_index] = 0;
  4451. }
  4452. // Sample period MeterValue
  4453. if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>3?(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):3))))
  4454. {
  4455. //check Transaction active
  4456. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4457. {
  4458. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4459. {
  4460. tempIndex = ((gun_index==2) ? 1: 0);
  4461. }
  4462. else
  4463. {
  4464. tempIndex = gun_index;
  4465. }
  4466. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4467. {
  4468. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4469. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4470. {
  4471. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4472. {
  4473. reqSampleMeter[gun_index] = 1;
  4474. }
  4475. }
  4476. }// End for CHAdeMO
  4477. }
  4478. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4479. {
  4480. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4481. {
  4482. tempIndex = ((gun_index==2) ? 1: 0);
  4483. }
  4484. else
  4485. {
  4486. tempIndex = gun_index;
  4487. }
  4488. for (int index = 0; index < CCS_QUANTITY; index++)
  4489. {
  4490. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4491. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4492. {
  4493. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4494. {
  4495. reqSampleMeter[gun_index] = 1;
  4496. }
  4497. }
  4498. } // End for CCS
  4499. }
  4500. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4501. {
  4502. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4503. {
  4504. tempIndex = ((gun_index==2) ? 1: 0);
  4505. }
  4506. else
  4507. {
  4508. tempIndex = gun_index;
  4509. }
  4510. for (int index = 0; index < GB_QUANTITY; index++)
  4511. {
  4512. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4513. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4514. {
  4515. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4516. {
  4517. reqSampleMeter[gun_index] = 1;
  4518. }
  4519. }
  4520. }// End for GB
  4521. }
  4522. else if(gunType[gun_index] == GUN_TYPE_DO)
  4523. {
  4524. tempIndex = gun_index;
  4525. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4526. {
  4527. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4528. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4529. {
  4530. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4531. {
  4532. reqSampleMeter[gun_index] = 1;
  4533. }
  4534. }
  4535. }
  4536. }
  4537. else
  4538. {
  4539. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4540. {
  4541. tempIndex = 2;
  4542. }
  4543. else
  4544. {
  4545. tempIndex = gun_index;
  4546. }
  4547. for (int index = 0; index < AC_QUANTITY; index++)
  4548. {
  4549. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4550. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4551. {
  4552. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4553. {
  4554. reqSampleMeter[gun_index] = 1;
  4555. }
  4556. }
  4557. }//End for AC
  4558. }
  4559. if(reqSampleMeter[gun_index] == 1)
  4560. {
  4561. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4562. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4563. storeTempStopTransaction(gun_index);
  4564. reqSampleMeter[gun_index] = 0;
  4565. }
  4566. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4567. }
  4568. //==============================================
  4569. // Check Connector reserved
  4570. //==============================================
  4571. //===============================
  4572. // Check if Reserve is expired
  4573. //===============================
  4574. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4575. {
  4576. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4577. {
  4578. DEBUG_INFO("reserve expired.\n");
  4579. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4580. }
  4581. }//END OF Check if Reserve is expired
  4582. //==========================================
  4583. // csu trigger FirmwareStatusNotificationReq
  4584. //==========================================
  4585. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4586. {
  4587. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  4588. }
  4589. //==========================================
  4590. // csu trigger DiagnosticsStatusNotificationReq
  4591. //==========================================
  4592. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4593. {
  4594. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  4595. }
  4596. //==========================================
  4597. // csu trigger CancelReservationConf
  4598. //==========================================
  4599. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4600. {
  4601. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  4602. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4603. }
  4604. //==========================================
  4605. // csu trigger ChangeAvailabilityConf
  4606. //==========================================
  4607. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4608. {
  4609. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  4610. }
  4611. //==========================================
  4612. // csu trigger UnlockConnectorConf
  4613. //==========================================
  4614. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4615. {
  4616. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  4617. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4618. }
  4619. //==========================================
  4620. // csu trigger ReserveNowConf
  4621. //==========================================
  4622. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4623. {
  4624. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  4625. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4626. }
  4627. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  4628. {
  4629. sendSignCertificateRequest();
  4630. }
  4631. }
  4632. }
  4633. //==========================================
  4634. // send request routine
  4635. //==========================================
  4636. int sendAuthorizeRequest(int gun_index)
  4637. {
  4638. mtrace();
  4639. int result = FAIL;
  4640. char message[100]={0};
  4641. char guid[37];
  4642. char tempdata[65]={0};
  4643. DEBUG_INFO("sendAuthorizeRequest...\n");
  4644. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4645. //Local Authorize
  4646. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  4647. {
  4648. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4649. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4650. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4651. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4652. result = PASS;
  4653. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4654. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4655. authorizeRetryTimes = 0;
  4656. return result;
  4657. }
  4658. else if(((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))||
  4659. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4660. {
  4661. // Query from cache
  4662. DEBUG_INFO("Authorize from cache.\n");
  4663. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4664. // Query from list
  4665. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4666. {
  4667. DEBUG_INFO("Authorize from list.\n");
  4668. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4669. }
  4670. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4671. {
  4672. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4673. {
  4674. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4675. }
  4676. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4677. {
  4678. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4679. }
  4680. if(!GetOcppConnStatus())
  4681. {
  4682. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4683. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4684. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4685. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4686. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4687. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4688. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4689. authorizeRetryTimes = 0;
  4690. return result;
  4691. }
  4692. }
  4693. else
  4694. {
  4695. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4696. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4697. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4698. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4699. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  4700. else
  4701. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4702. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4703. result = PASS;
  4704. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4705. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4706. authorizeRetryTimes = 0;
  4707. return result;
  4708. }
  4709. }
  4710. //initialize struct Authorize
  4711. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  4712. //get data from shared memory
  4713. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4714. random_uuid(guid);
  4715. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  4716. LWS_Send(message);
  4717. sprintf(tempdata, "Authorize,%d", gun_index);
  4718. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4719. {
  4720. result = PASS;
  4721. DEBUG_INFO("Authorize mapItem pass\n");
  4722. }
  4723. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4724. return result;
  4725. }
  4726. int sendBootNotificationRequest(void)
  4727. {
  4728. mtrace();
  4729. int result = FAIL;
  4730. char message[500]={0}, payload[700]={0};
  4731. char guid[37]={0};
  4732. char tempdata[65]={0};
  4733. // Fill BootNotification fields
  4734. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  4735. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4736. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4737. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4738. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4739. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4740. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4741. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4742. ShmOCPP16Data->ChargeBoxId
  4743. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4744. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4745. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4746. ,ShmOCPP16Data->BootNotification.CpFwVersion
  4747. ,ShmOCPP16Data->BootNotification.CpIccid
  4748. ,ShmOCPP16Data->BootNotification.CpImsi);
  4749. random_uuid(guid);
  4750. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4751. LWS_Send(message);
  4752. sprintf(tempdata, "BootNotification,0");
  4753. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid,mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  4754. {
  4755. result = PASS;
  4756. }
  4757. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4758. strcpy(queuedata,message);
  4759. return result;
  4760. }
  4761. int sendDataTransferRequest(int gun_index)
  4762. {
  4763. mtrace();
  4764. char message[1000]={0};
  4765. char guid[37]={0};
  4766. char tempdata[65]={0};
  4767. int result = FAIL;
  4768. random_uuid(guid);
  4769. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4770. MESSAGE_TYPE_CALL,
  4771. guid,
  4772. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4773. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4774. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4775. LWS_Send(message);
  4776. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4777. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4778. {
  4779. result = PASS;
  4780. DEBUG_INFO("DataTransfer mapItem pass\n");
  4781. }
  4782. return result;
  4783. }
  4784. int sendDiagnosticsStatusNotificationRequest(char *status)
  4785. {
  4786. mtrace();
  4787. int result = FAIL;
  4788. char message[110]={0};
  4789. char guid[37]={0};
  4790. char tempdata[65]={0};
  4791. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4792. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4793. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4794. random_uuid(guid);
  4795. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4796. LWS_SendNow(message);
  4797. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4798. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4799. {
  4800. result = PASS;
  4801. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4802. }
  4803. //#ifdef SystemLogMessage
  4804. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4805. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4806. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4807. //#endif
  4808. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4809. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4810. //record status
  4811. if(strcmp(status,"Idle")==0)
  4812. {
  4813. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4814. }
  4815. else if(strcmp(status,"Uploaded")==0)
  4816. {
  4817. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4818. }
  4819. else if(strcmp(status,"UploadFailed")==0)
  4820. {
  4821. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4822. }
  4823. else if(strcmp(status,"Uploading")==0)
  4824. {
  4825. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4826. }
  4827. return result;
  4828. }
  4829. int sendFirmwareStatusNotificationRequest(char *status)
  4830. {
  4831. mtrace();
  4832. int result = FAIL;
  4833. char message[110]={0};
  4834. char guid[37]={0};
  4835. char tempdata[65]={0};
  4836. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4837. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4838. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4839. random_uuid(guid);
  4840. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4841. LWS_SendNow(message);
  4842. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4843. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  4844. {
  4845. result = PASS;
  4846. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4847. }
  4848. //#ifdef SystemLogMessage
  4849. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4850. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4851. //#endif
  4852. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4853. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4854. //record status
  4855. if(strcmp(status,"Downloaded")==0)
  4856. {
  4857. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4858. }
  4859. else if(strcmp(status,"DownloadFailed")==0)
  4860. {
  4861. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4862. }
  4863. else if(strcmp(status,"Downloading")==0)
  4864. {
  4865. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4866. }
  4867. else if(strcmp(status,"Idle")==0)
  4868. {
  4869. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4870. }
  4871. else if(strcmp(status,"InstallationFailed")==0)
  4872. {
  4873. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4874. }
  4875. else if(strcmp(status,"Installing")==0)
  4876. {
  4877. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4878. }
  4879. else if(strcmp(status,"Installed")==0)
  4880. {
  4881. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4882. }
  4883. return result;
  4884. }
  4885. int sendHeartbeatRequest(int gun_index)
  4886. {
  4887. mtrace();
  4888. int result = FAIL;
  4889. char message[80]={0};
  4890. char guid[37]={0};
  4891. char tempdata[65]={0};
  4892. random_uuid(guid);
  4893. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4894. , MESSAGE_TYPE_CALL
  4895. , guid );
  4896. LWS_Send(message);
  4897. sprintf(tempdata, "Heartbeat,%d", 0);
  4898. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  4899. {
  4900. result = PASS;
  4901. }
  4902. return result;
  4903. }
  4904. int sendStartTransactionRequest(int gun_index)
  4905. {
  4906. mtrace();
  4907. int result = FAIL;
  4908. char message[250]={0};
  4909. char guid[37]={0};
  4910. struct timeval tmnow;
  4911. struct tm *tm;
  4912. char buf[28];//, usec_buf[6];
  4913. char tempdata[65]={0};
  4914. int tempIndex = 0;
  4915. DEBUG_INFO("sendStartTransactionRequest...\n");
  4916. gettimeofday(&tmnow, NULL);
  4917. time_t t;
  4918. t = time(NULL);
  4919. /*UTC time and date*/
  4920. tm = gmtime(&t);
  4921. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4922. #if 0 // remove temporally
  4923. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4924. strcat(buf,".");
  4925. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4926. strcat(buf,usec_buf);
  4927. #endif
  4928. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4929. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4930. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4931. // clear StartTransaction Response
  4932. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4933. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4934. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4935. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4936. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4937. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4938. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4939. {
  4940. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4941. {
  4942. tempIndex = ((gun_index==2) ? 1: 0);
  4943. }
  4944. else
  4945. {
  4946. tempIndex = gun_index;
  4947. }
  4948. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4949. {
  4950. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4951. {
  4952. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4953. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4954. }
  4955. }
  4956. }
  4957. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4958. {
  4959. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4960. {
  4961. tempIndex = ((gun_index==2) ? 1: 0);
  4962. }
  4963. else
  4964. {
  4965. tempIndex = gun_index;
  4966. }
  4967. for (int index = 0; index < CCS_QUANTITY; index++)
  4968. {
  4969. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4970. {
  4971. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4972. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4973. }
  4974. }
  4975. }
  4976. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4977. {
  4978. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4979. {
  4980. tempIndex = ((gun_index==2) ? 1: 0);
  4981. }
  4982. else
  4983. {
  4984. tempIndex = gun_index;
  4985. }
  4986. for (int index = 0; index < GB_QUANTITY; index++)
  4987. {
  4988. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4989. {
  4990. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4991. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4992. }
  4993. }
  4994. }
  4995. else if(gunType[gun_index] == GUN_TYPE_DO)
  4996. {
  4997. tempIndex = gun_index;
  4998. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4999. {
  5000. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5001. {
  5002. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5003. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5004. }
  5005. }
  5006. }
  5007. else
  5008. {
  5009. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5010. {
  5011. tempIndex = 2;
  5012. }
  5013. else
  5014. {
  5015. tempIndex = gun_index;
  5016. }
  5017. for (int index = 0; index < AC_QUANTITY; index++)
  5018. {
  5019. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5020. {
  5021. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5022. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5023. }
  5024. }
  5025. }
  5026. random_uuid(guid);
  5027. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5028. {
  5029. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5030. , gun_index +1
  5031. , MESSAGE_TYPE_CALL
  5032. , guid
  5033. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5034. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5035. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5036. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5037. }
  5038. else
  5039. {
  5040. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5041. , gun_index +1
  5042. , MESSAGE_TYPE_CALL
  5043. , guid
  5044. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5045. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5046. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5047. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  5048. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5049. }
  5050. #if 1
  5051. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5052. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  5053. {
  5054. result = PASS;
  5055. }
  5056. #endif
  5057. strcpy(queuedata, message);
  5058. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5059. OCPP_insert_transaction_msg(YES, queuedata);
  5060. return result;
  5061. }
  5062. int sendStatusNotificationRequest(int gun_index)
  5063. {
  5064. mtrace();
  5065. int result = FAIL;
  5066. char message[600]={0};
  5067. char guid[37];
  5068. int currentStatus = 0;
  5069. struct timeval tmnow;
  5070. struct tm *tm;
  5071. char buf[28];//, usec_buf[6];
  5072. char tempdata[65]={0};
  5073. int tempIndex = 0;
  5074. uint8_t isStateChanged = TRUE;
  5075. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5076. gettimeofday(&tmnow, NULL);
  5077. time_t t;
  5078. t = time(NULL);
  5079. /*UTC time and date*/
  5080. tm = gmtime(&t);
  5081. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5082. #if 0 // remove temporally
  5083. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5084. strcat(buf,".");
  5085. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5086. strcat(buf,usec_buf);
  5087. #endif
  5088. //printf("%s",buf);
  5089. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5090. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5091. // it's option
  5092. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5093. /*
  5094. enum _SYSTEM_STATUS
  5095. {
  5096. S_BOOTING = 0,
  5097. S_IDLE, = 1
  5098. S_AUTHORIZING, =2
  5099. S_REASSIGN_CHECK, =3
  5100. S_REASSIGN, =4
  5101. S_PRECHARGE, =5
  5102. S_PREPARING_FOR_EV, =6
  5103. S_PREPARING_FOR_EVSE, =7
  5104. S_CHARGING, =8
  5105. S_TERMINATING, =9
  5106. S_COMPLETE, =10
  5107. S_ALARM, =11
  5108. S_FAULT =12
  5109. }
  5110. */
  5111. //check Transaction active
  5112. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5113. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5114. {
  5115. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5116. {
  5117. tempIndex = ((gun_index==2) ? 1: 0);
  5118. }
  5119. else
  5120. {
  5121. tempIndex = gun_index;
  5122. }
  5123. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5124. {
  5125. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5126. {
  5127. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5128. {
  5129. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5130. {
  5131. currentStatus = Preparing; //OCPP Status: Preparing
  5132. }
  5133. else
  5134. {
  5135. currentStatus = Available; //OCPP Status: Available
  5136. }
  5137. }
  5138. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5139. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5140. ) //S_PRECHARGE
  5141. {
  5142. currentStatus = Preparing; //OCPP Status: Preparing
  5143. }
  5144. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5145. {
  5146. currentStatus = Charging; //OCPP Status: Charging
  5147. }
  5148. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5149. {
  5150. currentStatus = Finishing; //OCPP Status: Finishing
  5151. }
  5152. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5153. {
  5154. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5155. }
  5156. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5157. {
  5158. currentStatus = Unavailable; //OCPP Status: Unavailable
  5159. }
  5160. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5161. {
  5162. currentStatus = Faulted; //OCPP Status: Faulted
  5163. }
  5164. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5165. {
  5166. currentStatus = Reserved; //OCPP Status: Reserved
  5167. }
  5168. } //end of the same index
  5169. }//end of for CHAdeMO_QUANTITY
  5170. }
  5171. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5172. {
  5173. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5174. {
  5175. tempIndex = ((gun_index==2) ? 1: 0);
  5176. }
  5177. else
  5178. {
  5179. tempIndex = gun_index;
  5180. }
  5181. for (int index = 0; index < CCS_QUANTITY; index++)
  5182. {
  5183. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5184. {
  5185. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5186. {
  5187. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5188. {
  5189. currentStatus = Preparing; //OCPP Status: Preparing
  5190. }
  5191. else
  5192. {
  5193. currentStatus = Available; //OCPP Status: Available
  5194. }
  5195. }
  5196. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5197. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5198. ) //S_PRECHARGE
  5199. {
  5200. currentStatus = Preparing; //OCPP Status: Preparing
  5201. }
  5202. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5203. {
  5204. currentStatus = Charging; //OCPP Status: Charging
  5205. }
  5206. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5207. {
  5208. currentStatus = Finishing; //OCPP Status: Finishing
  5209. }
  5210. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5211. {
  5212. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5213. }
  5214. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5215. {
  5216. currentStatus = Unavailable; //OCPP Status : Unavailable
  5217. }
  5218. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5219. {
  5220. currentStatus = Faulted; //OCPP Status: Faulted
  5221. }
  5222. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5223. {
  5224. currentStatus = Reserved; //OCPP Status: Reserved
  5225. }
  5226. } //end of the same index
  5227. } // end of for CCS_QUANTITY
  5228. }
  5229. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5230. {
  5231. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5232. {
  5233. tempIndex = ((gun_index==2) ? 1: 0);
  5234. }
  5235. else
  5236. {
  5237. tempIndex = gun_index;
  5238. }
  5239. for (int index = 0; index < GB_QUANTITY; index++)
  5240. {
  5241. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5242. {
  5243. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5244. {
  5245. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5246. {
  5247. currentStatus = Preparing; //OCPP Status: Preparing
  5248. }
  5249. else
  5250. {
  5251. currentStatus = Available; //OCPP Status: Available
  5252. }
  5253. }
  5254. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5255. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5256. ) //S_PRECHARGE
  5257. {
  5258. currentStatus = Preparing; //OCPP Status: Preparing
  5259. }
  5260. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5261. {
  5262. currentStatus = Charging; //OCPP Status: Charging
  5263. }
  5264. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5265. {
  5266. currentStatus = Finishing; //OCPP Status: Finishing
  5267. }
  5268. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5269. {
  5270. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5271. }
  5272. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5273. {
  5274. currentStatus = Unavailable; //OCPP Status: Unavailable
  5275. }
  5276. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5277. {
  5278. currentStatus = Faulted; //OCPP Status: Faulted
  5279. }
  5280. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5281. {
  5282. currentStatus = Reserved; //OCPP Status: Reserved
  5283. }
  5284. } //end of the same index
  5285. } // end of for GB_QUANTITY
  5286. }
  5287. else if(gunType[gun_index] == GUN_TYPE_DO)
  5288. {
  5289. tempIndex = gun_index;
  5290. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5291. {
  5292. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5293. {
  5294. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5295. {
  5296. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5297. {
  5298. currentStatus = Preparing; //OCPP Status: Preparing
  5299. }
  5300. else
  5301. {
  5302. currentStatus = Available; //OCPP Status: Available
  5303. }
  5304. }
  5305. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5306. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5307. ) //S_PRECHARGE
  5308. {
  5309. currentStatus = Preparing; //OCPP Status: Preparing
  5310. }
  5311. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5312. {
  5313. currentStatus = Charging; //OCPP Status: Charging
  5314. }
  5315. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5316. {
  5317. currentStatus = Finishing; //OCPP Status: Finishing
  5318. }
  5319. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5320. {
  5321. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5322. }
  5323. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5324. {
  5325. currentStatus = Unavailable; //OCPP Status: Unavailable
  5326. }
  5327. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5328. {
  5329. currentStatus = Faulted; //OCPP Status: Faulted
  5330. }
  5331. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5332. {
  5333. currentStatus = Reserved; //OCPP Status: Reserved
  5334. }
  5335. } //end of the same index
  5336. }
  5337. }
  5338. else
  5339. {
  5340. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5341. {
  5342. tempIndex = 2;
  5343. }
  5344. else
  5345. {
  5346. tempIndex = gun_index;
  5347. }
  5348. for (int index = 0; index < AC_QUANTITY; index++)
  5349. {
  5350. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5351. {
  5352. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5353. {
  5354. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  5355. {
  5356. currentStatus = Preparing; //OCPP Status: Preparing
  5357. }
  5358. else
  5359. {
  5360. currentStatus = Available; //OCPP Status: Available
  5361. }
  5362. }
  5363. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5364. {
  5365. currentStatus = Preparing; //OCPP Status: Preparing
  5366. }
  5367. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5368. {
  5369. currentStatus = Charging; //OCPP Status: Charging
  5370. }
  5371. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5372. {
  5373. currentStatus = Finishing; //OCPP Status: Finishing
  5374. }
  5375. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5376. {
  5377. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5378. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5379. else
  5380. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5381. }
  5382. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5383. {
  5384. currentStatus = Unavailable; //OCPP Status: Unavailable
  5385. }
  5386. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5387. {
  5388. currentStatus = Faulted; //OCPP Status: Faulted
  5389. }
  5390. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5391. {
  5392. currentStatus = Reserved; //OCPP Status: Reserved
  5393. }
  5394. }//end of the same index
  5395. }//end of for AC_QUANTITY
  5396. }
  5397. //it's option
  5398. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5399. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5400. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5401. {
  5402. isStateChanged = FALSE;
  5403. }
  5404. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5405. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5406. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5407. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5408. random_uuid(guid);
  5409. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5410. , MESSAGE_TYPE_CALL
  5411. , guid
  5412. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5413. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5414. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5415. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5416. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5417. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5418. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5419. if((server_sign == TRUE) && isStateChanged)
  5420. {
  5421. LWS_Send(message);
  5422. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5423. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  5424. {
  5425. //DEBUG_ERROR("statusNotification mapitem pass");
  5426. result = PASS;
  5427. }
  5428. }
  5429. else
  5430. {
  5431. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5432. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5433. result = PASS;
  5434. }
  5435. return result;
  5436. }
  5437. int sendStopTransactionRequest(int gun_index)
  5438. {
  5439. mtrace();
  5440. int result = FAIL;
  5441. //char message[1500]={0};
  5442. char guid[37]={0};
  5443. char tempdata[65]={0};
  5444. int tempIndex = 0;
  5445. char TempStopTransaction[256];
  5446. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5447. //int idx_sample=0;
  5448. DEBUG_INFO("sendStopTransactionRequest \n");
  5449. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5450. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5451. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5452. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5453. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5454. {
  5455. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5456. {
  5457. tempIndex = ((gun_index==2) ? 1: 0);
  5458. }
  5459. else
  5460. {
  5461. tempIndex = gun_index;
  5462. }
  5463. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5464. {
  5465. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5466. {
  5467. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5468. }
  5469. }// END OF CHAdeMO_QUANTITY
  5470. }
  5471. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5472. {
  5473. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5474. {
  5475. tempIndex = ((gun_index==2) ? 1: 0);
  5476. }
  5477. else
  5478. {
  5479. tempIndex = gun_index;
  5480. }
  5481. for (int index = 0; index < CCS_QUANTITY; index++)
  5482. {
  5483. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5484. {
  5485. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5486. }
  5487. }// END OF CCS_QUANTITY
  5488. }
  5489. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5490. {
  5491. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5492. {
  5493. tempIndex = ((gun_index==2) ? 1: 0);
  5494. }
  5495. else
  5496. {
  5497. tempIndex = gun_index;
  5498. }
  5499. for (int index = 0; index < GB_QUANTITY; index++)
  5500. {
  5501. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5502. {
  5503. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5504. }
  5505. }// END OF GB_QUANTITY
  5506. }
  5507. else if(gunType[gun_index] == GUN_TYPE_DO)
  5508. {
  5509. tempIndex = gun_index;
  5510. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5511. {
  5512. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5513. {
  5514. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5515. }
  5516. }// END OF GB_QUANTITY
  5517. }
  5518. else
  5519. {
  5520. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5521. {
  5522. tempIndex = 2;
  5523. }
  5524. else
  5525. {
  5526. tempIndex = gun_index;
  5527. }
  5528. for (int index = 0; index < AC_QUANTITY; index++)
  5529. {
  5530. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5531. {
  5532. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5533. }
  5534. }// END OF AC_QUANTITY
  5535. }
  5536. //====================================== Stop Transaction Time =====================================================
  5537. struct timeval tmnow;
  5538. struct tm *tm;
  5539. char buf[28];//, usec_buf[6];
  5540. gettimeofday(&tmnow, NULL);
  5541. time_t t;
  5542. t = time(NULL);
  5543. /*UTC time and date*/
  5544. tm = gmtime(&t);
  5545. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5546. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  5547. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  5548. random_uuid(guid);
  5549. /***********************************transactionData******************************************************/
  5550. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5551. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5552. //=================================
  5553. // Transaction_Begin
  5554. //=================================
  5555. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5556. {
  5557. //============================================ Energy.Active.Import.Interval ================================
  5558. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5559. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5560. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5561. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  5562. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5563. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  5564. {
  5565. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5566. }
  5567. else
  5568. {
  5569. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5570. }
  5571. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5572. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5573. }
  5574. //=================================
  5575. // Transaction_End
  5576. //=================================
  5577. // ================================= Current.Import L1 ===============================================
  5578. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5579. {
  5580. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5581. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5582. {
  5583. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5584. {
  5585. tempIndex = ((gun_index==2) ? 1: 0);
  5586. }
  5587. else
  5588. {
  5589. tempIndex = gun_index;
  5590. }
  5591. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5592. {
  5593. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5594. {
  5595. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5596. }
  5597. }// End of for CHAdeMO_QUANTITY
  5598. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5599. }
  5600. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5601. {
  5602. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5603. {
  5604. tempIndex = ((gun_index==2) ? 1: 0);
  5605. }
  5606. else
  5607. {
  5608. tempIndex = gun_index;
  5609. }
  5610. for (int index = 0; index < CCS_QUANTITY; index++)
  5611. {
  5612. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5613. {
  5614. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5615. }
  5616. }// End of for CCS_QUANTITY
  5617. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5618. }
  5619. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5620. {
  5621. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5622. {
  5623. tempIndex = ((gun_index==2) ? 1: 0);
  5624. }
  5625. else
  5626. {
  5627. tempIndex = gun_index;
  5628. }
  5629. for (int index = 0; index < GB_QUANTITY; index++)
  5630. {
  5631. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5632. {
  5633. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5634. }
  5635. }// End of for GB_QUANTITY
  5636. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5637. }
  5638. else if(gunType[gun_index] == GUN_TYPE_DO)
  5639. {
  5640. tempIndex = gun_index;
  5641. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5642. {
  5643. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5644. {
  5645. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5646. }
  5647. }
  5648. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5649. }
  5650. else
  5651. {
  5652. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5653. {
  5654. tempIndex = 2;
  5655. }
  5656. else
  5657. {
  5658. tempIndex = gun_index;
  5659. }
  5660. for (int index = 0; index < AC_QUANTITY; index++)
  5661. {
  5662. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5663. {
  5664. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5665. }
  5666. }// End of for AC_QUANTITY
  5667. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5668. }
  5669. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5670. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5671. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5672. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5673. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5674. }
  5675. // ================================= Energy.Active.Import.Interval ==============================================
  5676. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5677. {
  5678. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5679. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5680. {
  5681. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5682. {
  5683. tempIndex = ((gun_index==2) ? 1: 0);
  5684. }
  5685. else
  5686. {
  5687. tempIndex = gun_index;
  5688. }
  5689. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5690. {
  5691. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5692. {
  5693. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5694. }
  5695. }// END OF CHAdeMO_QUANTITY
  5696. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5697. }
  5698. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5699. {
  5700. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5701. {
  5702. tempIndex = ((gun_index==2) ? 1: 0);
  5703. }
  5704. else
  5705. {
  5706. tempIndex = gun_index;
  5707. }
  5708. for (int index = 0; index < CCS_QUANTITY; index++)
  5709. {
  5710. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5711. {
  5712. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5713. }
  5714. }// END OF CCS_QUANTITY
  5715. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5716. }
  5717. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5718. {
  5719. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5720. {
  5721. tempIndex = ((gun_index==2) ? 1: 0);
  5722. }
  5723. else
  5724. {
  5725. tempIndex = gun_index;
  5726. }
  5727. for (int index = 0; index < GB_QUANTITY; index++)
  5728. {
  5729. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5730. {
  5731. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5732. }
  5733. }// END OF GB_QUANTITY
  5734. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5735. }
  5736. else if(gunType[gun_index] == GUN_TYPE_DO)
  5737. {
  5738. tempIndex = gun_index;
  5739. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5740. {
  5741. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5742. {
  5743. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5744. }
  5745. }
  5746. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5747. }
  5748. else
  5749. {
  5750. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5751. {
  5752. tempIndex = 2;
  5753. }
  5754. else
  5755. {
  5756. tempIndex = gun_index;
  5757. }
  5758. for (int index = 0; index < AC_QUANTITY; index++)
  5759. {
  5760. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5761. {
  5762. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5763. }
  5764. }// END OF AC_QUANTITY
  5765. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5766. }
  5767. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5768. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5769. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5770. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5771. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5772. }
  5773. //=================================== Power.Active.Import ==================================================
  5774. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5775. {
  5776. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5777. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5778. {
  5779. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5780. {
  5781. tempIndex = ((gun_index==2) ? 1: 0);
  5782. }
  5783. else
  5784. {
  5785. tempIndex = gun_index;
  5786. }
  5787. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5788. {
  5789. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5790. {
  5791. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5792. }
  5793. } // End for CHAdeMO_QUANTITY
  5794. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5795. }
  5796. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5797. {
  5798. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5799. {
  5800. tempIndex = ((gun_index==2) ? 1: 0);
  5801. }
  5802. else
  5803. {
  5804. tempIndex = gun_index;
  5805. }
  5806. for (int index = 0; index < CCS_QUANTITY; index++)
  5807. {
  5808. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5809. {
  5810. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5811. }
  5812. } // END for CCS_QUANTITY
  5813. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5814. }
  5815. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5816. {
  5817. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5818. {
  5819. tempIndex = ((gun_index==2) ? 1: 0);
  5820. }
  5821. else
  5822. {
  5823. tempIndex = gun_index;
  5824. }
  5825. for (int index = 0; index < GB_QUANTITY; index++)
  5826. {
  5827. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5828. {
  5829. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5830. }
  5831. }// END for GB_QUANTITY
  5832. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5833. }
  5834. else if(gunType[gun_index] == GUN_TYPE_DO)
  5835. {
  5836. tempIndex = gun_index;
  5837. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5838. {
  5839. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5840. {
  5841. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5842. }
  5843. }
  5844. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5845. }
  5846. else
  5847. {
  5848. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5849. {
  5850. tempIndex = 2;
  5851. }
  5852. else
  5853. {
  5854. tempIndex = gun_index;
  5855. }
  5856. for (int index = 0; index < AC_QUANTITY; index++)
  5857. {
  5858. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5859. {
  5860. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5861. }
  5862. } // END for AC_QUANTITY
  5863. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5864. }
  5865. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5866. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5867. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5868. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5869. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5870. }
  5871. //============================ Voltage L1 ====================================
  5872. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5873. {
  5874. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5875. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5876. {
  5877. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5878. {
  5879. tempIndex = ((gun_index==2) ? 1: 0);
  5880. }
  5881. else
  5882. {
  5883. tempIndex = gun_index;
  5884. }
  5885. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5886. {
  5887. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5888. {
  5889. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5890. }
  5891. } // END OF FOR CHAdeMO_QUANTITY
  5892. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5893. }
  5894. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5895. {
  5896. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5897. {
  5898. tempIndex = ((gun_index==2) ? 1: 0);
  5899. }
  5900. else
  5901. {
  5902. tempIndex = gun_index;
  5903. }
  5904. for (int index = 0; index < CCS_QUANTITY; index++)
  5905. {
  5906. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5907. {
  5908. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5909. }
  5910. } // END OF FOR CCS_QUANTITY
  5911. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5912. }
  5913. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5914. {
  5915. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5916. {
  5917. tempIndex = ((gun_index==2) ? 1: 0);
  5918. }
  5919. else
  5920. {
  5921. tempIndex = gun_index;
  5922. }
  5923. for (int index = 0; index < GB_QUANTITY; index++)
  5924. {
  5925. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5926. {
  5927. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5928. }
  5929. } // END OF FOR GB_QUANTITY
  5930. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5931. }
  5932. else if(gunType[gun_index] == GUN_TYPE_DO)
  5933. {
  5934. tempIndex = gun_index;
  5935. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5936. {
  5937. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5938. {
  5939. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5940. }
  5941. }
  5942. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5943. }
  5944. else
  5945. {
  5946. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5947. {
  5948. tempIndex = 2;
  5949. }
  5950. else
  5951. {
  5952. tempIndex = gun_index;
  5953. }
  5954. for (int index = 0; index < AC_QUANTITY; index++)
  5955. {
  5956. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5957. {
  5958. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  5959. }
  5960. } // END OF FOR AC_QUANTITY
  5961. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5962. }
  5963. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5964. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5965. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5966. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5967. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5968. }
  5969. //====================== End SoC ================================
  5970. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5971. {
  5972. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5973. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  5974. {
  5975. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5976. {
  5977. tempIndex = ((gun_index==2) ? 1: 0);
  5978. }
  5979. else
  5980. {
  5981. tempIndex = gun_index;
  5982. }
  5983. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5984. {
  5985. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5986. {
  5987. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5988. {
  5989. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5990. }
  5991. }
  5992. }
  5993. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5994. {
  5995. for (int index = 0; index < CCS_QUANTITY; index++)
  5996. {
  5997. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5998. {
  5999. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6000. }
  6001. }
  6002. }
  6003. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6004. {
  6005. for (int index = 0; index < GB_QUANTITY; index++)
  6006. {
  6007. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6008. {
  6009. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6010. }
  6011. }
  6012. }
  6013. else if(gunType[gun_index] == GUN_TYPE_DO)
  6014. {
  6015. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6016. {
  6017. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6018. {
  6019. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6020. }
  6021. }
  6022. }
  6023. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6024. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6025. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6026. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6027. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6028. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6029. } // END FOR DC CASE
  6030. }
  6031. // ================================= Current.Import L2 ===============================================
  6032. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6033. {
  6034. // AC 3 phse L2 current
  6035. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6036. {
  6037. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6038. {
  6039. tempIndex = 2;
  6040. }
  6041. else
  6042. {
  6043. tempIndex = gun_index;
  6044. }
  6045. for (int index = 0; index < AC_QUANTITY; index++)
  6046. {
  6047. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6048. {
  6049. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6050. }
  6051. }// End of for AC_QUANTITY
  6052. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6053. }
  6054. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6055. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6056. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6057. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6058. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6059. }
  6060. // ================================= Current.Import L3 ===============================================
  6061. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6062. {
  6063. // AC 3 phse L3 current
  6064. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6065. {
  6066. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6067. {
  6068. tempIndex = 2;
  6069. }
  6070. else
  6071. {
  6072. tempIndex = gun_index;
  6073. }
  6074. for (int index = 0; index < AC_QUANTITY; index++)
  6075. {
  6076. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6077. {
  6078. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6079. }
  6080. }// End of for AC_QUANTITY
  6081. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6082. }
  6083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6084. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6085. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6086. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6087. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6088. }
  6089. //============================ Voltage L2 ====================================
  6090. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6091. {
  6092. // AC 3 phse L2 voltage
  6093. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6094. {
  6095. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6096. {
  6097. tempIndex = 2;
  6098. }
  6099. else
  6100. {
  6101. tempIndex = gun_index;
  6102. }
  6103. for (int index = 0; index < AC_QUANTITY; index++)
  6104. {
  6105. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6106. {
  6107. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  6108. }
  6109. } // END OF FOR AC_QUANTITY
  6110. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6111. }
  6112. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6113. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6114. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6115. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6116. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6117. }
  6118. //============================ Voltage L3 ====================================
  6119. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6120. {
  6121. // AC 3 phse L3 voltage
  6122. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6123. {
  6124. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6125. {
  6126. tempIndex = 2;
  6127. }
  6128. else
  6129. {
  6130. tempIndex = gun_index;
  6131. }
  6132. for (int index = 0; index < AC_QUANTITY; index++)
  6133. {
  6134. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6135. {
  6136. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  6137. }
  6138. } // END OF FOR AC_QUANTITY
  6139. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6140. }
  6141. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6142. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6143. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6144. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6145. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6146. }
  6147. //====================== Start SoC ================================
  6148. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6149. {
  6150. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6151. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  6152. {
  6153. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6154. {
  6155. tempIndex = ((gun_index==2) ? 1: 0);
  6156. }
  6157. else
  6158. {
  6159. tempIndex = gun_index;
  6160. }
  6161. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6162. {
  6163. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6164. {
  6165. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6166. {
  6167. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6168. }
  6169. }
  6170. }
  6171. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6172. {
  6173. for (int index = 0; index < CCS_QUANTITY; index++)
  6174. {
  6175. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6176. {
  6177. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6178. }
  6179. }
  6180. }
  6181. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6182. {
  6183. for (int index = 0; index < GB_QUANTITY; index++)
  6184. {
  6185. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6186. {
  6187. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6188. }
  6189. }
  6190. }
  6191. else if(gunType[gun_index] == GUN_TYPE_DO)
  6192. {
  6193. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6194. {
  6195. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6196. {
  6197. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6198. }
  6199. }
  6200. }
  6201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6203. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6204. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6205. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6206. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6207. } // END FOR DC CASE
  6208. }
  6209. //================================================ Message create ====================================================
  6210. json_object *StopTransaction = json_object_new_object();
  6211. json_object *transactionDatas = json_object_new_array();
  6212. json_object *sampledValues = json_object_new_array();
  6213. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6214. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6215. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6216. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6217. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6218. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6219. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6220. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6221. {
  6222. json_object *transactionData = json_object_new_object();
  6223. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6224. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6225. {
  6226. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6227. {
  6228. json_object *sampledValue = json_object_new_object();
  6229. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6230. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6231. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6232. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6233. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6234. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6235. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6236. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6237. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6238. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6239. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6240. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6241. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6242. json_object_array_add(sampledValues, sampledValue);
  6243. }
  6244. }
  6245. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6246. json_object_array_add(transactionDatas, transactionData);
  6247. }
  6248. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6249. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6250. ,MESSAGE_TYPE_CALL
  6251. ,guid
  6252. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6253. json_object_put(StopTransaction);
  6254. #if 1 // for TempStopTransaction
  6255. //Delete TempStopTransaction
  6256. if((access(TempStopTransaction,F_OK))!=-1)
  6257. {
  6258. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6259. }
  6260. #endif
  6261. #if 1
  6262. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6263. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6264. {
  6265. result = PASS;
  6266. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6267. }
  6268. #endif
  6269. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6270. OCPP_insert_transaction_msg(NO, queuedata);
  6271. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6272. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6273. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6274. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6275. {
  6276. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6277. }
  6278. //for test
  6279. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6280. return result;
  6281. }
  6282. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6283. {
  6284. mtrace();
  6285. int result = FAIL;
  6286. char guid[37]={0};
  6287. char tempdata[65]={0};
  6288. int tempIndex = 0;
  6289. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6290. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6291. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6292. //set value
  6293. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6294. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6295. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6296. -1);
  6297. random_uuid(guid);
  6298. //UTC Date time
  6299. struct timeval tmnow;
  6300. struct tm *tm;
  6301. char buf[28];//, usec_buf[6];
  6302. gettimeofday(&tmnow, NULL);
  6303. time_t t;
  6304. t = time(NULL);
  6305. /*UTC time and date*/
  6306. tm = gmtime(&t);
  6307. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6308. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6309. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6310. //********************************(1)Current.Import L1************************************************/
  6311. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6312. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6313. (dataType == ReadingContext_Trigger))
  6314. {
  6315. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6316. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6317. {
  6318. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6319. {
  6320. tempIndex = ((gun_index==2) ? 1: 0);
  6321. }
  6322. else
  6323. {
  6324. tempIndex = gun_index;
  6325. }
  6326. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6327. {
  6328. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6329. {
  6330. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6331. }
  6332. }
  6333. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6334. }
  6335. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6336. {
  6337. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6338. {
  6339. tempIndex = ((gun_index==2) ? 1: 0);
  6340. }
  6341. else
  6342. {
  6343. tempIndex = gun_index;
  6344. }
  6345. for (int index = 0; index < CCS_QUANTITY; index++)
  6346. {
  6347. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6348. {
  6349. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6350. }
  6351. }
  6352. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6353. }
  6354. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6355. {
  6356. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6357. {
  6358. tempIndex = ((gun_index==2) ? 1: 0);
  6359. }
  6360. else
  6361. {
  6362. tempIndex = gun_index;
  6363. }
  6364. for (int index = 0; index < GB_QUANTITY; index++)
  6365. {
  6366. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6367. {
  6368. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6369. }
  6370. }
  6371. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6372. }
  6373. else if(gunType[gun_index] == GUN_TYPE_DO)
  6374. {
  6375. tempIndex = gun_index;
  6376. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6377. {
  6378. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6379. {
  6380. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6381. }
  6382. }
  6383. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6384. }
  6385. else
  6386. {
  6387. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6388. {
  6389. tempIndex = 2;
  6390. }
  6391. else
  6392. {
  6393. tempIndex = gun_index;
  6394. }
  6395. for (int index = 0; index < AC_QUANTITY; index++)
  6396. {
  6397. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6398. {
  6399. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6400. }
  6401. }
  6402. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6403. }
  6404. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6405. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6406. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6407. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6408. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6409. }
  6410. //********************************(2)Energy.Active.Import.Register ************************************************/
  6411. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6412. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6413. (dataType == ReadingContext_Trigger))
  6414. {
  6415. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6416. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6417. {
  6418. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6419. {
  6420. tempIndex = ((gun_index==2) ? 1: 0);
  6421. }
  6422. else
  6423. {
  6424. tempIndex = gun_index;
  6425. }
  6426. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6427. {
  6428. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6429. {
  6430. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6431. }
  6432. }
  6433. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6434. }
  6435. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6436. {
  6437. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6438. {
  6439. tempIndex = ((gun_index==2) ? 1: 0);
  6440. }
  6441. else
  6442. {
  6443. tempIndex = gun_index;
  6444. }
  6445. for (int index = 0; index < CCS_QUANTITY; index++)
  6446. {
  6447. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6448. {
  6449. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6450. }
  6451. }
  6452. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6453. }
  6454. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6455. {
  6456. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6457. {
  6458. tempIndex = ((gun_index==2) ? 1: 0);
  6459. }
  6460. else
  6461. {
  6462. tempIndex = gun_index;
  6463. }
  6464. for (int index = 0; index < GB_QUANTITY; index++)
  6465. {
  6466. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6467. {
  6468. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6469. }
  6470. }
  6471. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6472. }
  6473. else if(gunType[gun_index] == GUN_TYPE_DO)
  6474. {
  6475. tempIndex = gun_index;
  6476. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6477. {
  6478. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6479. {
  6480. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6481. }
  6482. }
  6483. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6484. }
  6485. else
  6486. {
  6487. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6488. {
  6489. tempIndex = 2;
  6490. }
  6491. else
  6492. {
  6493. tempIndex = gun_index;
  6494. }
  6495. for (int index = 0; index < AC_QUANTITY; index++)
  6496. {
  6497. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6498. {
  6499. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6500. }
  6501. }
  6502. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6503. }
  6504. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6505. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6506. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6507. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6508. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6509. }
  6510. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6511. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6512. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6513. (dataType == ReadingContext_Trigger))
  6514. {
  6515. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6516. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6517. {
  6518. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6519. {
  6520. tempIndex = ((gun_index==2) ? 1: 0);
  6521. }
  6522. else
  6523. {
  6524. tempIndex = gun_index;
  6525. }
  6526. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6527. {
  6528. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6529. {
  6530. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6531. }
  6532. } // END OF FOR CHAdeMO_QUANTITY
  6533. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6534. }
  6535. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6536. {
  6537. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6538. {
  6539. tempIndex = ((gun_index==2) ? 1: 0);
  6540. }
  6541. else
  6542. {
  6543. tempIndex = gun_index;
  6544. }
  6545. for (int index = 0; index < CCS_QUANTITY; index++)
  6546. {
  6547. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6548. {
  6549. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6550. }
  6551. } // END OF CCS_QUANTITY
  6552. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6553. }
  6554. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6555. {
  6556. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6557. {
  6558. tempIndex = ((gun_index==2) ? 1: 0);
  6559. }
  6560. else
  6561. {
  6562. tempIndex = gun_index;
  6563. }
  6564. for (int index = 0; index < GB_QUANTITY; index++)
  6565. {
  6566. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6567. {
  6568. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6569. }
  6570. } // END OF GB_QUANTITY
  6571. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6572. }
  6573. else if(gunType[gun_index] == GUN_TYPE_DO)
  6574. {
  6575. tempIndex = gun_index;
  6576. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6577. {
  6578. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6579. {
  6580. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6581. }
  6582. }
  6583. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6584. }
  6585. else
  6586. {
  6587. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6588. {
  6589. tempIndex = 2;
  6590. }
  6591. else
  6592. {
  6593. tempIndex = gun_index;
  6594. }
  6595. for (int index = 0; index < AC_QUANTITY; index++)
  6596. {
  6597. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6598. {
  6599. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6600. }
  6601. }
  6602. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6603. }
  6604. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6605. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6606. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6607. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6608. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6609. }
  6610. //********************************(4)Power.Active.Import************************************************/
  6611. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6612. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6613. (dataType == ReadingContext_Trigger))
  6614. {
  6615. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6616. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6617. {
  6618. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6619. {
  6620. tempIndex = ((gun_index==2) ? 1: 0);
  6621. }
  6622. else
  6623. {
  6624. tempIndex = gun_index;
  6625. }
  6626. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6627. {
  6628. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6629. {
  6630. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6631. }
  6632. } // END OF FOR
  6633. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6634. }
  6635. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6636. {
  6637. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6638. {
  6639. tempIndex = ((gun_index==2) ? 1: 0);
  6640. }
  6641. else
  6642. {
  6643. tempIndex = gun_index;
  6644. }
  6645. for (int index = 0; index < CCS_QUANTITY; index++)
  6646. {
  6647. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6648. {
  6649. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6650. }
  6651. }
  6652. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6653. }
  6654. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6655. {
  6656. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6657. {
  6658. tempIndex = ((gun_index==2) ? 1: 0);
  6659. }
  6660. else
  6661. {
  6662. tempIndex = gun_index;
  6663. }
  6664. for (int index = 0; index < GB_QUANTITY; index++)
  6665. {
  6666. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6667. {
  6668. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6669. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6670. }
  6671. }
  6672. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6673. }
  6674. else if(gunType[gun_index] == GUN_TYPE_DO)
  6675. {
  6676. tempIndex = gun_index;
  6677. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6678. {
  6679. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6680. {
  6681. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6682. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6683. }
  6684. }
  6685. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6686. }
  6687. else
  6688. {
  6689. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6690. {
  6691. tempIndex = 2;
  6692. }
  6693. else
  6694. {
  6695. tempIndex = gun_index;
  6696. }
  6697. for (int index = 0; index < AC_QUANTITY; index++)
  6698. {
  6699. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6700. {
  6701. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6702. }
  6703. }
  6704. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6705. }
  6706. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6707. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6708. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6709. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6710. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6711. }
  6712. //***********************************************(5)VOLTAGE L1******************************************************/
  6713. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6714. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6715. (dataType == ReadingContext_Trigger))
  6716. {
  6717. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6718. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6719. {
  6720. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6721. {
  6722. tempIndex = ((gun_index==2) ? 1: 0);
  6723. }
  6724. else
  6725. {
  6726. tempIndex = gun_index;
  6727. }
  6728. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6729. {
  6730. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6731. {
  6732. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6733. }
  6734. }
  6735. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6736. }
  6737. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6738. {
  6739. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6740. {
  6741. tempIndex = ((gun_index==2) ? 1: 0);
  6742. }
  6743. else
  6744. {
  6745. tempIndex = gun_index;
  6746. }
  6747. for (int index = 0; index < CCS_QUANTITY; index++)
  6748. {
  6749. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6750. {
  6751. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6752. }
  6753. }
  6754. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6755. }
  6756. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6757. {
  6758. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6759. {
  6760. tempIndex = ((gun_index==2) ? 1: 0);
  6761. }
  6762. else
  6763. {
  6764. tempIndex = gun_index;
  6765. }
  6766. for (int index = 0; index < GB_QUANTITY; index++)
  6767. {
  6768. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6769. {
  6770. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6771. }
  6772. }
  6773. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6774. }
  6775. else if(gunType[gun_index] == GUN_TYPE_DO)
  6776. {
  6777. tempIndex = gun_index;
  6778. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6779. {
  6780. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6781. {
  6782. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6783. }
  6784. }
  6785. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6786. }
  6787. else
  6788. {
  6789. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6790. {
  6791. tempIndex = 2;
  6792. }
  6793. else
  6794. {
  6795. tempIndex = gun_index;
  6796. }
  6797. for (int index = 0; index < AC_QUANTITY; index++)
  6798. {
  6799. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6800. {
  6801. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6802. }
  6803. }
  6804. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6805. }
  6806. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6807. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6808. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6809. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6810. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6811. }
  6812. //***********************************************(6)SOC******************************************************/
  6813. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6814. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6815. (dataType == ReadingContext_Trigger))
  6816. {
  6817. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  6818. {
  6819. //idx_sample=5;
  6820. //sampledValue = NULL;
  6821. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6822. {
  6823. tempIndex = ((gun_index==2) ? 1: 0);
  6824. }
  6825. else
  6826. {
  6827. tempIndex = gun_index;
  6828. }
  6829. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6830. {
  6831. //tempIndex = ((gun_index==2) ? 1: 0);
  6832. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6833. {
  6834. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6835. {
  6836. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6837. }
  6838. }
  6839. }
  6840. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6841. {
  6842. //tempIndex = ((gun_index==2) ? 1: 0);
  6843. for (int index = 0; index < CCS_QUANTITY; index++)
  6844. {
  6845. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6846. {
  6847. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6848. }
  6849. }
  6850. }
  6851. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6852. {
  6853. //tempIndex = ((gun_index==2) ? 1: 0);
  6854. for (int index = 0; index < GB_QUANTITY; index++)
  6855. {
  6856. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6857. {
  6858. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6859. }
  6860. }
  6861. }
  6862. else if(gunType[gun_index] == GUN_TYPE_DO)
  6863. {
  6864. //tempIndex = ((gun_index==2) ? 1: 0);
  6865. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6866. {
  6867. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6868. {
  6869. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6870. }
  6871. }
  6872. }
  6873. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6874. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6875. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6876. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6877. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6878. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6879. }
  6880. }
  6881. //********************************(7)Current.Import L2************************************************/
  6882. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6883. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6884. (dataType == ReadingContext_Trigger))
  6885. {
  6886. // Only for AC 3 phase
  6887. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6888. {
  6889. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6890. {
  6891. tempIndex = 2;
  6892. }
  6893. else
  6894. {
  6895. tempIndex = gun_index;
  6896. }
  6897. for (int index = 0; index < AC_QUANTITY; index++)
  6898. {
  6899. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6900. {
  6901. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6902. }
  6903. }
  6904. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6905. }
  6906. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6907. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6908. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6909. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6910. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6911. }
  6912. //********************************(8)Current.Import L3************************************************/
  6913. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6914. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6915. (dataType == ReadingContext_Trigger))
  6916. {
  6917. // Only for AC 3 phase
  6918. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6919. {
  6920. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6921. {
  6922. tempIndex = 2;
  6923. }
  6924. else
  6925. {
  6926. tempIndex = gun_index;
  6927. }
  6928. for (int index = 0; index < AC_QUANTITY; index++)
  6929. {
  6930. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6931. {
  6932. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6933. }
  6934. }
  6935. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6936. }
  6937. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6938. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6939. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6940. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6941. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6942. }
  6943. //***********************************************(9)VOLTAGE L2******************************************************/
  6944. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6945. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6946. (dataType == ReadingContext_Trigger))
  6947. {
  6948. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6949. {
  6950. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6951. {
  6952. tempIndex = 2;
  6953. }
  6954. else
  6955. {
  6956. tempIndex = gun_index;
  6957. }
  6958. for (int index = 0; index < AC_QUANTITY; index++)
  6959. {
  6960. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6961. {
  6962. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6963. }
  6964. }
  6965. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6966. }
  6967. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6968. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6969. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6970. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6971. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6972. }
  6973. //***********************************************(10)VOLTAGE L3******************************************************/
  6974. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6975. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6976. (dataType == ReadingContext_Trigger))
  6977. {
  6978. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6979. {
  6980. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6981. {
  6982. tempIndex = 2;
  6983. }
  6984. else
  6985. {
  6986. tempIndex = gun_index;
  6987. }
  6988. for (int index = 0; index < AC_QUANTITY; index++)
  6989. {
  6990. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6991. {
  6992. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6993. }
  6994. }
  6995. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6996. }
  6997. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6998. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6999. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7000. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7001. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7002. }
  7003. //***********************************************(11)Current.Offered******************************************************/
  7004. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7005. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7006. (dataType == ReadingContext_Trigger))
  7007. {
  7008. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7009. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7010. {
  7011. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7012. {
  7013. tempIndex = ((gun_index==2) ? 1: 0);
  7014. }
  7015. else
  7016. {
  7017. tempIndex = gun_index;
  7018. }
  7019. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7020. {
  7021. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7022. {
  7023. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7024. }
  7025. } // END OF FOR CHAdeMO_QUANTITY
  7026. }
  7027. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7028. {
  7029. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7030. {
  7031. tempIndex = ((gun_index==2) ? 1: 0);
  7032. }
  7033. else
  7034. {
  7035. tempIndex = gun_index;
  7036. }
  7037. for (int index = 0; index < CCS_QUANTITY; index++)
  7038. {
  7039. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7040. {
  7041. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7042. }
  7043. } // END OF CCS_QUANTITY
  7044. }
  7045. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7046. {
  7047. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7048. {
  7049. tempIndex = ((gun_index==2) ? 1: 0);
  7050. }
  7051. else
  7052. {
  7053. tempIndex = gun_index;
  7054. }
  7055. for (int index = 0; index < GB_QUANTITY; index++)
  7056. {
  7057. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7058. {
  7059. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7060. }
  7061. } // END OF GB_QUANTITY
  7062. }
  7063. else if(gunType[gun_index] == GUN_TYPE_DO)
  7064. {
  7065. tempIndex = gun_index;
  7066. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7067. {
  7068. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7069. {
  7070. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7071. }
  7072. }
  7073. }
  7074. else
  7075. {
  7076. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7077. {
  7078. tempIndex = 2;
  7079. }
  7080. else
  7081. {
  7082. tempIndex = gun_index;
  7083. }
  7084. for (int index = 0; index < AC_QUANTITY; index++)
  7085. {
  7086. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7087. {
  7088. uint16_t currentOffer;
  7089. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7090. {
  7091. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7092. }
  7093. else
  7094. {
  7095. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7096. }
  7097. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7098. }
  7099. }
  7100. }
  7101. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7102. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7103. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7104. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7105. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7106. }
  7107. //***********************************************(12)Power.Offered******************************************************/
  7108. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7109. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7110. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7111. {
  7112. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7113. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7114. {
  7115. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7116. {
  7117. tempIndex = ((gun_index==2) ? 1: 0);
  7118. }
  7119. else
  7120. {
  7121. tempIndex = gun_index;
  7122. }
  7123. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7124. {
  7125. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7126. {
  7127. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7128. }
  7129. } // END OF FOR CHAdeMO_QUANTITY
  7130. }
  7131. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7132. {
  7133. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7134. {
  7135. tempIndex = ((gun_index==2) ? 1: 0);
  7136. }
  7137. else
  7138. {
  7139. tempIndex = gun_index;
  7140. }
  7141. for (int index = 0; index < CCS_QUANTITY; index++)
  7142. {
  7143. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7144. {
  7145. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7146. }
  7147. } // END OF CCS_QUANTITY
  7148. }
  7149. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7150. {
  7151. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7152. {
  7153. tempIndex = ((gun_index==2) ? 1: 0);
  7154. }
  7155. else
  7156. {
  7157. tempIndex = gun_index;
  7158. }
  7159. for (int index = 0; index < GB_QUANTITY; index++)
  7160. {
  7161. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7162. {
  7163. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7164. }
  7165. } // END OF GB_QUANTITY
  7166. }
  7167. else if(gunType[gun_index] == GUN_TYPE_DO)
  7168. {
  7169. tempIndex = gun_index;
  7170. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7171. {
  7172. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7173. {
  7174. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7175. }
  7176. }
  7177. }
  7178. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7179. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7180. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7181. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7182. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7183. }
  7184. // Message create ====================================================================================================
  7185. if(TRUE)
  7186. {
  7187. json_object *MeterValueReq = json_object_new_object();
  7188. json_object *MeterValues = json_object_new_array();
  7189. json_object *sampledValues = json_object_new_array();
  7190. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7191. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7192. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7193. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7194. {
  7195. json_object *MeterValue = json_object_new_object();
  7196. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7197. {
  7198. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7199. {
  7200. json_object *sampledValue = json_object_new_object();
  7201. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7202. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7203. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7204. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7205. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7206. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7207. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7208. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7209. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7210. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7211. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7212. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7213. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7214. json_object_array_add(sampledValues, sampledValue);
  7215. }
  7216. }
  7217. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7218. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7219. json_object_array_add(MeterValues, MeterValue);
  7220. }
  7221. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7222. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7223. ,gun_index + 1
  7224. ,MESSAGE_TYPE_CALL
  7225. ,guid
  7226. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7227. json_object_put(MeterValueReq);
  7228. }
  7229. // Put request guid to hash map
  7230. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7231. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  7232. {
  7233. result = PASS;
  7234. //DEBUG_INFO("MeterValues mapitem pass\n");
  7235. }
  7236. if((dataType != ReadingContext_Trigger) &&
  7237. (dataType != ReadingContext_Sample_Clock) &&
  7238. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7239. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7240. else
  7241. {
  7242. if(FirstHeartBeat)
  7243. LWS_Send(queuedata +2);
  7244. }
  7245. return result;
  7246. }
  7247. int sendLogStatusNotificationRequest(char *status)
  7248. {
  7249. mtrace();
  7250. int result = PASS;
  7251. char message[4096]={0};
  7252. char guid[37]={0};
  7253. char tempdata[128]={0};
  7254. json_object *LogStatusNotification = json_object_new_object();
  7255. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7256. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7257. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7258. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7259. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7260. random_uuid(guid);
  7261. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7262. json_object_put(LogStatusNotification);
  7263. LWS_Send(message);
  7264. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7265. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7266. {
  7267. result = PASS;
  7268. }
  7269. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7270. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7271. return result;
  7272. }
  7273. int sendSecurityEventNotificationRequest()
  7274. {
  7275. mtrace();
  7276. int result = PASS;
  7277. char message[4096]={0};
  7278. char guid[37]={0};
  7279. char tempdata[128]={0};
  7280. json_object *SecurityEventNotification = json_object_new_object();
  7281. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7282. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7283. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7284. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7285. random_uuid(guid);
  7286. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7287. json_object_put(SecurityEventNotification);
  7288. LWS_Send(message);
  7289. sprintf(tempdata, "SecurityEventNotification,0");
  7290. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7291. {
  7292. result = PASS;
  7293. }
  7294. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7295. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7296. return result;
  7297. }
  7298. int sendSignCertificateRequest()
  7299. {
  7300. mtrace();
  7301. int result = PASS;
  7302. char message[4096]={0};
  7303. char guid[37]={0};
  7304. char tempdata[128]={0};
  7305. json_object *SignCertificate = json_object_new_object();
  7306. DEBUG_INFO("sendSignCertificateRequest...\n");
  7307. // Read csr file content
  7308. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7309. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7310. char *line = NULL;
  7311. size_t len = 0;
  7312. while(getline(&line, &len, fp) != -1)
  7313. {
  7314. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7315. {
  7316. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7317. }
  7318. }
  7319. fclose(fp);
  7320. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7321. random_uuid(guid);
  7322. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7323. json_object_put(SignCertificate);
  7324. LWS_Send(message);
  7325. sprintf(tempdata, "SignCertificate,0");
  7326. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7327. {
  7328. result = PASS;
  7329. }
  7330. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7331. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7332. return result;
  7333. }
  7334. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7335. {
  7336. mtrace();
  7337. int result = PASS;
  7338. char message[110]={0};
  7339. char guid[37]={0};
  7340. char tempdata[65]={0};
  7341. json_object *FirmwareStatusNotification = json_object_new_object();
  7342. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7343. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7344. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7345. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7346. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7347. random_uuid(guid);
  7348. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7349. json_object_put(FirmwareStatusNotification);
  7350. LWS_Send(message);
  7351. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7352. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7353. {
  7354. result = PASS;
  7355. }
  7356. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7357. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7358. return result;
  7359. }
  7360. //==========================================
  7361. // send confirm routine
  7362. //==========================================
  7363. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7364. {
  7365. mtrace();
  7366. int result = FAIL;
  7367. char message[100]={0};
  7368. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7369. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7370. LWS_Send(message);
  7371. result = TRUE;
  7372. return result;
  7373. }
  7374. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7375. {
  7376. mtrace();
  7377. int result = FAIL;
  7378. char message[100]={0};
  7379. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7380. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7381. LWS_Send(message);
  7382. result = TRUE;
  7383. return result;
  7384. }
  7385. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7386. {
  7387. mtrace();
  7388. int result = FAIL;
  7389. char message[100]={0};
  7390. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7391. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7392. LWS_Send(message);
  7393. result = TRUE;
  7394. return result;
  7395. }
  7396. int sendClearCacheConfirmation(char *uuid,char *payload)
  7397. {
  7398. mtrace();
  7399. int result = FAIL;
  7400. char message[500]={0};
  7401. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7402. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7403. LWS_Send(message);
  7404. return result;
  7405. }
  7406. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7407. {
  7408. mtrace();
  7409. int result = FAIL;
  7410. char message[500]={0};
  7411. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7412. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7413. LWS_Send(message);
  7414. return result;
  7415. }
  7416. int sendDataTransferConfirmation(char *uuid,char *payload)
  7417. {
  7418. mtrace();
  7419. char statusStr[20]={0};
  7420. char dataStr[10]={0};
  7421. char sstr[20]={0};
  7422. int c = 0;
  7423. char *loc;
  7424. int result = FAIL;
  7425. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7426. /**********************status**************************/
  7427. loc = strstr(payload, "status");
  7428. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7429. c = 0;
  7430. while (loc[3+strlen("status")+c] != '\"')
  7431. {
  7432. sstr[c] = loc[3+strlen("status")+c];
  7433. c++;
  7434. }
  7435. sstr[c] = '\0';
  7436. strcpy(statusStr, sstr);
  7437. /**********************data**************************/
  7438. loc = strstr(payload, "data");
  7439. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7440. c = 0;
  7441. while (loc[3+strlen("data")+c] != '\"')
  7442. {
  7443. sstr[c] = loc[3+strlen("data")+c];
  7444. c++;
  7445. }
  7446. sstr[c] = '\0';
  7447. strcpy(dataStr, sstr);
  7448. return result;
  7449. }
  7450. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7451. {
  7452. mtrace();
  7453. int result = FAIL;
  7454. char message[1000]={0};
  7455. int CompositeScheduleIndex = 0;
  7456. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7457. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7458. if(nPeriod == 0)
  7459. {
  7460. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7461. {
  7462. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7463. ,MESSAGE_TYPE_CALLRESULT
  7464. ,uuid
  7465. ,payload
  7466. ,connectorIdInt);
  7467. }
  7468. else
  7469. {
  7470. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7471. ,MESSAGE_TYPE_CALLRESULT
  7472. ,uuid
  7473. ,payload
  7474. ,connectorIdInt
  7475. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7476. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7477. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7478. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7479. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7480. }
  7481. }
  7482. else
  7483. {
  7484. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7485. ,MESSAGE_TYPE_CALLRESULT
  7486. ,uuid
  7487. ,payload
  7488. ,connectorIdInt
  7489. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7490. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7491. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7492. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7493. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7494. {
  7495. if (idx_sample == 0)
  7496. {
  7497. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7498. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7499. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7500. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7501. }
  7502. else
  7503. {
  7504. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7505. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7506. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7507. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7508. }
  7509. }
  7510. sprintf(message + strlen(message), "]}}]");
  7511. }
  7512. LWS_Send(message);
  7513. result = TRUE;
  7514. return result;
  7515. }
  7516. int sendGetConfigurationConfirmation(char *uuid)
  7517. {
  7518. mtrace();
  7519. int result = FAIL;
  7520. int MaxKeySupported = 0;
  7521. int sentConfigurationNumber= 0;
  7522. int sentunConfigurationNumber= 0;
  7523. char message[1024*10]={0};
  7524. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7525. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7526. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7527. ,MESSAGE_TYPE_CALLRESULT
  7528. ,uuid );
  7529. //configuration key
  7530. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7531. {
  7532. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7533. {
  7534. if (sentConfigurationNumber == 0)
  7535. {
  7536. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7537. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7538. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7539. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7540. }
  7541. else
  7542. {
  7543. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7544. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7545. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7546. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7547. }
  7548. sentConfigurationNumber = sentConfigurationNumber + 1;
  7549. }
  7550. }
  7551. sprintf(message + strlen(message), "]");
  7552. if(UnknownKeynum != 0)
  7553. {
  7554. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7555. //unkown key
  7556. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7557. {
  7558. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7559. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7560. if(sentunConfigurationNumber == 0)
  7561. {
  7562. sprintf(message + strlen(message), "\"%s\""
  7563. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7564. }
  7565. else
  7566. {
  7567. sprintf(message + strlen(message), ",\"%s\""
  7568. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7569. }
  7570. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7571. }
  7572. sprintf(message + strlen(message), "]");
  7573. }
  7574. sprintf(message + strlen(message), "}]");
  7575. LWS_Send(message);
  7576. return result;
  7577. }
  7578. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7579. {
  7580. mtrace();
  7581. int result = FAIL;
  7582. char message[400]={0};
  7583. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7584. if(strcmp(payload,"")==0)
  7585. {
  7586. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7587. }
  7588. else
  7589. {
  7590. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7591. }
  7592. LWS_Send(message);
  7593. result = TRUE;
  7594. return result;
  7595. }
  7596. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7597. {
  7598. mtrace();
  7599. int result = FAIL;
  7600. char message[80]={0};
  7601. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7602. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  7603. LWS_Send(message);
  7604. result = TRUE;
  7605. return result;
  7606. }
  7607. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7608. {
  7609. mtrace();
  7610. int result = FAIL;
  7611. char message[80]={0};
  7612. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7613. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7614. LWS_Send(message);
  7615. result = TRUE;
  7616. return result;
  7617. }
  7618. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7619. {
  7620. mtrace();
  7621. int result = FAIL;
  7622. char message[80]={0};
  7623. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7624. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7625. LWS_Send(message);
  7626. result = TRUE;
  7627. return result;
  7628. }
  7629. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7630. {
  7631. mtrace();
  7632. int result = FAIL;
  7633. char message[80]={0};
  7634. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7635. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7636. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7637. LWS_Send(message);
  7638. result = TRUE;
  7639. return result;
  7640. }
  7641. int sendResetConfirmation(char *uuid,char *payload)
  7642. {
  7643. mtrace();
  7644. int result = FAIL;
  7645. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7646. char message[80]={0};
  7647. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  7648. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7649. LWS_Send(message);
  7650. result = TRUE;
  7651. return result;
  7652. }
  7653. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7654. {
  7655. mtrace();
  7656. int result = FAIL;
  7657. char message[500]={0};
  7658. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7659. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7660. LWS_Send(message);
  7661. result = TRUE;
  7662. return result;
  7663. }
  7664. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7665. {
  7666. mtrace();
  7667. int result = FAIL;
  7668. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7669. char message[80]={0};
  7670. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7671. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7672. LWS_Send(message);
  7673. result = TRUE;
  7674. return result;
  7675. }
  7676. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7677. {
  7678. mtrace();
  7679. int result = FAIL;
  7680. char message[80]={0};
  7681. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7682. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7683. LWS_Send(message);
  7684. result = TRUE;
  7685. return result;
  7686. }
  7687. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7688. {
  7689. mtrace();
  7690. int result = FAIL;
  7691. char message[80]={0};
  7692. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7693. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7694. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7695. LWS_Send(message);
  7696. result = TRUE;
  7697. return result;
  7698. }
  7699. int sendUpdateFirmwareConfirmation(char *uuid)
  7700. {
  7701. mtrace();
  7702. int result = FAIL;
  7703. char message[60]={0};
  7704. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7705. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7706. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7707. LWS_Send(message);
  7708. result = TRUE;
  7709. return result;
  7710. }
  7711. int sendCertificateSignedConfirmation(char *uuid)
  7712. {
  7713. mtrace();
  7714. int result = PASS;
  7715. char message[4096]={0};
  7716. json_object *CertificateSigned = json_object_new_object();
  7717. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7718. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  7719. sprintf(message,"[%d,\"%s\",%s]"
  7720. ,MESSAGE_TYPE_CALLRESULT
  7721. ,uuid
  7722. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7723. json_object_put(CertificateSigned);
  7724. LWS_Send(message);
  7725. return result;
  7726. }
  7727. int sendDeleteCertificateConfirmation(char *uuid)
  7728. {
  7729. mtrace();
  7730. int result = PASS;
  7731. char message[4096]={0};
  7732. json_object *DeleteCertificate = json_object_new_object();
  7733. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7734. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  7735. sprintf(message,"[%d,\"%s\",%s]"
  7736. ,MESSAGE_TYPE_CALLRESULT
  7737. ,uuid
  7738. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7739. json_object_put(DeleteCertificate);
  7740. LWS_Send(message);
  7741. return result;
  7742. }
  7743. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7744. {
  7745. mtrace();
  7746. int result = PASS;
  7747. char message[4096]={0};
  7748. json_object *ExtendedTriggerMessage = json_object_new_object();
  7749. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7750. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  7751. sprintf(message,"[%d,\"%s\",%s]"
  7752. ,MESSAGE_TYPE_CALLRESULT
  7753. ,uuid
  7754. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7755. json_object_put(ExtendedTriggerMessage);
  7756. LWS_Send(message);
  7757. return result;
  7758. }
  7759. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7760. {
  7761. mtrace();
  7762. int result = PASS;
  7763. char message[4096]={0};
  7764. json_object *GetInstalledCertificateIds = json_object_new_object();
  7765. json_object *certificateHashDataDatas = json_object_new_array();
  7766. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7767. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  7768. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7769. {
  7770. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7771. {
  7772. json_object *certificateHashData = json_object_new_object();
  7773. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7774. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7775. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7776. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7777. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7778. }
  7779. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7780. }
  7781. else
  7782. {
  7783. json_object_put(certificateHashDataDatas);
  7784. }
  7785. sprintf(message,"[%d,\"%s\",%s]"
  7786. ,MESSAGE_TYPE_CALLRESULT
  7787. ,uuid
  7788. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7789. json_object_put(GetInstalledCertificateIds);
  7790. LWS_Send(message);
  7791. return result;
  7792. }
  7793. int sendGetLogConfirmation(char *uuid)
  7794. {
  7795. mtrace();
  7796. int result = PASS;
  7797. char message[4096]={0};
  7798. json_object *GetLog = json_object_new_object();
  7799. DEBUG_INFO("sendGetLogConfirmation...\n");
  7800. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  7801. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  7802. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  7803. sprintf(message,"[%d,\"%s\",%s]"
  7804. ,MESSAGE_TYPE_CALLRESULT
  7805. ,uuid
  7806. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7807. json_object_put(GetLog);
  7808. LWS_Send(message);
  7809. return result;
  7810. }
  7811. int sendInstallCertificateConfirmation(char *uuid)
  7812. {
  7813. mtrace();
  7814. int result = PASS;
  7815. char message[4096]={0};
  7816. json_object *InstallCertificate = json_object_new_object();
  7817. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7818. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  7819. sprintf(message,"[%d,\"%s\",%s]"
  7820. ,MESSAGE_TYPE_CALLRESULT
  7821. ,uuid
  7822. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7823. json_object_put(InstallCertificate);
  7824. LWS_Send(message);
  7825. return result;
  7826. }
  7827. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7828. {
  7829. mtrace();
  7830. int result = PASS;
  7831. char message[4096]={0};
  7832. json_object *SignedUpdateFirmware = json_object_new_object();
  7833. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7834. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  7835. sprintf(message,"[%d,\"%s\",%s]"
  7836. ,MESSAGE_TYPE_CALLRESULT
  7837. ,uuid
  7838. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7839. json_object_put(SignedUpdateFirmware);
  7840. LWS_Send(message);
  7841. return result;
  7842. }
  7843. int sendUnknownConfirmation(char *uuid)
  7844. {
  7845. mtrace();
  7846. int result = PASS;
  7847. char message[256]={0};
  7848. DEBUG_INFO("sendUnknownConfirmation...\n");
  7849. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7850. LWS_Send(message);
  7851. return result;
  7852. }
  7853. //==========================================
  7854. // Handle server request routine Start
  7855. //==========================================
  7856. int handleCancelReservationRequest(char *uuid, char *payload)
  7857. {
  7858. mtrace();
  7859. int result = FAIL;
  7860. int gunNO = 0;
  7861. int reservationIdInt = -1;
  7862. char comfirmstr[20];
  7863. DEBUG_INFO("handleCancelReservationRequest...\n");
  7864. json_object *CancelReservation;
  7865. CancelReservation = json_tokener_parse(payload);
  7866. if(!is_error(CancelReservation))
  7867. {
  7868. // Required data
  7869. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7870. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7871. }
  7872. json_object_put(CancelReservation);
  7873. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7874. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7875. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7876. if(reservationIdInt != -1)
  7877. {
  7878. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7879. //check Transaction active
  7880. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7881. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7882. {
  7883. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7884. {
  7885. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7886. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7887. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7888. {
  7889. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7890. }
  7891. else
  7892. {
  7893. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7894. }
  7895. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7896. goto end;
  7897. }
  7898. }
  7899. for (int index = 0; index < CCS_QUANTITY; index++)
  7900. {
  7901. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7902. {
  7903. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7904. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7905. if(gunType[2] == GUN_TYPE_CCS)
  7906. {
  7907. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7908. }
  7909. else
  7910. {
  7911. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7912. }
  7913. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7914. goto end;
  7915. }
  7916. }
  7917. for (int index = 0; index < GB_QUANTITY; index++)
  7918. {
  7919. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7920. {
  7921. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7922. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7923. if(gunType[2] == GUN_TYPE_GBT)
  7924. {
  7925. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7926. }
  7927. else
  7928. {
  7929. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7930. }
  7931. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7932. goto end;
  7933. }
  7934. }
  7935. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7936. {
  7937. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7938. {
  7939. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7940. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7941. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7942. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7943. goto end;
  7944. }
  7945. }
  7946. for (int index = 0; index < AC_QUANTITY; index++)
  7947. {
  7948. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7949. {
  7950. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7951. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7952. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7953. {
  7954. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7955. }
  7956. else
  7957. {
  7958. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7959. }
  7960. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7961. goto end;
  7962. }
  7963. }
  7964. }
  7965. //The reservationId does NOT match the reservationId
  7966. sendCancelReservationConfirmation(uuid, comfirmstr);
  7967. end:
  7968. // Fill in ocpp packet uuid
  7969. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  7970. return result;
  7971. }
  7972. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7973. {
  7974. mtrace();
  7975. int result = FAIL;
  7976. int gunIndex = -1;
  7977. char typeStr[16]={0};
  7978. char comfirmstr[20];
  7979. int specificId = FALSE;
  7980. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7981. json_object *ChangeAvailability;
  7982. ChangeAvailability = json_tokener_parse(payload);
  7983. if(!is_error(ChangeAvailability))
  7984. {
  7985. // Required data
  7986. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7987. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7988. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7989. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7990. }
  7991. json_object_put(ChangeAvailability);
  7992. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7993. {
  7994. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7995. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7996. }
  7997. else if(gunIndex == 0)
  7998. {
  7999. for(int i=0; i < gunTotalNumber; i++)
  8000. {
  8001. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8002. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8003. }
  8004. }
  8005. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8006. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8007. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8008. {
  8009. specificId = TRUE;
  8010. }
  8011. if(specificId == FALSE)
  8012. goto end;
  8013. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8014. {
  8015. //----------------------gunIndex is 0 ------------------------------------------------//
  8016. if(gunIndex == 0)
  8017. {
  8018. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8019. {
  8020. for(int i=0; i < gunTotalNumber; i++)
  8021. {
  8022. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8023. {
  8024. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8025. {
  8026. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8027. {
  8028. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8029. goto end;
  8030. }
  8031. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8032. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8033. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8034. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8035. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8036. {
  8037. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8038. goto end;
  8039. }
  8040. }
  8041. }//END FOR CHAdeMO_QUANTITY
  8042. for (int index = 0; index < CCS_QUANTITY; index++)
  8043. {
  8044. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8045. {
  8046. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8047. {
  8048. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8049. goto end;
  8050. }
  8051. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8052. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8053. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8054. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8055. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8056. {
  8057. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8058. goto end;
  8059. }
  8060. }
  8061. }//END FOR CCS_QUANTITY
  8062. for (int index = 0; index < GB_QUANTITY; index++)
  8063. {
  8064. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8065. {
  8066. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8067. {
  8068. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8069. goto end;
  8070. }
  8071. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8072. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8073. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8074. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8075. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8076. {
  8077. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8078. goto end;
  8079. }
  8080. }
  8081. }// END FOR GB_QUANTITY
  8082. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8083. {
  8084. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8085. {
  8086. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8087. {
  8088. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8089. goto end;
  8090. }
  8091. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8092. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8093. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8094. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8095. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8096. {
  8097. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8098. goto end;
  8099. }
  8100. }
  8101. }// END FOR GENERAL_GUN_QUANTITY
  8102. for (int index = 0; index < AC_QUANTITY; index++)
  8103. {
  8104. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8105. {
  8106. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8107. {
  8108. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8109. goto end;
  8110. }
  8111. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8112. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8113. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8114. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8115. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8116. {
  8117. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8118. goto end;
  8119. }
  8120. }
  8121. }//END FOR AC_QUANTITY
  8122. }// END FOR gunTotalNumber
  8123. }
  8124. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8125. {
  8126. for(int i=0; i < gunTotalNumber; i++)
  8127. {
  8128. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8129. {
  8130. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8131. goto end;
  8132. }
  8133. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8134. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8135. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8136. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8137. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8138. {
  8139. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8140. goto end;
  8141. }
  8142. }
  8143. }
  8144. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8145. goto end;
  8146. }
  8147. //----------------------gunIndex is not 0 ------------------------------------------------//
  8148. //check Transaction active
  8149. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8150. {
  8151. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8152. {
  8153. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8154. {
  8155. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8156. goto end;
  8157. }
  8158. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8159. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8160. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8161. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8162. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8163. {
  8164. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8165. goto end;
  8166. }
  8167. else
  8168. {
  8169. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8170. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8171. goto end;
  8172. }
  8173. }
  8174. }//END FOR CHAdeMO_QUANTITY
  8175. for (int index = 0; index < CCS_QUANTITY; index++)
  8176. {
  8177. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8178. {
  8179. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8180. {
  8181. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8182. goto end;
  8183. }
  8184. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8185. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8186. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8187. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8188. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8189. {
  8190. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8191. goto end;
  8192. }
  8193. else
  8194. {
  8195. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8196. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8197. goto end;
  8198. }
  8199. }
  8200. }//END FOR CCS_QUANTITY
  8201. for (int index = 0; index < GB_QUANTITY; index++)
  8202. {
  8203. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8204. {
  8205. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8206. {
  8207. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8208. goto end;
  8209. }
  8210. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8211. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8212. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8213. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8214. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8215. {
  8216. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8217. goto end;
  8218. }
  8219. else
  8220. {
  8221. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8222. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8223. goto end;
  8224. }
  8225. }
  8226. }// END FOR GB_QUANTITY
  8227. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8228. {
  8229. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8230. {
  8231. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8232. {
  8233. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8234. goto end;
  8235. }
  8236. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8237. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8238. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8239. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8240. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8241. {
  8242. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8243. goto end;
  8244. }
  8245. else
  8246. {
  8247. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8248. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8249. goto end;
  8250. }
  8251. }
  8252. }// END FOR GENERAL_GUN_QUANTITY
  8253. for (int index = 0; index < AC_QUANTITY; index++)
  8254. {
  8255. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8256. {
  8257. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8258. {
  8259. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8260. goto end;
  8261. }
  8262. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8263. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8264. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8265. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8266. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8267. {
  8268. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8269. goto end;
  8270. }
  8271. else
  8272. {
  8273. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8274. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8275. goto end;
  8276. }
  8277. }
  8278. }//END FOR AC_QUANTITY
  8279. }//END FOR AvailabilityTypeStr[Inoperative]
  8280. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8281. {
  8282. //----------------------gunIndex is 0 ------------------------------------------------//
  8283. if(gunIndex == 0)
  8284. {
  8285. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8286. {
  8287. for(int i=0; i < gunTotalNumber; i++)
  8288. {
  8289. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8290. {
  8291. if ((gunType[i] == GUN_TYPE_CHAdeMO )&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO)) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8292. {
  8293. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8294. goto end;
  8295. }
  8296. }//END FOR CHAdeMO_QUANTITY
  8297. for (int index = 0; index < CCS_QUANTITY; index++)
  8298. {
  8299. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT//(((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8300. {
  8301. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8302. goto end;
  8303. }
  8304. }//END FOR CCS_QUANTITY
  8305. for (int index = 0; index < GB_QUANTITY; index++)
  8306. {
  8307. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8308. {
  8309. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8310. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8311. goto end;
  8312. }
  8313. }// END FOR GB_QUANTITY
  8314. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8315. {
  8316. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'O')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8317. {
  8318. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8319. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8320. goto end;
  8321. }
  8322. }// END FOR GENERAL_GUN_QUANTITY
  8323. for (int index = 0; index < AC_QUANTITY; index++)
  8324. {
  8325. if ((gunType[i] == GUN_TYPE_AC) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8326. {
  8327. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8328. goto end;
  8329. }
  8330. }//END FOR CHAdeMO_QUANTITY
  8331. }// END FOR gunTotalNumber
  8332. }
  8333. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8334. {
  8335. for(int i=0; i < gunTotalNumber; i++)
  8336. {
  8337. for (int index = 0; index < AC_QUANTITY; index++)
  8338. {
  8339. if ((gunType[i] == GUN_TYPE_AC) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8340. {
  8341. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8342. goto end;
  8343. }
  8344. }//END FOR CHAdeMO_QUANTITY
  8345. } // END FOR gunTotalNumber
  8346. }
  8347. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8348. goto end;
  8349. }
  8350. //----------------------gunIndex is not 0 ------------------------------------------------//
  8351. //check Transaction active
  8352. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8353. {
  8354. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8355. {
  8356. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8357. goto end;
  8358. }
  8359. }//END FOR CHAdeMO_QUANTITY
  8360. for (int index = 0; index < CCS_QUANTITY; index++)
  8361. {
  8362. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8363. {
  8364. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8365. goto end;
  8366. }
  8367. }//END FOR CCS_QUANTITY
  8368. for (int index = 0; index < GB_QUANTITY; index++)
  8369. {
  8370. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8371. {
  8372. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8373. goto end;
  8374. }
  8375. }// END FOR GB_QUANTITY
  8376. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8377. {
  8378. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8379. {
  8380. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8381. goto end;
  8382. }
  8383. }// END FOR GENERAL_GUN_QUANTITY
  8384. for (int index = 0; index < AC_QUANTITY; index++)
  8385. {
  8386. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8387. {
  8388. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8389. goto end;
  8390. }
  8391. }//END FOR AC_QUANTITY
  8392. }//END FOR AvailabilityTypeStr[Operative]
  8393. end:
  8394. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8395. {
  8396. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8397. }
  8398. else
  8399. {
  8400. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8401. }
  8402. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8403. {
  8404. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8405. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8406. }
  8407. else if(gunIndex == 0)
  8408. {
  8409. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8410. {
  8411. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8412. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8413. }
  8414. }
  8415. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8416. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8417. return result;
  8418. }
  8419. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8420. {
  8421. mtrace();
  8422. int valueInvalid = NO;
  8423. int result = FAIL;
  8424. char keystr[40]={0};
  8425. char valuestr[501]={0}; //value should be limited in 500 bytes
  8426. char comfirmstr[20]={0};
  8427. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8428. json_object *ChangeConfiguration;
  8429. ChangeConfiguration = json_tokener_parse(payload);
  8430. if(!is_error(ChangeConfiguration))
  8431. {
  8432. // Required data
  8433. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8434. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8435. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8436. {
  8437. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8438. }
  8439. else
  8440. {
  8441. valueInvalid = YES;
  8442. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8443. }
  8444. }
  8445. json_object_put(ChangeConfiguration);
  8446. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  8447. {
  8448. DEBUG_ERROR("Payload is null or value is invalid.\n");
  8449. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8450. }
  8451. else
  8452. {
  8453. int status = setKeyValue(keystr, valuestr);
  8454. switch(status)
  8455. {
  8456. case ConfigurationStatus_Accepted:
  8457. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8458. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8459. StoreConfigurationTable();
  8460. break;
  8461. case RebootRequired:
  8462. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8463. StoreConfigurationTable();
  8464. break;
  8465. case NotSupported:
  8466. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8467. break;
  8468. case ConfigurationStatus_Rejected:
  8469. default:
  8470. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8471. break;
  8472. }
  8473. }
  8474. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8475. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8476. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8477. {
  8478. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8479. SetOcppConnStatus(FALSE);
  8480. }
  8481. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8482. {
  8483. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8484. }
  8485. return result;
  8486. }
  8487. int handleClearCacheRequest(char *uuid, char *payload)
  8488. {
  8489. mtrace();
  8490. int result = FAIL;
  8491. char comfirmstr[20];
  8492. char rmFileCmd[100]={0};
  8493. struct stat stats;
  8494. DEBUG_INFO("handleClearCacheRequest...\n");
  8495. stat("/Storage/OCPP", &stats);
  8496. // Check for directory existence
  8497. if (S_ISDIR(stats.st_mode) == 1)
  8498. {}
  8499. else
  8500. {
  8501. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8502. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  8503. system(rmFileCmd);
  8504. }
  8505. if(OCPP_cleanLocalCache())
  8506. {
  8507. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8508. }
  8509. else
  8510. {
  8511. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8512. }
  8513. sendClearCacheConfirmation(uuid, comfirmstr);
  8514. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8515. return result;
  8516. }
  8517. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8518. {
  8519. mtrace();
  8520. int result = FAIL;
  8521. int resultRename;
  8522. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8523. char chargingProfilePurposeStr[26]={0};
  8524. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8525. char tempchargingProfilePurposeStr[26]={0};
  8526. char str[100]={0};
  8527. char fname[200]={0};
  8528. char comfirmstr[20]={0};
  8529. char word[1600]={0};
  8530. int clearflag = FALSE;
  8531. int chargingProfileIdIsNULL = FALSE;
  8532. int connectorIsNULL = FALSE;
  8533. int chargingProfilePurposeIsNULL = FALSE;
  8534. int stackLevelIsNULL = FALSE;
  8535. //int GotoEnd = FALSE;
  8536. FILE *fptr1, *fptr2;
  8537. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  8538. int n_chargingProfile=0;
  8539. int isEmptyFile = FALSE;
  8540. char sLineWord[1600]={0};
  8541. char chargingProfiles[10][100]={0};
  8542. int ChargeProfileCount = 0;
  8543. int ch;
  8544. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8545. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8546. json_object *ClearChargingProfile;
  8547. ClearChargingProfile = json_tokener_parse(payload);
  8548. if(!is_error(ClearChargingProfile))
  8549. {
  8550. // Optional data
  8551. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8552. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8553. else
  8554. chargingProfileIdIsNULL = TRUE;
  8555. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8556. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8557. else
  8558. connectorIsNULL = TRUE;
  8559. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8560. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8561. else
  8562. chargingProfilePurposeIsNULL = TRUE;
  8563. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8564. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8565. else
  8566. stackLevelIsNULL = TRUE;
  8567. }
  8568. json_object_put(ClearChargingProfile);
  8569. if(connectorIsNULL == FALSE)
  8570. {
  8571. switch(connectorIdInt)
  8572. {
  8573. case 0:
  8574. if(chargingProfilePurposeIsNULL == TRUE)
  8575. {
  8576. int l = 0;
  8577. strcpy(fname, ChargePointMaxProfile_JSON);
  8578. if((access(fname,F_OK))!=-1)
  8579. {
  8580. strcpy(chargingProfiles[l], fname);
  8581. l = l + 1;
  8582. }
  8583. strcpy(fname, TxDefaultProfile_0_JSON);
  8584. if((access(fname,F_OK))!=-1)
  8585. {
  8586. strcpy(chargingProfiles[l], fname);
  8587. l = l + 1;
  8588. }
  8589. ChargeProfileCount = l;
  8590. }
  8591. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8592. {
  8593. strcpy(fname, ChargePointMaxProfile_JSON);
  8594. if((access(fname,F_OK))!=-1)
  8595. {
  8596. strcpy(chargingProfiles[0], fname);
  8597. ChargeProfileCount = 1;
  8598. }
  8599. }
  8600. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8601. {
  8602. strcpy(fname, TxDefaultProfile_0_JSON);
  8603. if((access(fname,F_OK))!=-1)
  8604. {
  8605. strcpy(chargingProfiles[0], fname);
  8606. ChargeProfileCount = 1;
  8607. }
  8608. }
  8609. break;
  8610. default:
  8611. if(chargingProfilePurposeIsNULL == TRUE)
  8612. {
  8613. int m = 0;
  8614. memset(fname, 0, ARRAY_SIZE(fname));
  8615. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8616. if((access(fname,F_OK))!=-1)
  8617. {
  8618. strcpy(chargingProfiles[m], fname);
  8619. m = m + 1;
  8620. }
  8621. memset(fname, 0, ARRAY_SIZE(fname));
  8622. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8623. if((access(fname,F_OK))!=-1)
  8624. {
  8625. strcpy(chargingProfiles[m], fname);
  8626. m = m + 1;
  8627. }
  8628. ChargeProfileCount = m;
  8629. }
  8630. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8631. {
  8632. //strcpy(fname, TxDefaultProfile_1_JSON);
  8633. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8634. if((access(fname,F_OK))!=-1)
  8635. {
  8636. strcpy(chargingProfiles[0], fname);
  8637. ChargeProfileCount = 1;
  8638. }
  8639. }
  8640. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8641. {
  8642. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8643. if((access(fname,F_OK))!=-1)
  8644. {
  8645. strcpy(chargingProfiles[0], fname);
  8646. ChargeProfileCount = 1;
  8647. }
  8648. //strcpy(fname, TxProfile_1_JSON);
  8649. }
  8650. //strcpy(fname, ChargePointMaxProfile_JSON );
  8651. break;
  8652. }
  8653. }
  8654. else // Check all Charging Profiles
  8655. {
  8656. int i = 0;
  8657. char fnametemp[200]={0};
  8658. ChargeProfileCount = 0;
  8659. //Check ChargePointMaxProfile.json exit
  8660. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8661. {
  8662. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  8663. i = i + 1;
  8664. }
  8665. //Check TxDefaultProfile_0.json exit
  8666. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8667. {
  8668. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  8669. i = i + 1;
  8670. }
  8671. //Check TxDefaultProfile_%d.json
  8672. for(int j=1; j <= gunTotalNumber; j++)
  8673. {
  8674. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8675. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8676. if((access(fnametemp,F_OK))!=-1)
  8677. {
  8678. strcpy(chargingProfiles[i], fnametemp);
  8679. i = i + 1;
  8680. }
  8681. }
  8682. //Check TxProfile_%d.json
  8683. for(int j=1; j <= gunTotalNumber; j++)
  8684. {
  8685. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8686. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8687. if((access(fnametemp,F_OK))!=-1)
  8688. {
  8689. strcpy(chargingProfiles[i], fnametemp);
  8690. i = i + 1;
  8691. }
  8692. }
  8693. ChargeProfileCount = i;
  8694. }// End connectorIsNULL is TRUE
  8695. if(ChargeProfileCount == 0)
  8696. {
  8697. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8698. goto end;
  8699. }
  8700. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8701. {
  8702. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8703. goto end;
  8704. }
  8705. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8706. {
  8707. memset(str, 0, ARRAY_SIZE(str));
  8708. // clear temp file
  8709. sprintf(str,"rm -f %s",temp);
  8710. system(str);
  8711. for(int k=0; k < ChargeProfileCount; k++)
  8712. {
  8713. memset(str, 0, ARRAY_SIZE(str));
  8714. //clear file in C
  8715. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8716. system(str);
  8717. }
  8718. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8719. goto end;
  8720. }
  8721. else if(connectorIsNULL == TRUE)
  8722. {
  8723. for(int k=0; k < ChargeProfileCount; k++)
  8724. {
  8725. fptr1 = fopen(chargingProfiles[k], "r");
  8726. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  8727. //Check Charging Profile Count
  8728. while(fscanf(fptr1, "%s", word) != EOF)
  8729. {
  8730. //DEBUG_INFO("word=%s\n",word);
  8731. if(strstr(word, "chargingProfileId")!= NULL)
  8732. {
  8733. //DEBUG_INFO("test chargingProfileId \n");
  8734. n_chargingProfile = n_chargingProfile + 1;
  8735. //DEBUG_INFO("chargingProfileId Found\n");
  8736. }
  8737. }
  8738. rewind(fptr1);
  8739. //search Charging Profile Element
  8740. //int i= 0;
  8741. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8742. {
  8743. json_object *tmpProfilee;
  8744. tmpProfilee = json_tokener_parse(sLineWord);
  8745. if(!is_error(tmpProfilee))
  8746. {
  8747. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8748. {
  8749. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8750. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8751. }
  8752. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8753. {
  8754. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8755. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8756. }
  8757. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8758. {
  8759. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8760. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8761. }
  8762. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8763. {
  8764. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8765. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8766. }
  8767. }
  8768. json_object_put(tmpProfilee);
  8769. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8770. {
  8771. //------- not write to fptr2-------//
  8772. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8773. //clearflag = TRUE;
  8774. }
  8775. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8776. {
  8777. //------- not write to fptr2-------//
  8778. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8779. }
  8780. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8781. {
  8782. //------- not write to fptr2-------//
  8783. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8784. }
  8785. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8786. {
  8787. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8788. }
  8789. else
  8790. {
  8791. fprintf(fptr2, sLineWord);//writing data into file
  8792. }
  8793. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8794. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8795. if(clearflag == TRUE)
  8796. {
  8797. fclose(fptr1);
  8798. fclose(fptr2);
  8799. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8800. system(str);
  8801. // clear temp file
  8802. sprintf(str,"rm -f %s",temp);
  8803. system(str);
  8804. }
  8805. else
  8806. {
  8807. fclose(fptr1);
  8808. fclose(fptr2);
  8809. memset(str, 0, ARRAY_SIZE(str));
  8810. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8811. system(str);
  8812. resultRename = rename(temp, chargingProfiles[k]);
  8813. if(resultRename == 0)
  8814. {
  8815. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8816. }
  8817. else
  8818. {
  8819. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8820. }
  8821. if(comfirmstr[0]== 0)
  8822. {
  8823. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8824. }
  8825. //Check chargingProfile is empty file
  8826. /*------ Read the file ----------------*/
  8827. fptr1=fopen(chargingProfiles[k],"r");
  8828. ch=fgetc(fptr1);
  8829. rewind(fptr1);
  8830. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8831. if(ch!=EOF)
  8832. {
  8833. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8834. {
  8835. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8836. if(sLineWord[0]=='\0')
  8837. {
  8838. isEmptyFile = TRUE;
  8839. break;
  8840. }
  8841. else
  8842. {
  8843. isEmptyFile = FALSE;
  8844. break;
  8845. }
  8846. }
  8847. }
  8848. else
  8849. isEmptyFile = TRUE;
  8850. fclose(fptr1);
  8851. if(isEmptyFile == TRUE)
  8852. {
  8853. memset(str, 0, ARRAY_SIZE(str));
  8854. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8855. system(str);
  8856. }
  8857. }
  8858. }// End of while(int k=0; k < ChargePointCount; k++)
  8859. }
  8860. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8861. {
  8862. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8863. for(int k=0; k < ChargeProfileCount; k++)
  8864. {
  8865. fptr1 = fopen(chargingProfiles[k], "r");
  8866. fptr2 = fopen(temp, "w+");
  8867. //Check Charging Profile Count
  8868. while(fscanf(fptr1, "%s", word) != EOF)
  8869. {
  8870. //DEBUG_INFO("word=%s\n",word);
  8871. if(strstr(word, "chargingProfileId")!= NULL)
  8872. {
  8873. n_chargingProfile = n_chargingProfile + 1;
  8874. }
  8875. }
  8876. rewind(fptr1);
  8877. //search Charging Profile Element
  8878. //int i= 0;
  8879. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8880. {
  8881. json_object *tmpProfilee;
  8882. tmpProfilee = json_tokener_parse(sLineWord);
  8883. if(!is_error(tmpProfilee))
  8884. {
  8885. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8886. {
  8887. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8888. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8889. }
  8890. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8891. {
  8892. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8893. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8894. }
  8895. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8896. {
  8897. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8898. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8899. }
  8900. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8901. {
  8902. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8903. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8904. }
  8905. }
  8906. json_object_put(tmpProfilee);
  8907. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8908. {
  8909. //------- not write to fptr2-------//
  8910. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8911. //clearflag = TRUE;
  8912. }
  8913. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8914. {
  8915. //------- not write to fptr2-------//
  8916. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8917. }
  8918. else if(stackLevelIsNULL == TRUE)
  8919. {
  8920. //Clear Whole File
  8921. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8922. clearflag = TRUE;
  8923. break;
  8924. }
  8925. else
  8926. {
  8927. fprintf(fptr2, sLineWord);//writing data into file
  8928. }
  8929. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8930. }
  8931. if(clearflag == TRUE)
  8932. {
  8933. fclose(fptr1);
  8934. fclose(fptr2);
  8935. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8936. system(str);
  8937. // clear temp file
  8938. sprintf(str,"rm -f %s",temp);
  8939. system(str);
  8940. }
  8941. else
  8942. {
  8943. fclose(fptr1);
  8944. fclose(fptr2);
  8945. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8946. system(str);
  8947. resultRename = rename(temp, chargingProfiles[k]);
  8948. if(resultRename == 0)
  8949. {
  8950. DEBUG_INFO("File ChargingProfile renamed successfully");
  8951. }
  8952. else
  8953. {
  8954. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8955. }
  8956. if(comfirmstr[0]== 0)
  8957. {
  8958. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8959. }
  8960. //Check chargingProfile is empty file
  8961. /*------ Read the file ----------------*/
  8962. fptr1=fopen(chargingProfiles[k],"r");
  8963. ch=fgetc(fptr1);
  8964. rewind(fptr1);
  8965. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8966. if(ch!=EOF)
  8967. {
  8968. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8969. {
  8970. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8971. if(sLineWord[0]=='\0')
  8972. {
  8973. isEmptyFile = TRUE;
  8974. break;
  8975. }
  8976. else
  8977. {
  8978. isEmptyFile = FALSE;
  8979. break;
  8980. }
  8981. }
  8982. }
  8983. else
  8984. isEmptyFile = TRUE;
  8985. fclose(fptr1);
  8986. if(isEmptyFile == TRUE)
  8987. {
  8988. memset(str, 0, ARRAY_SIZE(str));
  8989. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8990. system(str);
  8991. }
  8992. /*------- End of reading ---------------*/
  8993. }
  8994. } // while(int k=0; k < ChargeProfileCount; k++)
  8995. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8996. end:
  8997. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8998. {
  8999. if(connectorIdInt == 0)
  9000. {
  9001. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9002. {
  9003. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9004. }
  9005. }
  9006. else
  9007. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9008. }
  9009. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9010. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9011. return result;
  9012. }
  9013. void createFirmwareVersionByDataTransfer(void)
  9014. {
  9015. json_object *FirmwareDataTransfer = json_object_new_object();
  9016. // AC & DC model
  9017. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9018. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9019. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9020. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9021. // DC model
  9022. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9023. {
  9024. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9025. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9026. (gunType[3] != GUN_TYPE_UNKNOWN))
  9027. {
  9028. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9029. }
  9030. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9031. {
  9032. // DS DM DW
  9033. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9034. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9035. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9036. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9037. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9038. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9039. }
  9040. else
  9041. {
  9042. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9043. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9044. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9045. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9046. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9047. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9048. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9049. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9050. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9051. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9052. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9053. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9054. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9055. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9056. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9057. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9058. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9059. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9060. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9061. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9062. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9063. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9064. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9065. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9066. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9067. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9068. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9069. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9070. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9071. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9072. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9073. }
  9074. }
  9075. // 4G model
  9076. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9077. {
  9078. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9079. }
  9080. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9081. json_object_put(FirmwareDataTransfer);
  9082. }
  9083. int handleDataTransferRequest(char *uuid, char *payload)
  9084. {
  9085. mtrace();
  9086. json_object *response = json_object_new_object();
  9087. int result = FAIL;
  9088. char tempvendorId[255]={0};
  9089. char tempmessageId[50]={0};
  9090. char tempdata[512]={0};
  9091. char message[2048]={0};
  9092. DEBUG_INFO("handleDataTransferRequest...\n");
  9093. if((uuid != NULL) && (payload != NULL))
  9094. {
  9095. json_object *DataTransfer;
  9096. DataTransfer = json_tokener_parse(payload);
  9097. if(!is_error(DataTransfer))
  9098. {
  9099. // Required data
  9100. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9101. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9102. // Optional data
  9103. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9104. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9105. if(json_object_object_get(DataTransfer, "data") != NULL)
  9106. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9107. result = PASS;
  9108. }
  9109. json_object_put(DataTransfer);
  9110. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9111. {
  9112. // Send all moudle firmware version on EVSE
  9113. createFirmwareVersionByDataTransfer();
  9114. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9115. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9116. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9117. json_object_put(response);
  9118. }
  9119. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9120. {
  9121. system("/usr/bin/run_tmate_restart.sh &");
  9122. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9123. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9124. json_object_put(response);
  9125. }
  9126. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9127. {
  9128. json_object *data;
  9129. data = json_tokener_parse(tempdata);
  9130. if(!is_error(data))
  9131. {
  9132. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) <= gunTotalNumber))
  9133. {
  9134. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9135. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9136. if(json_object_object_get(data, "SOC") != NULL)
  9137. {
  9138. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9139. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9140. }
  9141. if(json_object_object_get(data, "Energy") != NULL)
  9142. {
  9143. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9144. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9145. }
  9146. if(json_object_object_get(data, "Duration") != NULL)
  9147. {
  9148. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9149. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9150. }
  9151. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9152. }
  9153. else
  9154. {
  9155. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9156. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9157. }
  9158. }
  9159. else
  9160. {
  9161. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9162. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9163. }
  9164. json_object_put(data);
  9165. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9166. json_object_put(response);
  9167. }
  9168. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9169. {
  9170. json_object *data;
  9171. data = json_tokener_parse(tempdata);
  9172. if(!is_error(data))
  9173. {
  9174. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9175. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9176. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9177. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9178. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9179. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9180. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9181. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9182. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9183. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9184. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9185. }
  9186. else
  9187. {
  9188. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9189. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9190. }
  9191. json_object_put(data);
  9192. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9193. json_object_put(response);
  9194. }
  9195. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9196. {
  9197. json_object *data;
  9198. data = json_tokener_parse(tempdata);
  9199. if(!is_error(data))
  9200. {
  9201. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9202. if(json_object_object_get(data, "idToken") != NULL)
  9203. {
  9204. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9205. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9206. }
  9207. if(json_object_object_get(data, "price") != NULL)
  9208. {
  9209. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9210. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9211. }
  9212. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9213. }
  9214. else
  9215. {
  9216. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9217. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9218. }
  9219. json_object_put(data);
  9220. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9221. json_object_put(response);
  9222. }
  9223. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9224. {
  9225. json_object *data;
  9226. data = json_tokener_parse(tempdata);
  9227. if(!is_error(data))
  9228. {
  9229. if(json_object_object_get(data, "txId") != NULL)
  9230. {
  9231. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9232. for(int idx = 0;idx<gunTotalNumber;idx++)
  9233. {
  9234. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9235. {
  9236. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9237. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9238. if(json_object_object_get(data, "description") != NULL)
  9239. {
  9240. // California pricing V1.0
  9241. DEBUG_INFO("California pricing V1.0\n");
  9242. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9243. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9244. }
  9245. else
  9246. {
  9247. // California pricing V1.1
  9248. DEBUG_INFO("California pricing V1.1\n");
  9249. if(json_object_object_get(data, "timestamp") != NULL)
  9250. {
  9251. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9252. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9253. }
  9254. if(json_object_object_get(data, "meterValue") != NULL)
  9255. {
  9256. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9257. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9258. }
  9259. if(json_object_object_get(data, "cost") != NULL)
  9260. {
  9261. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9262. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9263. }
  9264. if(json_object_object_get(data, "state") != NULL)
  9265. {
  9266. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9267. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9268. }
  9269. if(json_object_object_get(data, "chargingPrice") != NULL)
  9270. {
  9271. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9272. {
  9273. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9274. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9275. }
  9276. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9277. {
  9278. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9279. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9280. }
  9281. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9282. {
  9283. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9284. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9285. }
  9286. }
  9287. if(json_object_object_get(data, "idlePrice") != NULL)
  9288. {
  9289. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9290. {
  9291. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9292. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9293. }
  9294. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9295. {
  9296. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9297. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9298. }
  9299. }
  9300. if(json_object_object_get(data, "nextPeriod") != NULL)
  9301. {
  9302. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9303. {
  9304. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9305. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9306. }
  9307. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9308. {
  9309. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9310. {
  9311. DEBUG_INFO("nextPeriod-chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice")));
  9312. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice"));
  9313. }
  9314. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9315. {
  9316. DEBUG_INFO("nextPeriod-chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice")));
  9317. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice"));
  9318. }
  9319. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9320. {
  9321. DEBUG_INFO("nextPeriod-chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee")));
  9322. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee"));
  9323. }
  9324. }
  9325. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9326. {
  9327. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9328. {
  9329. DEBUG_INFO("nextPeriod-idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes")));
  9330. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes"));
  9331. }
  9332. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9333. {
  9334. DEBUG_INFO("nextPeriod-idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice")));
  9335. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice"));
  9336. }
  9337. }
  9338. }
  9339. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9340. {
  9341. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9342. {
  9343. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9344. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9345. }
  9346. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9347. {
  9348. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9349. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9350. }
  9351. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9352. {
  9353. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9354. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9355. }
  9356. }
  9357. }
  9358. }
  9359. }
  9360. }
  9361. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9362. }
  9363. else
  9364. {
  9365. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9366. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9367. }
  9368. json_object_put(data);
  9369. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9370. json_object_put(response);
  9371. }
  9372. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9373. {
  9374. json_object *data;
  9375. data = json_tokener_parse(tempdata);
  9376. if(!is_error(data))
  9377. {
  9378. if(json_object_object_get(data, "txId") != NULL)
  9379. {
  9380. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9381. for(int idx = 0;idx<gunTotalNumber;idx++)
  9382. {
  9383. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9384. {
  9385. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9386. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9387. if(json_object_object_get(data, "description") != NULL)
  9388. {
  9389. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9390. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9391. }
  9392. }
  9393. }
  9394. }
  9395. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9396. }
  9397. else
  9398. {
  9399. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9400. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9401. }
  9402. json_object_put(data);
  9403. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9404. json_object_put(response);
  9405. }
  9406. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9407. {
  9408. json_object *data;
  9409. data = json_tokener_parse(tempdata);
  9410. if(!is_error(data))
  9411. {
  9412. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9413. if(json_object_object_get(data, "Content_Type") != NULL)
  9414. {
  9415. if((0 <= json_object_get_int(json_object_object_get(data, "Content_Type"))) && (json_object_get_int(json_object_object_get(data, "Content_Type")) <= 1))
  9416. {
  9417. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9418. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9419. {
  9420. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9421. }
  9422. }
  9423. else
  9424. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9425. }
  9426. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9427. }
  9428. else
  9429. {
  9430. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9431. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9432. }
  9433. json_object_put(data);
  9434. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9435. json_object_put(response);
  9436. }
  9437. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  9438. {
  9439. json_object *data;
  9440. data = json_tokener_parse(tempdata);
  9441. if(!is_error(data))
  9442. {
  9443. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9444. if(json_object_object_get(data, "Page_Index") != NULL)
  9445. {
  9446. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9447. }
  9448. if(json_object_object_get(data, "Duration") != NULL)
  9449. {
  9450. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9451. }
  9452. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  9453. }
  9454. else
  9455. {
  9456. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9457. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9458. }
  9459. json_object_put(data);
  9460. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9461. json_object_put(response);
  9462. }
  9463. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9464. {
  9465. json_object *data;
  9466. data = json_tokener_parse(tempdata);
  9467. if(!is_error(data))
  9468. {
  9469. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9470. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9471. {
  9472. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9473. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9474. else
  9475. {
  9476. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9477. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9478. }
  9479. }
  9480. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9481. {
  9482. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9483. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9484. else
  9485. {
  9486. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9487. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9488. }
  9489. }
  9490. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9491. {
  9492. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9493. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9494. else
  9495. {
  9496. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9497. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9498. }
  9499. }
  9500. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9501. {
  9502. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9503. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9504. else
  9505. {
  9506. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9507. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9508. }
  9509. }
  9510. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9511. {
  9512. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9513. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9514. else
  9515. {
  9516. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9517. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9518. }
  9519. }
  9520. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9521. {
  9522. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9523. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9524. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9525. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9526. else
  9527. {
  9528. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9529. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9530. }
  9531. }
  9532. if(json_object_object_get(data, "isAuthentication") != NULL)
  9533. {
  9534. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9535. {
  9536. case 0:
  9537. case 1:
  9538. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9539. break;
  9540. default:
  9541. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9542. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9543. break;
  9544. }
  9545. }
  9546. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9547. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9548. }
  9549. else
  9550. {
  9551. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9552. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9553. }
  9554. json_object_put(data);
  9555. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9556. json_object_put(response);
  9557. }
  9558. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  9559. {
  9560. json_object *data;
  9561. data = json_tokener_parse(tempdata);
  9562. if(!is_error(data))
  9563. {
  9564. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9565. {
  9566. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  9567. {
  9568. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9569. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9570. }
  9571. else
  9572. {
  9573. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9574. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  9575. }
  9576. }
  9577. else
  9578. {
  9579. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9580. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9581. }
  9582. }
  9583. else
  9584. {
  9585. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9586. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9587. }
  9588. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9589. json_object_put(response);
  9590. }
  9591. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9592. {
  9593. json_object *data;
  9594. data = json_tokener_parse(tempdata);
  9595. if(!is_error(data))
  9596. {
  9597. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9598. if(json_object_object_get(data, "stationName") != NULL)
  9599. {
  9600. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9601. }
  9602. else
  9603. {
  9604. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9605. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9606. }
  9607. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9608. {
  9609. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  9610. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9611. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  9612. }
  9613. }
  9614. else
  9615. {
  9616. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9617. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9618. }
  9619. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9620. json_object_put(response);
  9621. }
  9622. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9623. {
  9624. json_object *data;
  9625. data = json_tokener_parse(tempdata);
  9626. if(!is_error(data))
  9627. {
  9628. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9629. if(json_object_object_get(data, "weatherId") != NULL)
  9630. {
  9631. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9632. }
  9633. else
  9634. {
  9635. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9636. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9637. }
  9638. if(json_object_object_get(data, "Temperature") != NULL)
  9639. {
  9640. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9641. }
  9642. else
  9643. {
  9644. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9645. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9646. }
  9647. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9648. {
  9649. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  9650. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9651. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  9652. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  9653. );
  9654. }
  9655. }
  9656. else
  9657. {
  9658. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9659. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9660. }
  9661. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9662. json_object_put(response);
  9663. }
  9664. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9665. {
  9666. json_object *data;
  9667. data = json_tokener_parse(tempdata);
  9668. if(!is_error(data))
  9669. {
  9670. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9671. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9672. {
  9673. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9674. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9675. }
  9676. else
  9677. {
  9678. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9679. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9680. }
  9681. }
  9682. else
  9683. {
  9684. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9685. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9686. }
  9687. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9688. json_object_put(response);
  9689. }
  9690. else
  9691. {
  9692. // Can not find valid message id
  9693. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9694. }
  9695. }
  9696. else
  9697. {
  9698. // Payload is null
  9699. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9700. }
  9701. LWS_Send(message);
  9702. return result;
  9703. }
  9704. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9705. {
  9706. mtrace();
  9707. int result = FAIL;
  9708. int connectorIdInt, durationInt;
  9709. char chargingRateUnitStr[4]={0};
  9710. char comfirmstr[20];
  9711. int confirmPeriods = 0;
  9712. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9713. json_object *GetCompositeSchedule;
  9714. GetCompositeSchedule = json_tokener_parse(payload);
  9715. if(!is_error(GetCompositeSchedule))
  9716. {
  9717. // Required data
  9718. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9719. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9720. else
  9721. connectorIdInt = -1;
  9722. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9723. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9724. else
  9725. durationInt = 86400;
  9726. // Optional data
  9727. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9728. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9729. }
  9730. json_object_put(GetCompositeSchedule);
  9731. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9732. if((connectorIdInt == 0) ||
  9733. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9734. {
  9735. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9736. struct StructChargingProfile tmpProfile[1];
  9737. if(strstr(chargingRateUnitStr, "W") != NULL)
  9738. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9739. else
  9740. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9741. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9742. {
  9743. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9744. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9745. }
  9746. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9747. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9748. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9749. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9750. {
  9751. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9752. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9753. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9754. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9755. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9756. {
  9757. confirmPeriods = idx;
  9758. break;
  9759. }
  9760. }
  9761. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9762. {
  9763. confirmPeriods += 1;
  9764. }
  9765. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9766. }
  9767. else
  9768. {
  9769. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9770. }
  9771. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9772. return result;
  9773. }
  9774. int handleGetConfigurationRequest(char *uuid, char *payload)
  9775. {
  9776. mtrace();
  9777. int result = FAIL;
  9778. int MaxKeySupported = 0;
  9779. int n_keys = 0;
  9780. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9781. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9782. json_object *GetConfiguration;
  9783. GetConfiguration = json_tokener_parse(payload);
  9784. if(!is_error(GetConfiguration))
  9785. {
  9786. // Optional data
  9787. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9788. {
  9789. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9790. {
  9791. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9792. n_keys = idx + 1;
  9793. }
  9794. }
  9795. }
  9796. json_object_put(GetConfiguration);
  9797. UnknownKeynum = 0;
  9798. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9799. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9800. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9801. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9802. if(n_keys != 0)
  9803. {
  9804. for(int i=0;i<n_keys;i++)
  9805. {
  9806. getKeyValue(requestKey[i]);
  9807. }
  9808. }
  9809. else
  9810. {
  9811. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9812. getKeyValue("");
  9813. }
  9814. processUnkownKey();
  9815. sendGetConfigurationConfirmation(uuid);
  9816. return result;
  9817. }
  9818. static char fnamePlusPath[100]={0};
  9819. static char fnamePWithNoPath[60]={0};
  9820. void checkUploadLog(void)
  9821. {
  9822. FILE *fp;
  9823. /* Open the command for reading. */
  9824. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9825. if (fp == NULL) {
  9826. DEBUG_WARN("Failed to run command\n" );
  9827. exit(1);
  9828. }
  9829. int ftppathlen = 0;
  9830. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9831. int i = 0;
  9832. /* Read the output a line at a time - output it. */
  9833. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9834. if(i==0)
  9835. {
  9836. ftppathlen = strlen(fnamePlusPath);
  9837. DEBUG_INFO("%s\n", fnamePlusPath);
  9838. fnamePlusPath[ftppathlen]='\0';
  9839. break;
  9840. }
  9841. i= i+1;
  9842. }
  9843. /* close */
  9844. pclose(fp);
  9845. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9846. {
  9847. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9848. {
  9849. fnamePlusPath[k]='\0';
  9850. }
  9851. }
  9852. i=1;
  9853. //char fname[60]={0};
  9854. while(i < ftppathlen)
  9855. {
  9856. int len=ftppathlen-i;
  9857. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9858. {
  9859. DEBUG_INFO("compare '/' all right\n");
  9860. break;
  9861. }
  9862. i=i+1;
  9863. }
  9864. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9865. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9866. fnamePWithNoPath[i+1] = '\0';
  9867. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9868. {
  9869. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9870. {
  9871. fnamePWithNoPath[j]='\0';
  9872. }
  9873. }
  9874. FILE* fp1 = fopen(fnamePlusPath, "r");
  9875. if (fp1)
  9876. {
  9877. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9878. // file exists
  9879. fclose(fp1);
  9880. }
  9881. else
  9882. {
  9883. // file doesn't exist
  9884. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9885. }
  9886. }
  9887. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9888. {
  9889. mtrace();
  9890. int result = FAIL;
  9891. time_t CurrentTime;
  9892. struct tm *tm;
  9893. pthread_t th_Status;
  9894. CurrentTime = time(NULL);
  9895. tm = localtime(&CurrentTime);
  9896. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  9897. 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);
  9898. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9899. if(!interLock.isGetDiagnosticGoing)
  9900. {
  9901. interLock.isGetDiagnosticGoing = 1;
  9902. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9903. sleep(1);
  9904. }
  9905. else
  9906. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9907. return result;
  9908. }
  9909. void* GetDiagnosticsProcess(void* data)
  9910. {
  9911. pthread_detach(pthread_self());
  9912. mtrace();
  9913. int retriesInt=0, retryIntervalInt=0;
  9914. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9915. 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};
  9916. int port=0;
  9917. int isSuccess = FALSE;
  9918. char cmdBuf[2048];
  9919. struct tm *tmNow;
  9920. time_t CurrentTime;
  9921. struct tm tmStart;
  9922. struct tm tmStop;
  9923. CurrentTime = time(NULL);
  9924. tmNow=localtime(&CurrentTime);
  9925. uint16_t targetYear, targetMonth;
  9926. json_object *GetDiagnostics;
  9927. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9928. GetDiagnostics = json_tokener_parse(data);
  9929. if(!is_error(GetDiagnostics))
  9930. {
  9931. // Required data
  9932. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9933. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9934. // Optional data
  9935. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9936. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9937. else
  9938. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9939. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9940. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9941. else
  9942. retryIntervalInt = 30;
  9943. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9944. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9945. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9946. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9947. }
  9948. json_object_put(GetDiagnostics);
  9949. // Pack log to compress file
  9950. 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) &&
  9951. (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))
  9952. {
  9953. // Pack system log
  9954. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9955. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9956. targetYear = tmStart.tm_year;
  9957. targetMonth = tmStart.tm_mon;
  9958. do
  9959. {
  9960. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9961. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9962. if(targetMonth+1>=13)
  9963. {
  9964. targetYear += 1;
  9965. targetMonth = 1;
  9966. }
  9967. else
  9968. {
  9969. targetMonth += 1;
  9970. }
  9971. }while((targetYear < (tmNow->tm_year+1900)) ||
  9972. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9973. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9974. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9975. system(cmdBuf);
  9976. // Pack charging & event log
  9977. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9978. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9979. targetYear = tmStart.tm_year;
  9980. targetMonth = tmStart.tm_mon;
  9981. do
  9982. {
  9983. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9984. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9985. if(targetMonth+1>=13)
  9986. {
  9987. targetYear += 1;
  9988. targetMonth = 1;
  9989. }
  9990. else
  9991. {
  9992. targetMonth += 1;
  9993. }
  9994. }while((targetYear < (tmNow->tm_year+1900)) ||
  9995. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9996. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9997. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9998. system(cmdBuf);
  9999. // Combine log file
  10000. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10001. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10002. }
  10003. else
  10004. {
  10005. system("exec /root/logPackTools 'log' 6");
  10006. }
  10007. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10008. system(cmdBuf);
  10009. checkUploadLog();
  10010. //****************location*******************/
  10011. if(strcmp(locationstr,"")==0)
  10012. {
  10013. DEBUG_INFO("location is <Empty>!\n");
  10014. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10015. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10016. goto end;
  10017. }
  10018. memset(protocol, 0, ARRAY_SIZE(protocol));
  10019. memset(user, 0, ARRAY_SIZE(user) );
  10020. memset(password, 0, ARRAY_SIZE(password));
  10021. memset(host, 0, ARRAY_SIZE(host));
  10022. memset(path, 0, ARRAY_SIZE(path));
  10023. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10024. memset(host1, 0, ARRAY_SIZE(host1));
  10025. memset(path1, 0, ARRAY_SIZE(path1));
  10026. /*location: ftp://user:password@host:port/path*/
  10027. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10028. if((access(fnamePlusPath,F_OK))!=-1)
  10029. {
  10030. DEBUG_INFO("fnamePlusPath exist.\n");
  10031. }
  10032. else
  10033. {
  10034. DEBUG_INFO("fnamePlusPath not exist!\n");
  10035. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10036. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10037. goto end;
  10038. }
  10039. if(strchr(locationstr,'@')==NULL)
  10040. {
  10041. sscanf(locationstr,
  10042. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10043. protocol, host, &port, path);
  10044. strcpy(user,"anonymous");
  10045. strcpy(password,"");
  10046. }
  10047. else
  10048. {
  10049. //DEBUG_INFO("pch=%s\n", pch);
  10050. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10051. protocol, user, password, host, &port, path);
  10052. }
  10053. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10054. {
  10055. DEBUG_INFO("protocol is not ftp/http ! \n");
  10056. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10057. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10058. goto end;
  10059. }
  10060. if(strncmp(locationstr,"http", 4) == 0)
  10061. {
  10062. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10063. sprintf(ftppath,"/%s", path);
  10064. do
  10065. {
  10066. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10067. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10068. sleep(3);
  10069. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10070. if(!isSuccess)
  10071. {
  10072. DEBUG_INFO("Diagnostics fail.\n");
  10073. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10074. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10075. sleep(retryIntervalInt);
  10076. }
  10077. else
  10078. {
  10079. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10080. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10081. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10082. }
  10083. retriesInt--;
  10084. }while((isSuccess == 0)&&(retriesInt >= 0));
  10085. }
  10086. else
  10087. {
  10088. sscanf(host,"%[^/]%s",host1, path1);
  10089. if(strlen(path) > 0)
  10090. sprintf(ftppath,"/%s", path);
  10091. else
  10092. sprintf(ftppath,"/%s", path1);
  10093. int ftppathlen=strlen(ftppath);
  10094. int i=1;
  10095. char filenametemp[50];
  10096. while(i < ftppathlen)
  10097. {
  10098. int len=ftppathlen-i;
  10099. if(ftppath[len]== 47) // '/' ascll code: 47
  10100. {
  10101. DEBUG_INFO("find '/' all right\n");
  10102. break;
  10103. }
  10104. i=i+1;
  10105. }
  10106. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10107. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10108. filenametemp[i+1] = 0;
  10109. if(port == 0)
  10110. port = 21;
  10111. do
  10112. {
  10113. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10114. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10115. sleep(3);
  10116. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10117. if(!isSuccess)
  10118. {
  10119. DEBUG_INFO("Diagnostics fail.\n");
  10120. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10121. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10122. sleep(retryIntervalInt);
  10123. }
  10124. else
  10125. {
  10126. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10127. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10128. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10129. }
  10130. retriesInt--;
  10131. }while((!isSuccess)&&(retriesInt >= 0));
  10132. }
  10133. end:
  10134. system("rm -f /mnt/*");
  10135. sleep(5);
  10136. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10137. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10138. interLock.isGetDiagnosticGoing = 0;
  10139. pthread_exit(NULL);
  10140. }
  10141. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10142. {
  10143. mtrace();
  10144. int result = FAIL;
  10145. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10146. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10147. {
  10148. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10149. locallistVersion = -1;
  10150. }
  10151. else
  10152. {
  10153. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10154. OCPP_getListVerion();
  10155. }
  10156. //from db.OCPP_getListVerion
  10157. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10158. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  10159. sendGetLocalListVersionConfirmation(uuid,"");
  10160. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  10161. return result;
  10162. }
  10163. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10164. {
  10165. mtrace();
  10166. int result = FAIL;
  10167. int connectorIdInt=-1;
  10168. int tempIndex = 0;
  10169. int connectorIdIsNULL, chargingProfileIsNULL;
  10170. char comfirmstr[20]={0};
  10171. char cmdBuf[512];
  10172. json_object *RemoteStartTransaction;
  10173. FILE *fp;
  10174. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10175. if(server_pending == TRUE)
  10176. {
  10177. return 0;
  10178. }
  10179. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10180. RemoteStartTransaction = json_tokener_parse(payload);
  10181. if(!is_error(RemoteStartTransaction))
  10182. {
  10183. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10184. {
  10185. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10186. }
  10187. else
  10188. {
  10189. connectorIdIsNULL = TRUE;
  10190. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10191. {
  10192. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10193. {
  10194. connectorIdIsNULL = FALSE;
  10195. connectorIdInt = (gun_index+1);
  10196. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10197. break;
  10198. }
  10199. }
  10200. }
  10201. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10202. {
  10203. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10204. // Required data
  10205. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10206. // Optional data
  10207. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10208. {
  10209. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10210. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10211. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10212. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10213. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10214. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10215. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10216. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10217. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10218. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10219. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10220. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10221. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10222. {
  10223. 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")));
  10224. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10225. 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"));
  10226. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10227. 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"));
  10228. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10229. 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")));
  10230. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10231. {
  10232. 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++)
  10233. {
  10234. 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"));
  10235. 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"));
  10236. 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)
  10237. 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"));
  10238. }
  10239. }
  10240. }
  10241. }
  10242. else
  10243. {
  10244. chargingProfileIsNULL = TRUE;
  10245. }
  10246. }
  10247. }
  10248. else
  10249. {
  10250. connectorIdIsNULL = TRUE;
  10251. }
  10252. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10253. {
  10254. DEBUG_WARN("Connector id is NULL\n.");
  10255. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10256. goto end;
  10257. }
  10258. /*
  10259. enum _SYSTEM_STATUS
  10260. {
  10261. S_BOOTING = 0,
  10262. S_IDLE, = 1
  10263. S_AUTHORIZING, = 2
  10264. S_REASSIGN_CHECK, = 3
  10265. S_REASSIGN, = 4
  10266. S_PRECHARGE, = 5
  10267. S_PREPARING_FOR_EV, = 6
  10268. S_PREPARING_FOR_EVSE, = 7
  10269. S_CHARGING, = 8
  10270. S_TERMINATING, = 9
  10271. S_COMPLETE, = 10
  10272. S_ALARM, = 11
  10273. S_FAULT = 12
  10274. }
  10275. */
  10276. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10277. {
  10278. //check Transaction active
  10279. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10280. {
  10281. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10282. {
  10283. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10284. }
  10285. else
  10286. {
  10287. tempIndex = connectorIdInt -1;
  10288. }
  10289. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10290. {
  10291. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10292. {
  10293. 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))
  10294. {
  10295. //Reserved
  10296. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10297. }
  10298. 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))
  10299. {
  10300. //Reserved
  10301. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10302. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10303. goto end;
  10304. }
  10305. else
  10306. {
  10307. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10308. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10309. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10310. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10311. {
  10312. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10313. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10314. goto end;
  10315. }
  10316. }//END FOR ELSE
  10317. }
  10318. }// END FOR CHAdeMO_QUANTITY
  10319. }
  10320. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10321. {
  10322. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10323. {
  10324. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10325. }
  10326. else
  10327. {
  10328. tempIndex = connectorIdInt -1;
  10329. }
  10330. for (int index = 0; index < CCS_QUANTITY; index++)
  10331. {
  10332. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10333. {
  10334. 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))
  10335. {
  10336. //Reserved
  10337. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10338. }
  10339. 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))
  10340. {
  10341. //Reserved
  10342. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10343. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10344. goto end;
  10345. }
  10346. else
  10347. {
  10348. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10349. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10350. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10351. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10352. {
  10353. DEBUG_WARN("CCS connector not allow start\n.");
  10354. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10355. goto end;
  10356. }
  10357. }// END FOR ELSE
  10358. }
  10359. }// END FOR CCS_QUANTITY
  10360. }
  10361. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10362. {
  10363. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10364. {
  10365. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10366. }
  10367. else
  10368. {
  10369. tempIndex = connectorIdInt -1;
  10370. }
  10371. for (int index = 0; index < GB_QUANTITY; index++)
  10372. {
  10373. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10374. {
  10375. 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))
  10376. {
  10377. //Reserved
  10378. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10379. }
  10380. 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))
  10381. {
  10382. //Reserved
  10383. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10384. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10385. goto end;
  10386. }
  10387. else
  10388. {
  10389. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10390. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10391. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10392. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10393. {
  10394. DEBUG_WARN("GB connector not allow start\n.");
  10395. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10396. goto end;
  10397. }
  10398. }// END FOR ELSE
  10399. }
  10400. } // END FOR GB_QUANTITY
  10401. }
  10402. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10403. {
  10404. tempIndex = connectorIdInt -1;
  10405. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10406. {
  10407. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10408. {
  10409. 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))
  10410. {
  10411. //Reserved
  10412. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10413. }
  10414. 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))
  10415. {
  10416. //Reserved
  10417. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10418. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10419. goto end;
  10420. }
  10421. else
  10422. {
  10423. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10424. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10425. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10426. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10427. {
  10428. DEBUG_WARN("GB connector not allow start\n.");
  10429. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10430. goto end;
  10431. }
  10432. }// END FOR ELSE
  10433. }
  10434. } // END FOR GB_QUANTITY
  10435. }
  10436. else
  10437. {
  10438. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10439. {
  10440. tempIndex = 2;
  10441. }
  10442. else
  10443. {
  10444. tempIndex = connectorIdInt -1;
  10445. }
  10446. for (int index = 0; index < AC_QUANTITY; index++)
  10447. {
  10448. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10449. {
  10450. 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))
  10451. {
  10452. //Reserved
  10453. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10454. }
  10455. 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))
  10456. {
  10457. //Reserved
  10458. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10459. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10460. goto end;
  10461. }
  10462. else
  10463. {
  10464. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10465. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10466. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10467. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10468. {
  10469. DEBUG_WARN("AC connector not allow start\n.");
  10470. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10471. goto end;
  10472. }
  10473. }//END FOR ELSE
  10474. }
  10475. }// END FOR AC_QUANTITY
  10476. }
  10477. if(chargingProfileIsNULL == FALSE)
  10478. {
  10479. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10480. {
  10481. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10482. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10483. //memset idTag
  10484. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10485. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10486. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10487. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10488. // Save profile to file
  10489. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10490. system(cmdBuf);
  10491. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10492. fp = fopen(cmdBuf, "w");
  10493. 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));
  10494. fclose(fp);
  10495. }
  10496. else
  10497. {
  10498. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10499. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10500. }
  10501. }
  10502. else
  10503. {
  10504. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10505. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10506. //memset idTag
  10507. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10508. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10509. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10510. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10511. }
  10512. }
  10513. else
  10514. {
  10515. DEBUG_WARN("Connector id over\n.");
  10516. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10517. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10518. }
  10519. end:
  10520. json_object_put(RemoteStartTransaction);
  10521. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10522. {
  10523. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10524. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10525. }
  10526. //OCPP send RemoteStartConfirmation by first.
  10527. sendRemoteStartConfirmation(uuid, comfirmstr);
  10528. return result;
  10529. }
  10530. int handleRemoteStartRequest(char *uuid, char *payload)
  10531. {
  10532. mtrace();
  10533. int result = PASS;
  10534. int connectorIdInt=-1;
  10535. int tempIndex = 0;
  10536. char comfirmstr[20]={0};
  10537. char cmdBuf[512];
  10538. json_object *RemoteStartTransaction;
  10539. FILE *fp;
  10540. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10541. if(server_pending == TRUE)
  10542. {
  10543. result = FAIL;
  10544. }
  10545. RemoteStartTransaction = json_tokener_parse(payload);
  10546. if(!is_error(RemoteStartTransaction))
  10547. {
  10548. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10549. {
  10550. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10551. }
  10552. else
  10553. {
  10554. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10555. {
  10556. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10557. {
  10558. connectorIdInt = (gun_index+1);
  10559. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10560. break;
  10561. }
  10562. }
  10563. }
  10564. if(connectorIdInt == 0)
  10565. {
  10566. DEBUG_WARN("Connector id shall not equal 0.\n");
  10567. result = FAIL;
  10568. }
  10569. else if(connectorIdInt == -1)
  10570. {
  10571. DEBUG_INFO("Connector id does not specific.\n");
  10572. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10573. {
  10574. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10575. // Required data
  10576. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10577. // Optional data
  10578. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10579. {
  10580. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10581. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10582. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10583. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10584. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10585. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10586. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10587. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10588. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10589. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10590. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10591. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10592. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10593. {
  10594. 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")));
  10595. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10596. 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"));
  10597. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10598. 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"));
  10599. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10600. 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")));
  10601. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10602. {
  10603. 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++)
  10604. {
  10605. 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"));
  10606. 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"));
  10607. 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)
  10608. 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"));
  10609. }
  10610. }
  10611. }
  10612. }
  10613. else
  10614. {
  10615. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10616. }
  10617. }
  10618. }
  10619. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10620. {
  10621. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10622. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10623. // Required data
  10624. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10625. // Optional data
  10626. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10627. {
  10628. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10629. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10630. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10631. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10632. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10633. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10634. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10635. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10636. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10637. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10638. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10639. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10640. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10641. {
  10642. 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")));
  10643. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10644. 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"));
  10645. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10646. 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"));
  10647. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10648. 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")));
  10649. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10650. {
  10651. 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++)
  10652. {
  10653. 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"));
  10654. 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"));
  10655. 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)
  10656. 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"));
  10657. }
  10658. }
  10659. }
  10660. }
  10661. else
  10662. {
  10663. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10664. }
  10665. }
  10666. else
  10667. {
  10668. DEBUG_WARN("Connector id is over maximun value.\n");
  10669. result = FAIL;
  10670. }
  10671. }
  10672. if(result == PASS)
  10673. {
  10674. if(connectorIdInt > 0)
  10675. {
  10676. //check Transaction active
  10677. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10678. {
  10679. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10680. {
  10681. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10682. }
  10683. else
  10684. {
  10685. tempIndex = connectorIdInt -1;
  10686. }
  10687. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10688. {
  10689. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10690. {
  10691. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10692. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10693. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10694. {
  10695. //Reserved
  10696. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10697. }
  10698. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10699. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10700. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10701. {
  10702. //Reserved
  10703. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10704. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10705. goto end;
  10706. }
  10707. else
  10708. {
  10709. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10710. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10711. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10712. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10713. {
  10714. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10715. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10716. goto end;
  10717. }
  10718. }//END FOR ELSE
  10719. }
  10720. }// END FOR CHAdeMO_QUANTITY
  10721. }
  10722. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10723. {
  10724. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10725. {
  10726. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10727. }
  10728. else
  10729. {
  10730. tempIndex = connectorIdInt -1;
  10731. }
  10732. for (int index = 0; index < CCS_QUANTITY; index++)
  10733. {
  10734. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10735. {
  10736. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10737. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10738. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10739. {
  10740. //Reserved
  10741. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10742. }
  10743. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10744. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10745. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10746. {
  10747. //Reserved
  10748. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10749. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10750. goto end;
  10751. }
  10752. else
  10753. {
  10754. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10755. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10756. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10757. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10758. {
  10759. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10760. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10761. goto end;
  10762. }
  10763. }// END FOR ELSE
  10764. }
  10765. }// END FOR CCS_QUANTITY
  10766. }
  10767. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10768. {
  10769. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10770. {
  10771. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10772. }
  10773. else
  10774. {
  10775. tempIndex = connectorIdInt -1;
  10776. }
  10777. for (int index = 0; index < GB_QUANTITY; index++)
  10778. {
  10779. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10780. {
  10781. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10782. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10783. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10784. {
  10785. //Reserved
  10786. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10787. }
  10788. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10789. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10790. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10791. {
  10792. //Reserved
  10793. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10794. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10795. goto end;
  10796. }
  10797. else
  10798. {
  10799. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10800. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10801. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10802. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10803. {
  10804. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10805. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10806. goto end;
  10807. }
  10808. }// END FOR ELSE
  10809. }
  10810. } // END FOR GB_QUANTITY
  10811. }
  10812. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10813. {
  10814. tempIndex = connectorIdInt -1;
  10815. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10816. {
  10817. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10818. {
  10819. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10820. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10821. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10822. {
  10823. //Reserved
  10824. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10825. }
  10826. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10827. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10828. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10829. {
  10830. //Reserved
  10831. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10832. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10833. goto end;
  10834. }
  10835. else
  10836. {
  10837. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10838. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10839. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10840. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10841. {
  10842. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10843. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10844. goto end;
  10845. }
  10846. }// END FOR ELSE
  10847. }
  10848. } // END FOR GB_QUANTITY
  10849. }
  10850. else
  10851. {
  10852. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10853. {
  10854. tempIndex = 2;
  10855. }
  10856. else
  10857. {
  10858. tempIndex = connectorIdInt -1;
  10859. }
  10860. for (int index = 0; index < AC_QUANTITY; index++)
  10861. {
  10862. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10863. {
  10864. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10865. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10866. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10867. {
  10868. //Reserved
  10869. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10870. }
  10871. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10872. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10873. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10874. {
  10875. //Reserved
  10876. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10877. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10878. goto end;
  10879. }
  10880. else
  10881. {
  10882. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10883. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10884. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10885. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10886. {
  10887. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10888. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10889. goto end;
  10890. }
  10891. }//END FOR ELSE
  10892. }
  10893. }// END FOR AC_QUANTITY
  10894. }
  10895. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10896. {
  10897. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10898. {
  10899. // Save profile to file
  10900. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10901. system(cmdBuf);
  10902. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10903. fp = fopen(cmdBuf, "w");
  10904. 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));
  10905. fclose(fp);
  10906. }
  10907. else
  10908. {
  10909. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10910. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10911. goto end;
  10912. }
  10913. }
  10914. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10915. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10916. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10917. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10918. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10919. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10920. }
  10921. else
  10922. {
  10923. uint8_t isHasIdleConnector = FALSE;
  10924. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10925. {
  10926. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10927. {
  10928. isHasIdleConnector = TRUE;
  10929. break;
  10930. }
  10931. }
  10932. if(isHasIdleConnector == TRUE)
  10933. {
  10934. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10935. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10936. {
  10937. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10938. {
  10939. // Save profile to file
  10940. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  10941. system(cmdBuf);
  10942. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  10943. fp = fopen(cmdBuf, "w");
  10944. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10945. fclose(fp);
  10946. refreshStartTimer(&clientTime.RemoteStartWait);
  10947. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  10948. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10949. }
  10950. else
  10951. {
  10952. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10953. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10954. }
  10955. }
  10956. else
  10957. {
  10958. refreshStartTimer(&clientTime.RemoteStartWait);
  10959. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  10960. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10961. }
  10962. }
  10963. else
  10964. {
  10965. DEBUG_INFO("There is not any connector is idle.\n");
  10966. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10967. }
  10968. }
  10969. }
  10970. else
  10971. {
  10972. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10973. }
  10974. end:
  10975. json_object_put(RemoteStartTransaction);
  10976. sendRemoteStartConfirmation(uuid, comfirmstr);
  10977. return result;
  10978. }
  10979. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10980. {
  10981. mtrace();
  10982. int result = FAIL;
  10983. int match = FALSE;
  10984. int GunNO = 0;
  10985. int tempIndex = 0;
  10986. int transactionIdInt=0;
  10987. int transactionIdIsNULL= TRUE;
  10988. char comfirmstr[20];
  10989. json_object *RemoteStopTransaction;
  10990. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10991. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10992. if(server_pending == TRUE)
  10993. {
  10994. return 0;
  10995. }
  10996. RemoteStopTransaction = json_tokener_parse(payload);
  10997. if(!is_error(RemoteStopTransaction))
  10998. {
  10999. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11000. {
  11001. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11002. transactionIdIsNULL = FALSE;
  11003. }
  11004. }
  11005. json_object_put(RemoteStopTransaction);
  11006. if(transactionIdIsNULL == FALSE)
  11007. {
  11008. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11009. {
  11010. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11011. {
  11012. //check Transaction active
  11013. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11014. {
  11015. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11016. {
  11017. tempIndex = ((gun_index==2) ? 1: 0);
  11018. }
  11019. else
  11020. {
  11021. tempIndex = gun_index;
  11022. }
  11023. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11024. {
  11025. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11026. {
  11027. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11028. {
  11029. match = TRUE;
  11030. GunNO = gun_index;
  11031. }
  11032. }
  11033. }// END FOR CHAdeMO_QUANTITY
  11034. }
  11035. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11036. {
  11037. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11038. {
  11039. tempIndex = ((gun_index==2) ? 1: 0);
  11040. }
  11041. else
  11042. {
  11043. tempIndex = gun_index;
  11044. }
  11045. for (int index = 0; index < CCS_QUANTITY; index++)
  11046. {
  11047. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11048. {
  11049. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11050. {
  11051. match = TRUE;
  11052. GunNO = gun_index;
  11053. }
  11054. }
  11055. }// END FOR CCS_QUANTITY
  11056. }
  11057. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11058. {
  11059. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11060. {
  11061. tempIndex = ((gun_index==2) ? 1: 0);
  11062. }
  11063. else
  11064. {
  11065. tempIndex = gun_index;
  11066. }
  11067. for (int index = 0; index < GB_QUANTITY; index++)
  11068. {
  11069. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11070. {
  11071. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11072. {
  11073. match = TRUE;
  11074. GunNO = gun_index;
  11075. }
  11076. }
  11077. }// END FOR GB_QUANTITY
  11078. }
  11079. else if(gunType[gun_index] == GUN_TYPE_DO)
  11080. {
  11081. tempIndex = gun_index;
  11082. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11083. {
  11084. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11085. {
  11086. 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
  11087. {
  11088. match = TRUE;
  11089. GunNO = gun_index;
  11090. }
  11091. }
  11092. }// END FOR GB_QUANTITY
  11093. }
  11094. else
  11095. {
  11096. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11097. {
  11098. tempIndex = 2;
  11099. }
  11100. else
  11101. {
  11102. tempIndex = gun_index;
  11103. }
  11104. for (int index = 0; index < AC_QUANTITY; index++)
  11105. {
  11106. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11107. {
  11108. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11109. {
  11110. match = TRUE;
  11111. GunNO = gun_index;
  11112. }
  11113. }
  11114. }// END FOR CHAdeMO_QUANTITY
  11115. } // END FOR AC ELSE
  11116. }// CHECK IF ResponseTransactionId == transactionIdInt
  11117. }//END FOR
  11118. if( match == TRUE)
  11119. {
  11120. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11121. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11122. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11123. }
  11124. else
  11125. {
  11126. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11127. }
  11128. }
  11129. else
  11130. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11131. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11132. return result;
  11133. }
  11134. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11135. {
  11136. mtrace();
  11137. int result = FAIL;
  11138. int connectorIdInt=0, reservationIdInt=0;
  11139. int tempIndex = 0;
  11140. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  11141. char comfirmstr[20]={0};
  11142. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11143. int c = 0;
  11144. char *loc;
  11145. //char *ptr;
  11146. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11147. strcpy(sstrtemp, stringtrimspace(payload));
  11148. //***(1)connectorId ****/
  11149. c=0;
  11150. loc = strstr(sstrtemp, "connectorId");
  11151. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11152. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11153. {
  11154. sstr[c] = loc[strlen("connectorId")+2+c];
  11155. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11156. c++;
  11157. }
  11158. sstr[c] = '\0';
  11159. connectorIdInt = atoi(sstr);
  11160. //***(2)expiryDate ****/
  11161. loc = strstr(sstrtemp, "expiryDate");
  11162. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11163. c = 0;
  11164. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11165. {
  11166. sstr[c] = loc[3+strlen("expiryDate")+c];
  11167. c++;
  11168. }
  11169. sstr[c] = '\0';
  11170. strcpy(expiryDatestr, sstr);
  11171. //***(3)idTag ****/
  11172. loc = strstr(sstrtemp, "idTag");
  11173. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11174. c = 0;
  11175. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11176. {
  11177. sstr[c] = loc[3+strlen("idTag")+c];
  11178. c++;
  11179. }
  11180. sstr[c] = '\0';
  11181. strcpy(idTagstr, sstr);
  11182. //***(4)parentIdTag ****/
  11183. loc = strstr(sstrtemp, "parentIdTag");
  11184. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11185. c = 0;
  11186. if(loc == NULL)
  11187. {
  11188. strcpy(parentIdTagstr, "");
  11189. }
  11190. else
  11191. {
  11192. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11193. {
  11194. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11195. c++;
  11196. }
  11197. sstr[c] = '\0';
  11198. strcpy(parentIdTagstr, sstr);
  11199. }
  11200. //***(5)reservationId ****/
  11201. c=0;
  11202. loc = strstr(sstrtemp, "reservationId");
  11203. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11204. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11205. {
  11206. sstr[c] = loc[strlen("reservationId")+2+c];
  11207. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11208. c++;
  11209. }
  11210. sstr[c] = '\0';
  11211. reservationIdInt = atoi(sstr);
  11212. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11213. /*
  11214. enum SYSTEM_STATUS
  11215. {
  11216. SYS_MODE_BOOTING = 0,
  11217. SYS_MODE_IDLE = 1,
  11218. SYS_MODE_AUTHORIZING = 2,
  11219. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11220. SYS_MODE_REASSIGN = 4,
  11221. SYS_MODE_PREPARING = 5,
  11222. SYS_MODE_PREPARE_FOR_EV = 6,
  11223. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11224. SYS_MODE_CHARGING = 8,
  11225. SYS_MODE_TERMINATING = 9,
  11226. SYS_MODE_COMPLETE = 10,
  11227. SYS_MODE_ALARM = 11,
  11228. SYS_MODE_FAULT = 12,
  11229. SYS_MODE_RESERVATION = 13,
  11230. SYS_MODE_BOOKING = 14,
  11231. SYS_MODE_MAINTAIN = 15,
  11232. SYS_MODE_DEBUG = 16,
  11233. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11234. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11235. SYS_MODE_UPDATE = 19
  11236. };
  11237. */
  11238. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11239. {
  11240. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11241. goto end;
  11242. }
  11243. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11244. {
  11245. //check Transaction active
  11246. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11247. {
  11248. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11249. {
  11250. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11251. }
  11252. else
  11253. {
  11254. tempIndex = connectorIdInt -1;
  11255. }
  11256. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11257. {
  11258. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11259. {
  11260. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11261. {
  11262. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11263. {
  11264. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11265. {
  11266. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11267. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11268. }
  11269. 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'))
  11270. {
  11271. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11272. }
  11273. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11274. {
  11275. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11276. }
  11277. else
  11278. {
  11279. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11280. }
  11281. }
  11282. 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
  11283. {
  11284. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11285. }
  11286. }
  11287. else
  11288. {
  11289. //replace reservation
  11290. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11291. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11292. }
  11293. }
  11294. } // END FOR CHAdeMO_QUANTITY
  11295. }
  11296. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11297. {
  11298. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11299. {
  11300. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11301. }
  11302. else
  11303. {
  11304. tempIndex = connectorIdInt -1;
  11305. }
  11306. for (int index = 0; index < CCS_QUANTITY; index++)
  11307. {
  11308. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11309. {
  11310. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11311. {
  11312. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11313. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11314. {
  11315. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11316. {
  11317. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11318. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11319. }
  11320. 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'))
  11321. {
  11322. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11323. }
  11324. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11325. {
  11326. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11327. }
  11328. else
  11329. {
  11330. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11331. }
  11332. }
  11333. 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
  11334. {
  11335. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11336. }
  11337. }
  11338. else
  11339. {
  11340. //replace reservation
  11341. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11342. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11343. }
  11344. }
  11345. } // END FOR CCS_QUANTITY
  11346. }
  11347. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11348. {
  11349. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11350. {
  11351. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11352. }
  11353. else
  11354. {
  11355. tempIndex = connectorIdInt -1;
  11356. }
  11357. for (int index = 0; index < GB_QUANTITY; index++)
  11358. {
  11359. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11360. {
  11361. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11362. {
  11363. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11364. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11365. {
  11366. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11367. {
  11368. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11369. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11370. }
  11371. 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'))
  11372. {
  11373. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11374. }
  11375. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11376. {
  11377. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11378. }
  11379. else
  11380. {
  11381. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11382. }
  11383. }
  11384. 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
  11385. {
  11386. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11387. }
  11388. }
  11389. else
  11390. {
  11391. //replace reservation
  11392. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11393. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11394. }
  11395. }
  11396. }// END FOR GB_QUANTITY
  11397. }
  11398. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11399. {
  11400. tempIndex = connectorIdInt -1;
  11401. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11402. {
  11403. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11404. {
  11405. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11406. {
  11407. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11408. 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
  11409. {
  11410. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11411. {
  11412. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11413. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11414. }
  11415. 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'))
  11416. {
  11417. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11418. }
  11419. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11420. {
  11421. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11422. }
  11423. else
  11424. {
  11425. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11426. }
  11427. }
  11428. 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
  11429. {
  11430. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11431. }
  11432. }
  11433. else
  11434. {
  11435. //replace reservation
  11436. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11437. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11438. }
  11439. }
  11440. }// END FOR GB_QUANTITY
  11441. }
  11442. else
  11443. {
  11444. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11445. {
  11446. tempIndex = 2;
  11447. }
  11448. else
  11449. {
  11450. tempIndex = (connectorIdInt -1);
  11451. }
  11452. for (int index = 0; index < AC_QUANTITY; index++)
  11453. {
  11454. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11455. {
  11456. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11457. {
  11458. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11459. {
  11460. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11461. {
  11462. 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))
  11463. {
  11464. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11465. }
  11466. else
  11467. {
  11468. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11469. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11470. }
  11471. }
  11472. 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'))
  11473. {
  11474. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11475. }
  11476. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11477. {
  11478. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11479. }
  11480. else
  11481. {
  11482. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11483. }
  11484. }
  11485. else if((ShmSysConfigAndInfo->SysInfo.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
  11486. {
  11487. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11488. }
  11489. }
  11490. else
  11491. {
  11492. //replace reservation
  11493. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11494. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11495. }
  11496. }
  11497. } // END FOR AC_QUANTITY
  11498. }
  11499. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11500. }
  11501. else if(connectorIdInt == 0)
  11502. {
  11503. //check Transaction active
  11504. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11505. {
  11506. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11507. {
  11508. 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'))
  11509. {
  11510. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11511. goto end;
  11512. }
  11513. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11514. {
  11515. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11516. goto end;
  11517. }
  11518. 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
  11519. {
  11520. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11521. goto end;
  11522. }
  11523. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11524. {
  11525. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11526. goto end;
  11527. }
  11528. }
  11529. }// END FOR CHAdeMO_QUANTITY
  11530. for (int index = 0; index < CCS_QUANTITY; index++)
  11531. {
  11532. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11533. {
  11534. 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'))
  11535. {
  11536. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11537. goto end;
  11538. }
  11539. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11540. {
  11541. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11542. goto end;
  11543. }
  11544. 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
  11545. {
  11546. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11547. goto end;
  11548. }
  11549. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11550. {
  11551. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11552. goto end;
  11553. }
  11554. }
  11555. } // END FOR CCS_QUANTITY
  11556. for (int index = 0; index < GB_QUANTITY; index++)
  11557. {
  11558. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11559. {
  11560. 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'))
  11561. {
  11562. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11563. goto end;
  11564. }
  11565. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11566. {
  11567. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11568. goto end;
  11569. }
  11570. 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
  11571. {
  11572. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11573. goto end;
  11574. }
  11575. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11576. {
  11577. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11578. goto end;
  11579. }
  11580. }
  11581. } // END FOR GB_QUANTITY
  11582. for (int index = 0; index < AC_QUANTITY; index++)
  11583. {
  11584. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11585. {
  11586. 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'))
  11587. {
  11588. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11589. goto end;
  11590. }
  11591. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11592. {
  11593. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11594. goto end;
  11595. }
  11596. 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
  11597. {
  11598. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11599. goto end;
  11600. }
  11601. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11602. {
  11603. 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))
  11604. {
  11605. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11606. goto end;
  11607. }
  11608. }
  11609. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11610. {
  11611. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11612. goto end;
  11613. }
  11614. }
  11615. }// END FOR AC_QUANTITY
  11616. //The connectorId is 0
  11617. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  11618. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11619. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11620. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  11621. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11622. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  11623. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11624. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  11625. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  11626. result = TRUE;
  11627. return result;
  11628. }
  11629. else
  11630. {
  11631. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11632. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11633. }
  11634. if(strcmp(comfirmstr,"Accepted") == 0)
  11635. {
  11636. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11637. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11638. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11639. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11640. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11641. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  11642. result = TRUE;
  11643. return result;
  11644. }
  11645. end:
  11646. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11647. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11648. return result;
  11649. }
  11650. int handleResetRequest(char *uuid, char *payload)
  11651. {
  11652. mtrace();
  11653. int result = FAIL;
  11654. char sstr[10]={0},sstrtemp[30]={ 0 };
  11655. char typestr[10]={0};
  11656. char comfirmstr[20]={0};
  11657. int c = 0;
  11658. char *loc;
  11659. DEBUG_INFO("handleResetRequest...\n");
  11660. strcpy(sstrtemp, stringtrimspace(payload));
  11661. loc = strstr(sstrtemp, "type");
  11662. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11663. c = 0;
  11664. while (loc[3+strlen("type")+c] != '\"')
  11665. {
  11666. sstr[c] = loc[3+strlen("type")+c];
  11667. c++;
  11668. }
  11669. sstr[c] = '\0';
  11670. strcpy(typestr,sstr);
  11671. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11672. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11673. {
  11674. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11675. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  11676. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11677. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11678. }
  11679. else
  11680. {
  11681. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11682. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11683. result = PASS;
  11684. }
  11685. sendResetConfirmation(uuid, comfirmstr);
  11686. return result;
  11687. }
  11688. int handleSendLocalListRequest(char *uuid, char *payload)
  11689. {
  11690. mtrace();
  11691. int result = FAIL;
  11692. char comfirmstr[20];
  11693. int checkState_Faulted = FALSE;
  11694. json_object *SendLocalList;
  11695. DEBUG_INFO("handleSendLocalListRequest...\n");
  11696. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11697. {
  11698. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11699. goto end;
  11700. }
  11701. //check Charge Point state
  11702. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11703. {
  11704. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11705. {
  11706. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11707. }
  11708. }
  11709. for (int index = 0; index < CCS_QUANTITY; index++)
  11710. {
  11711. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11712. {
  11713. checkState_Faulted = TRUE; //OCPP Status
  11714. }
  11715. }
  11716. for (int index = 0; index < GB_QUANTITY; index++)
  11717. {
  11718. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11719. {
  11720. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11721. }
  11722. }
  11723. //check Charge Point state
  11724. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11725. {
  11726. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11727. {
  11728. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11729. }
  11730. }
  11731. //check Charge Point state
  11732. for (int index = 0; index < AC_QUANTITY; index++)
  11733. {
  11734. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11735. {
  11736. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11737. }
  11738. }
  11739. if(checkState_Faulted == TRUE)
  11740. {
  11741. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11742. goto end;
  11743. }
  11744. // Parsing payload
  11745. SendLocalList = json_tokener_parse(payload);
  11746. if(!is_error(SendLocalList))
  11747. {
  11748. // Required data
  11749. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11750. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11751. // Optional data
  11752. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11753. {
  11754. //Check UpdateType
  11755. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11756. {
  11757. //Local list full update
  11758. DEBUG_INFO("Local list full update.\n");
  11759. OCPP_getListVerion();
  11760. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11761. {
  11762. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11763. goto end;
  11764. }
  11765. OCPP_cleanLocalList();
  11766. }
  11767. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11768. {
  11769. //Local list different update
  11770. DEBUG_INFO("Local list different update.\n");
  11771. OCPP_getListVerion();
  11772. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11773. {
  11774. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11775. goto end;
  11776. }
  11777. }
  11778. else
  11779. {
  11780. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11781. goto end;
  11782. }
  11783. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11784. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11785. {
  11786. 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")));
  11787. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11788. {
  11789. 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")));
  11790. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11791. 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")));
  11792. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11793. 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")));
  11794. }
  11795. // Add to db
  11796. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11797. {
  11798. //Local list full update
  11799. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11800. idx,
  11801. ShmOCPP16Data->SendLocalList.ListVersion,
  11802. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11803. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11804. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11805. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11806. // update list
  11807. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11808. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11809. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11810. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11811. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11812. }
  11813. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11814. {
  11815. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11816. idx,
  11817. ShmOCPP16Data->SendLocalList.ListVersion,
  11818. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11819. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11820. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11821. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11822. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11823. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11824. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11825. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11826. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11827. }
  11828. }
  11829. }
  11830. else
  11831. {
  11832. //Check UpdateType
  11833. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11834. {
  11835. //Local list full update
  11836. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11837. OCPP_cleanLocalList();
  11838. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11839. goto end;
  11840. }
  11841. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11842. {
  11843. //Local list different update
  11844. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11845. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11846. goto end;
  11847. }
  11848. }
  11849. result = PASS;
  11850. }
  11851. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11852. end:
  11853. json_object_put(SendLocalList);
  11854. sendSendLocalListConfirmation(uuid, comfirmstr);
  11855. return result;
  11856. }
  11857. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11858. {
  11859. mtrace();
  11860. int result = FAIL;
  11861. struct StructSetChargingProfile SetProfileReq = {0};
  11862. int tempchargingProfileIdInt;
  11863. int chargingSchedulePeriodCount = 0;
  11864. char comfirmstr[20]={0};
  11865. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  11866. char rmFileCmd[128]={0};
  11867. int profileQuantity = 0;
  11868. json_object *SetChargingProfile;
  11869. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11870. SetChargingProfile = json_tokener_parse(payload);
  11871. if(!is_error(SetChargingProfile))
  11872. {
  11873. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11874. {
  11875. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11876. }
  11877. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11878. {
  11879. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11880. {
  11881. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11882. }
  11883. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11884. {
  11885. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11886. }
  11887. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11888. {
  11889. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11890. }
  11891. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11892. {
  11893. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11894. }
  11895. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11896. {
  11897. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11898. }
  11899. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11900. {
  11901. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11902. }
  11903. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11904. {
  11905. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11906. }
  11907. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11908. {
  11909. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11910. }
  11911. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11912. {
  11913. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11914. {
  11915. 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")));
  11916. }
  11917. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11918. {
  11919. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11920. }
  11921. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11922. {
  11923. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11924. }
  11925. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11926. {
  11927. 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")));
  11928. }
  11929. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11930. {
  11931. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11932. if(chargingSchedulePeriodCount <= 10)
  11933. {
  11934. 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++)
  11935. {
  11936. 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)
  11937. {
  11938. 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"));
  11939. }
  11940. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit") != NULL)
  11941. {
  11942. 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"));
  11943. }
  11944. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  11945. {
  11946. 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"));
  11947. }
  11948. }
  11949. }
  11950. }
  11951. }
  11952. }
  11953. }
  11954. // Profile periods quantity check
  11955. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11956. {
  11957. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11958. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11959. goto end;
  11960. }
  11961. // Check invalid limit
  11962. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11963. {
  11964. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11965. {
  11966. 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)))) ||
  11967. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11968. {
  11969. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11970. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11971. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11972. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11973. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11974. goto end;
  11975. }
  11976. }
  11977. }
  11978. else
  11979. {
  11980. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11981. {
  11982. 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))
  11983. {
  11984. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11985. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11986. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11987. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11988. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11989. goto end;
  11990. }
  11991. }
  11992. }
  11993. // Profile purpose info check
  11994. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11995. {
  11996. FILE *fp;
  11997. char dataLine[4096]={0};
  11998. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11999. if(SetProfileReq.ConnectorId != 0)
  12000. {
  12001. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12002. DEBUG_WARN("Profile connector id is not 0.\n");
  12003. goto end;
  12004. }
  12005. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12006. if (!fp)
  12007. {
  12008. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12009. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12010. }
  12011. else
  12012. {
  12013. while(fscanf(fp, "%s", dataLine) != EOF)
  12014. {
  12015. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12016. {
  12017. profileQuantity += 1;
  12018. }
  12019. }
  12020. }
  12021. fclose(fp);
  12022. }
  12023. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12024. {
  12025. FILE *fp;
  12026. char dataLine[4096]={0};
  12027. char filename[128]={0};
  12028. int tmpProfileQuantity;
  12029. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12030. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12031. {
  12032. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12033. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12034. goto end;
  12035. }
  12036. if(SetProfileReq.ConnectorId == 0)
  12037. {
  12038. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12039. {
  12040. tmpProfileQuantity = 0;
  12041. memset(filename, 0, ARRAY_SIZE(filename));
  12042. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12043. fp = fopen(filename, "r");
  12044. if (!fp)
  12045. {
  12046. DEBUG_INFO("%s does not create.\n", filename);
  12047. fp = fopen(filename, "w+");
  12048. }
  12049. else
  12050. {
  12051. while(fscanf(fp, "%s", dataLine) != EOF)
  12052. {
  12053. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12054. {
  12055. tmpProfileQuantity += 1;
  12056. }
  12057. }
  12058. }
  12059. fclose(fp);
  12060. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12061. }
  12062. }
  12063. else
  12064. {
  12065. memset(filename, 0, ARRAY_SIZE(filename));
  12066. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12067. fp = fopen(filename, "r");
  12068. if (!fp)
  12069. {
  12070. DEBUG_INFO("%s does not create.\n", filename);
  12071. fp = fopen(filename, "w+");
  12072. }
  12073. else
  12074. {
  12075. while(fscanf(fp, "%s", dataLine) != EOF)
  12076. {
  12077. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12078. {
  12079. profileQuantity += 1;
  12080. }
  12081. }
  12082. }
  12083. fclose(fp);
  12084. }
  12085. }
  12086. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12087. {
  12088. int isMatchTransactiodId= FALSE;
  12089. FILE *fp;
  12090. char dataLine[4096]={0};
  12091. char filename[128]={0};
  12092. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12093. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12094. if(SetProfileReq.ConnectorId == 0)
  12095. {
  12096. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12097. DEBUG_WARN("Profile connector id is 0.\n");
  12098. goto end;
  12099. }
  12100. int tempIndex = 0;
  12101. //check Transaction active
  12102. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12103. {
  12104. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12105. {
  12106. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12107. }
  12108. else
  12109. {
  12110. tempIndex = SetProfileReq.ConnectorId -1;
  12111. }
  12112. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12113. {
  12114. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12115. {
  12116. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12117. {
  12118. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12119. {
  12120. isMatchTransactiodId = TRUE;
  12121. break;
  12122. }
  12123. }
  12124. }
  12125. }
  12126. }
  12127. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12128. {
  12129. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12130. {
  12131. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12132. }
  12133. else
  12134. {
  12135. tempIndex = SetProfileReq.ConnectorId -1;
  12136. }
  12137. for (int index = 0; index < CCS_QUANTITY; index++)
  12138. {
  12139. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12140. {
  12141. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12142. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12143. {
  12144. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12145. {
  12146. isMatchTransactiodId = TRUE;
  12147. break;
  12148. }
  12149. }
  12150. }
  12151. }
  12152. }
  12153. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12154. {
  12155. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12156. {
  12157. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12158. }
  12159. else
  12160. {
  12161. tempIndex = SetProfileReq.ConnectorId -1;
  12162. }
  12163. for (int index = 0; index < GB_QUANTITY; index++)
  12164. {
  12165. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12166. {
  12167. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12168. {
  12169. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12170. {
  12171. isMatchTransactiodId = TRUE;
  12172. break;
  12173. }
  12174. }
  12175. }
  12176. }
  12177. }
  12178. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12179. {
  12180. tempIndex = SetProfileReq.ConnectorId -1;
  12181. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12182. {
  12183. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12184. {
  12185. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12186. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12187. {
  12188. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12189. {
  12190. isMatchTransactiodId = TRUE;
  12191. break;
  12192. }
  12193. }
  12194. }
  12195. }
  12196. }
  12197. else
  12198. {
  12199. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12200. {
  12201. tempIndex = 2;
  12202. }
  12203. else
  12204. {
  12205. tempIndex = (SetProfileReq.ConnectorId -1);
  12206. }
  12207. for (int index = 0; index < AC_QUANTITY; index++)
  12208. {
  12209. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12210. {
  12211. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12212. {
  12213. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12214. {
  12215. isMatchTransactiodId = TRUE;
  12216. break;
  12217. }
  12218. }
  12219. }
  12220. }
  12221. }
  12222. //check Transaction active
  12223. if(isMatchTransactiodId == FALSE)
  12224. {
  12225. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12226. DEBUG_WARN("Tx profile transaction id is not match.\n");
  12227. goto end;
  12228. }
  12229. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12230. {
  12231. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12232. DEBUG_WARN("Connector id is over max gun number.\n");
  12233. goto end;
  12234. }
  12235. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12236. fp = fopen(filename, "r");
  12237. if (!fp)
  12238. {
  12239. DEBUG_INFO("%s does not create.\n", filename);
  12240. fp = fopen(filename, "w+");
  12241. }
  12242. else
  12243. {
  12244. //Check Charging Profile Count
  12245. while(fscanf(fp, "%s", dataLine) != EOF)
  12246. {
  12247. //DEBUG_INFO("word=%s\n",word);
  12248. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12249. {
  12250. profileQuantity += 1;
  12251. }
  12252. }
  12253. }
  12254. fclose(fp);
  12255. }
  12256. // Check ChargeProfileMaxStackLevel
  12257. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12258. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12259. {
  12260. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12261. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12262. goto end;
  12263. }
  12264. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12265. {
  12266. FILE *fp;
  12267. char dataLine[4096]={0};
  12268. char fnametemp[128]={0};
  12269. int tmpProfileQuantity;
  12270. //Check ChargePointMaxProfile.json exit
  12271. profileQuantity = 0;
  12272. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12273. {
  12274. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  12275. //Check Charging Profile Count
  12276. tmpProfileQuantity = 0;
  12277. while(fscanf(fp, "%s", dataLine) != EOF)
  12278. {
  12279. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12280. {
  12281. profileQuantity += 1;
  12282. tmpProfileQuantity += 1;
  12283. }
  12284. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12285. }
  12286. fclose(fp);
  12287. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12288. }
  12289. //Check TxDefaultProfile_%d.json
  12290. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12291. {
  12292. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12293. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12294. if((access(fnametemp,F_OK))!=-1)
  12295. {
  12296. fp = fopen(fnametemp, "r");
  12297. //Check Charging Profile Count
  12298. tmpProfileQuantity = 0;
  12299. while(fscanf(fp, "%s", dataLine) != EOF)
  12300. {
  12301. //DEBUG_INFO("word=%s\n",word);
  12302. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12303. {
  12304. profileQuantity += 1;
  12305. tmpProfileQuantity += 1;
  12306. }
  12307. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12308. }
  12309. fclose(fp);
  12310. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12311. }
  12312. }
  12313. //Check TxProfile_%d.json
  12314. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12315. {
  12316. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12317. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  12318. if((access(fnametemp,F_OK))!=-1)
  12319. {
  12320. fp = fopen(fnametemp, "r");
  12321. //Check Charging Profile Count
  12322. tmpProfileQuantity = 0;
  12323. while(fscanf(fp, "%s", dataLine) != EOF)
  12324. {
  12325. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12326. {
  12327. profileQuantity += 1;
  12328. tmpProfileQuantity += 1;
  12329. }
  12330. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12331. }
  12332. fclose(fp);
  12333. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12334. }
  12335. }
  12336. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12337. if(profileQuantity > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12338. {
  12339. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12340. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12341. goto end;
  12342. }
  12343. }
  12344. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12345. //**********************************Write to File********************************************************/
  12346. {
  12347. FILE *infile;
  12348. FILE *outfile;
  12349. char dataLine[4096]={0};
  12350. char filename[128]={0};
  12351. int chkChar=0;
  12352. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12353. {
  12354. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12355. {
  12356. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12357. }
  12358. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12359. {
  12360. if(SetProfileReq.ConnectorId==0)
  12361. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12362. else
  12363. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12364. }
  12365. else
  12366. {
  12367. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12368. }
  12369. infile = fopen (filename, "r");
  12370. outfile = fopen (tempfile, "w");
  12371. chkChar = fgetc(infile);
  12372. rewind(infile);
  12373. if(chkChar == EOF)
  12374. {
  12375. // Profile is empty
  12376. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12377. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12378. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12379. fclose(infile);
  12380. fclose(outfile);
  12381. sprintf(rmFileCmd,"rm -f %s",filename);
  12382. system(rmFileCmd);
  12383. rename(tempfile, filename);
  12384. }
  12385. else
  12386. {
  12387. // Profile is not empty
  12388. int ChargingProfileAdded = FALSE;
  12389. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12390. {
  12391. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12392. json_object *tmpChargingProfile;
  12393. tmpChargingProfile = json_tokener_parse(dataLine);
  12394. if(!is_error(SetChargingProfile))
  12395. {
  12396. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12397. {
  12398. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12399. {
  12400. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12401. }
  12402. }
  12403. }
  12404. json_object_put(tmpChargingProfile);
  12405. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12406. {
  12407. if(ChargingProfileAdded == FALSE)
  12408. {
  12409. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12410. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12411. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12412. ChargingProfileAdded = TRUE;
  12413. }
  12414. }
  12415. else
  12416. {
  12417. fprintf(outfile,"%s\n",dataLine);
  12418. if(ChargingProfileAdded == FALSE)
  12419. {
  12420. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12421. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12422. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12423. ChargingProfileAdded = TRUE;
  12424. }
  12425. }
  12426. } // end of while loop
  12427. fclose(infile);
  12428. fclose(outfile);
  12429. sprintf(rmFileCmd,"rm -f %s",filename);
  12430. system(rmFileCmd);
  12431. rename(tempfile, filename);
  12432. }
  12433. }
  12434. sleep(1);
  12435. result = TRUE;
  12436. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12437. }
  12438. end:
  12439. json_object_put(SetChargingProfile);
  12440. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12441. {
  12442. if(SetProfileReq.ConnectorId == 0)
  12443. {
  12444. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12445. {
  12446. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  12447. }
  12448. }
  12449. else
  12450. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12451. }
  12452. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12453. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12454. return result;
  12455. }
  12456. int handleTriggerMessageRequest(char *uuid, char *payload)
  12457. {
  12458. mtrace();
  12459. int result = FAIL;
  12460. int connectorIdIsNULL = FALSE;
  12461. int connectorIdInt =0;
  12462. char sstr[40]={0},sstrtemp[100]={ 0 };
  12463. char requestedMessagestr[40]={0};
  12464. char comfirmstr[20]={0};
  12465. int c = 0;
  12466. char *loc;
  12467. DEBUG_INFO("handleTriggerMessageRequest\n");
  12468. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12469. strcpy(sstrtemp, stringtrimspace(payload));
  12470. c = 0;
  12471. loc = strstr(sstrtemp, "requestedMessage");
  12472. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12473. {
  12474. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12475. c++;
  12476. }
  12477. sstr[c] = '\0';
  12478. strcpy(requestedMessagestr, sstr);
  12479. c = 0;
  12480. loc = strstr(sstrtemp, "connectorId");
  12481. if(loc == NULL)
  12482. {
  12483. connectorIdIsNULL = TRUE;
  12484. }
  12485. else
  12486. {
  12487. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12488. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12489. {
  12490. sstr[c] = loc[strlen("connectorId")+2+c];
  12491. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12492. c++;
  12493. }
  12494. sstr[c] = '\0';
  12495. connectorIdInt = atoi(sstr);
  12496. }
  12497. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12498. {
  12499. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12500. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12501. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12502. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12503. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12504. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12505. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12506. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12507. {
  12508. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12509. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12510. return TRUE;
  12511. }
  12512. else
  12513. {
  12514. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12515. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12516. }
  12517. }
  12518. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12519. {
  12520. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12521. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12522. return TRUE;
  12523. }
  12524. //==========================
  12525. // Trigger message
  12526. //==========================
  12527. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12528. {
  12529. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12530. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12531. {
  12532. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12533. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12534. }
  12535. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12536. }
  12537. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12538. {
  12539. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  12540. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12541. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12542. }
  12543. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12544. {
  12545. //sendBootNotificationRequest();
  12546. server_sign = FALSE;
  12547. }
  12548. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12549. {
  12550. refreshStartTimer(&clientTime.Heartbeat);
  12551. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  12552. }
  12553. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12554. {
  12555. if(connectorIdIsNULL == FALSE)
  12556. {
  12557. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12558. {
  12559. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12560. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12561. }
  12562. }
  12563. else
  12564. {
  12565. for(int idx=0;idx< gunTotalNumber;idx++)
  12566. {
  12567. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12568. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12569. }
  12570. }
  12571. }
  12572. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12573. {
  12574. if(connectorIdIsNULL == FALSE)
  12575. {
  12576. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  12577. {
  12578. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12579. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  12580. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12581. }
  12582. }
  12583. else
  12584. {
  12585. for(int idx=0;idx< gunTotalNumber;idx++)
  12586. {
  12587. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  12588. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12589. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12590. }
  12591. }
  12592. }
  12593. return result;
  12594. }
  12595. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12596. {
  12597. mtrace();
  12598. int result = FAIL;
  12599. int connectorIdInt =0;
  12600. char comfirmstr[20]={0};
  12601. int tempIndex = 0;
  12602. json_object *UnlockConnector;
  12603. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12604. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12605. UnlockConnector = json_tokener_parse(payload);
  12606. if(!is_error(UnlockConnector))
  12607. {
  12608. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12609. {
  12610. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12611. }
  12612. }
  12613. json_object_put(UnlockConnector);
  12614. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12615. if(gunTotalNumber == 0)
  12616. {
  12617. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12618. goto end;
  12619. }
  12620. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12621. {
  12622. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12623. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12624. goto end;
  12625. }
  12626. else
  12627. {
  12628. //check Transaction active
  12629. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12630. {
  12631. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12632. {
  12633. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12634. }
  12635. else
  12636. {
  12637. tempIndex = connectorIdInt -1;
  12638. }
  12639. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12640. {
  12641. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12642. {
  12643. //stop Transaction
  12644. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12645. }
  12646. }
  12647. }
  12648. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12649. {
  12650. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12651. {
  12652. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12653. }
  12654. else
  12655. {
  12656. tempIndex = connectorIdInt -1;
  12657. }
  12658. for (int index = 0; index < CCS_QUANTITY; index++)
  12659. {
  12660. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12661. {
  12662. //stop Transaction
  12663. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12664. }
  12665. }
  12666. }
  12667. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12668. {
  12669. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12670. {
  12671. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12672. }
  12673. else
  12674. {
  12675. tempIndex = connectorIdInt -1;
  12676. }
  12677. for (int index = 0; index < GB_QUANTITY; index++)
  12678. {
  12679. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12680. {
  12681. //stop Transaction
  12682. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12683. }
  12684. }
  12685. }
  12686. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12687. {
  12688. tempIndex = connectorIdInt -1;
  12689. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12690. {
  12691. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12692. {
  12693. //stop Transaction
  12694. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12695. }
  12696. }
  12697. }
  12698. else
  12699. {
  12700. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12701. {
  12702. tempIndex = 2;
  12703. }
  12704. else
  12705. {
  12706. tempIndex = connectorIdInt-1;
  12707. }
  12708. for (int index = 0; index < AC_QUANTITY; index++)
  12709. {
  12710. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12711. {
  12712. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12713. }
  12714. }
  12715. }
  12716. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12717. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  12718. result = TRUE;
  12719. return result;
  12720. }
  12721. end:
  12722. //json_object_put(obj); --- remove temporally
  12723. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12724. return result;
  12725. }
  12726. static char UpdateFirmwarepayloadData[300]={0};
  12727. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12728. {
  12729. mtrace();
  12730. int result = FAIL;
  12731. pthread_t t;
  12732. sendUpdateFirmwareConfirmation(uuid);
  12733. memset(UpdateFirmwarepayloadData, 0, 300);
  12734. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12735. if(!interLock.isUpdateFirmwareGoing)
  12736. {
  12737. interLock.isUpdateFirmwareGoing = 1;
  12738. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12739. sleep(1);
  12740. }
  12741. else
  12742. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12743. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  12744. return result;
  12745. }
  12746. void *UpdateFirmwareProcess(void *data)
  12747. {
  12748. pthread_detach(pthread_self());
  12749. mtrace();
  12750. int retriesInt =0, retryIntervalInt=0;
  12751. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  12752. int port=0;
  12753. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  12754. int isSuccess = 0;
  12755. char ftpbuf[1024];
  12756. char temp[1024];
  12757. char * pch;
  12758. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12759. json_object *UpdateFirmware;
  12760. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12761. if(!is_error(UpdateFirmware))
  12762. {
  12763. // Required data
  12764. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12765. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12766. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12767. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12768. // Optional data
  12769. if(json_object_object_get(UpdateFirmware, "retries"))
  12770. {
  12771. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12772. }
  12773. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12774. {
  12775. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12776. }
  12777. }
  12778. json_object_put(UpdateFirmware);
  12779. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12780. memset(path, 0, ARRAY_SIZE(path));
  12781. // Wait retrieveData
  12782. if(strlen(retrieveDatestr) > 10)
  12783. {
  12784. do
  12785. {
  12786. sleep(1);
  12787. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12788. }
  12789. // Ready to download
  12790. system("rm -f /mnt/*");
  12791. if(strncmp(locationstr,"http", 4) == 0)
  12792. {
  12793. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12794. sprintf(ftppath,"/%s", path);
  12795. DEBUG_INFO("locationstr: %s\n", locationstr);
  12796. DEBUG_INFO("protocol: %s\n",protocol);
  12797. DEBUG_INFO("host: %s\n",host);
  12798. DEBUG_INFO("path: %s\n",path);
  12799. DEBUG_INFO("ftppath: %s\n",ftppath);
  12800. int ftppathlen=strlen(ftppath);
  12801. int i=1;
  12802. char filenametemp[50];
  12803. while(i < ftppathlen)
  12804. {
  12805. int len=ftppathlen-i;
  12806. if(ftppath[len]== 47) // '/' ascll code: 47
  12807. {
  12808. DEBUG_INFO("compare '/' all right\n");
  12809. break;
  12810. }
  12811. i=i+1;
  12812. }
  12813. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12814. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12815. filenametemp[i+1] = 0;
  12816. do
  12817. {
  12818. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12819. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12820. sleep(1);
  12821. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12822. if(!isSuccess)
  12823. {
  12824. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12825. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12826. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12827. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12828. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12829. }
  12830. else
  12831. {
  12832. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12833. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12834. }
  12835. retriesInt--;
  12836. }while((isSuccess == 0)&&(retriesInt >= 0));
  12837. }
  12838. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12839. {
  12840. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12841. memset(temp, 0, ARRAY_SIZE(temp));
  12842. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12843. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12844. int ftppathlen=strlen(ftpbuf);
  12845. int i=1;
  12846. char filenametemp[50];
  12847. while(i < ftppathlen)
  12848. {
  12849. int len=ftppathlen-i;
  12850. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12851. {
  12852. DEBUG_INFO(" compare '/' all right\n");
  12853. break;
  12854. }
  12855. i=i+1;
  12856. }
  12857. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12858. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12859. filenametemp[i+1] = 0;
  12860. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12861. pch=strchr(temp,'@');
  12862. if(pch==NULL)
  12863. {
  12864. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12865. protocol, host, &port, path);
  12866. strcpy(user,"anonymous");
  12867. strcpy(password,"");
  12868. }
  12869. else
  12870. {
  12871. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12872. protocol, user, password, host, &port, path);
  12873. }
  12874. sscanf(host,"%[^/]%s",host1, path1);
  12875. sprintf(ftppath,"%s", path1);
  12876. //DEBUG_INFO("protocol =%s\n",protocol);
  12877. //DEBUG_INFO("user =%s\n",user);
  12878. //DEBUG_INFO("password =%s\n",password);
  12879. //DEBUG_INFO("host1 =%s\n",host1);
  12880. //DEBUG_INFO("port =%d\n",port);
  12881. //DEBUG_INFO("path1 =%s\n",path1);
  12882. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12883. //ftpFile(host, user, password, port, ftppath, fname);
  12884. //download firmware pthred
  12885. if(port == 0)
  12886. {
  12887. port = 21;
  12888. }
  12889. do
  12890. {
  12891. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12892. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12893. sleep(1);
  12894. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12895. if(!isSuccess)
  12896. {
  12897. //BulldogUtil.sleepMs(interval*1000);
  12898. DEBUG_INFO("Update firmware request and download file fail.\n");
  12899. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12900. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12901. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12902. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12903. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12904. }
  12905. else
  12906. {
  12907. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12908. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12909. }
  12910. retriesInt--;
  12911. }while((!isSuccess)&&(retriesInt >= 0));
  12912. }
  12913. else
  12914. {
  12915. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12916. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12917. sleep(1);
  12918. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12919. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12920. }
  12921. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12922. interLock.isUpdateFirmwareGoing = 0;
  12923. pthread_exit(NULL);
  12924. }
  12925. int handleCertificateSignedRequest(char *uuid, char *payload)
  12926. {
  12927. mtrace();
  12928. int result = PASS;
  12929. json_object *CertificateSigned;
  12930. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12931. CertificateSigned = json_tokener_parse(payload);
  12932. if(!is_error(CertificateSigned))
  12933. {
  12934. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  12935. }
  12936. json_object_put(CertificateSigned);
  12937. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  12938. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  12939. fclose(fp);
  12940. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12941. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  12942. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  12943. sendCertificateSignedConfirmation(uuid);
  12944. return result;
  12945. }
  12946. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12947. {
  12948. mtrace();
  12949. int result = PASS;
  12950. json_object *DeleteCertificate;
  12951. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12952. DeleteCertificate = json_tokener_parse(payload);
  12953. if(!is_error(DeleteCertificate))
  12954. {
  12955. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12956. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12957. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12958. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12959. }
  12960. json_object_put(DeleteCertificate);
  12961. /*
  12962. * TODO: Delete certificateSigned process
  12963. */
  12964. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  12965. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  12966. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  12967. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  12968. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  12969. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  12970. sendDeleteCertificateConfirmation(uuid);
  12971. return result;
  12972. }
  12973. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12974. {
  12975. mtrace();
  12976. int result = PASS;
  12977. json_object *ExtendedTriggerMessage;
  12978. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12979. ExtendedTriggerMessage = json_tokener_parse(payload);
  12980. if(!is_error(ExtendedTriggerMessage))
  12981. {
  12982. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12983. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12984. {
  12985. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12986. }
  12987. else
  12988. {
  12989. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  12990. }
  12991. }
  12992. json_object_put(ExtendedTriggerMessage);
  12993. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  12994. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  12995. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  12996. {
  12997. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  12998. }
  12999. else
  13000. {
  13001. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13002. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13003. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13004. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13005. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13006. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13007. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13008. {
  13009. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13010. }
  13011. else
  13012. {
  13013. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13014. }
  13015. }
  13016. sendExtendedTriggerMessageConfirmation(uuid);
  13017. //==========================
  13018. // Trigger message
  13019. //==========================
  13020. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13021. {
  13022. //sendBootNotificationRequest();
  13023. server_sign = FALSE;
  13024. }
  13025. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13026. {
  13027. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13028. }
  13029. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13030. {
  13031. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13032. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13033. {
  13034. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13035. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13036. }
  13037. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13038. }
  13039. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13040. {
  13041. refreshStartTimer(&clientTime.Heartbeat);
  13042. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13043. }
  13044. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13045. {
  13046. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13047. {
  13048. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13049. }
  13050. else
  13051. {
  13052. for(int idx=0;idx< gunTotalNumber;idx++)
  13053. {
  13054. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13055. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13056. }
  13057. }
  13058. }
  13059. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13060. {
  13061. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  13062. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13063. {
  13064. 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\" &");
  13065. }
  13066. }
  13067. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13068. {
  13069. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13070. {
  13071. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13072. }
  13073. else
  13074. {
  13075. for(int idx=0;idx< gunTotalNumber;idx++)
  13076. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13077. }
  13078. }
  13079. return result;
  13080. }
  13081. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13082. {
  13083. mtrace();
  13084. int result = PASS;
  13085. json_object *GetInstalledCertificateIds;
  13086. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13087. GetInstalledCertificateIds = json_tokener_parse(payload);
  13088. if(!is_error(GetInstalledCertificateIds))
  13089. {
  13090. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13091. }
  13092. json_object_put(GetInstalledCertificateIds);
  13093. /*
  13094. * TODO: Return installed certificate process
  13095. */
  13096. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13097. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  13098. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13099. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13100. sendGetInstalledCertificateIdsConfirmation(uuid);
  13101. return result;
  13102. }
  13103. int handleGetLogRequest(char *uuid, char *payload)
  13104. {
  13105. mtrace();
  13106. int result = PASS;
  13107. json_object *GetLog;
  13108. DEBUG_INFO("handleGetLogRequest...\n");
  13109. GetLog = json_tokener_parse(payload);
  13110. if(!is_error(GetLog))
  13111. {
  13112. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13113. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13114. if(json_object_object_get(GetLog, "retries") != NULL)
  13115. {
  13116. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13117. }
  13118. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13119. {
  13120. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13121. }
  13122. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13123. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13124. {
  13125. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13126. }
  13127. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13128. {
  13129. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13130. }
  13131. }
  13132. json_object_put(GetLog);
  13133. /*
  13134. * TODO: Upload log process
  13135. */
  13136. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  13137. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  13138. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  13139. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  13140. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  13141. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  13142. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  13143. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  13144. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  13145. sendGetLogConfirmation(uuid);
  13146. return result;
  13147. }
  13148. int handleInstallCertificateRequest(char *uuid, char *payload)
  13149. {
  13150. mtrace();
  13151. int result = PASS;
  13152. json_object *InstallCertificate;
  13153. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13154. InstallCertificate = json_tokener_parse(payload);
  13155. if(!is_error(InstallCertificate))
  13156. {
  13157. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13158. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13159. /*
  13160. * TODO: Install certificate process
  13161. */
  13162. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  13163. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  13164. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  13165. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  13166. sendInstallCertificateConfirmation(uuid);
  13167. }
  13168. json_object_put(InstallCertificate);
  13169. return result;
  13170. }
  13171. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13172. {
  13173. mtrace();
  13174. int result = PASS;
  13175. json_object *SignedUpdateFirmware;
  13176. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13177. SignedUpdateFirmware = json_tokener_parse(payload);
  13178. if(!is_error(SignedUpdateFirmware))
  13179. {
  13180. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13181. {
  13182. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13183. }
  13184. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13185. {
  13186. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13187. }
  13188. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13189. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13190. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13191. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13192. {
  13193. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13194. }
  13195. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13196. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13197. }
  13198. json_object_put(SignedUpdateFirmware);
  13199. /*
  13200. * TODO: Upgrade firmware process
  13201. */
  13202. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13203. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  13204. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  13205. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  13206. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  13207. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  13208. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  13209. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  13210. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  13211. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  13212. sendInstallCertificateConfirmation(uuid);
  13213. return result;
  13214. }
  13215. int handleUnknownRequest(char *uuid, char *payload)
  13216. {
  13217. mtrace();
  13218. int result = PASS;
  13219. DEBUG_INFO("handleUnknownRequest...\n");
  13220. sendUnknownConfirmation(uuid);
  13221. result = PASS;
  13222. return result;
  13223. }
  13224. //==========================================
  13225. // Handle server response routine
  13226. //==========================================
  13227. void handleAuthorizeResponse(char *payload, int gun_index)
  13228. {
  13229. mtrace();
  13230. char expiryDatestr[30]={0};
  13231. char parentIdTagstr[20]={0};
  13232. char statusstr[20]={0};
  13233. int expiryDateISNULL=FALSE;
  13234. int parentIdTagISNULL=FALSE;
  13235. DEBUG_INFO("handleAuthorizeResponse...\n");
  13236. json_object *Authorize;
  13237. Authorize = json_tokener_parse(payload);
  13238. if(!is_error(Authorize))
  13239. {
  13240. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13241. {
  13242. // Required data
  13243. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13244. // Optional data
  13245. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13246. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13247. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13248. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13249. }
  13250. }
  13251. json_object_put(Authorize);
  13252. if(expiryDateISNULL == FALSE)
  13253. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13254. if(parentIdTagISNULL == FALSE)
  13255. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13256. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  13257. //Update idTag information to authorization cache if supproted
  13258. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13259. {
  13260. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13261. }
  13262. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  13263. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13264. authorizeRetryTimes = 0;
  13265. }
  13266. void handleBootNotificationResponse(char *payload, int gun_index)
  13267. {
  13268. mtrace();
  13269. char statusStr[12]={0};
  13270. char currentTimeStr[30]={0};
  13271. int intervalInt = 0;
  13272. DEBUG_INFO("handleBootNotificationResponse...\n");
  13273. json_object *BootNotification;
  13274. BootNotification = json_tokener_parse(payload);
  13275. if(!is_error(BootNotification))
  13276. {
  13277. // Required data
  13278. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13279. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13280. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13281. }
  13282. json_object_put(BootNotification);
  13283. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13284. BootNotificationInterval = intervalInt;
  13285. //write back to ShmOCPP16Data->BootNotification
  13286. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  13287. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13288. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  13289. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13290. {
  13291. if((intervalInt == 0) || (intervalInt >= 10))
  13292. {
  13293. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13294. HeartBeatWaitTime = intervalInt;
  13295. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13296. }
  13297. server_sign = TRUE;
  13298. server_pending =FALSE;
  13299. }
  13300. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13301. {
  13302. server_pending = TRUE;
  13303. }
  13304. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  13305. srand(time(NULL));
  13306. refreshStartTimer(&clientTime.Heartbeat);
  13307. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13308. SetOcppConnStatus(TRUE);
  13309. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  13310. }
  13311. void handleDataTransferResponse(char *payload, int gun_index)
  13312. {
  13313. json_object *DataTransfer = json_tokener_parse(payload);
  13314. if(!is_error(DataTransfer))
  13315. {
  13316. // Required data
  13317. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13318. // Optional data
  13319. if(json_object_object_get(DataTransfer, "data") != NULL)
  13320. {
  13321. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13322. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13323. if(!is_error(Data))
  13324. {
  13325. if(json_object_object_get(Data, "msgId") != NULL)
  13326. {
  13327. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13328. {
  13329. 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")));
  13330. }
  13331. }
  13332. }
  13333. json_object_put(Data);
  13334. }
  13335. }
  13336. json_object_put(DataTransfer);
  13337. }
  13338. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13339. {
  13340. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13341. //struct json_object *obj;
  13342. // obj = json_tokener_parse(payload);
  13343. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13344. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13345. //No fields are defined.
  13346. }
  13347. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13348. {
  13349. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13350. //struct json_object *obj;
  13351. // obj = json_tokener_parse(payload);
  13352. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13353. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13354. //No fields are defined.
  13355. }
  13356. void handleHeartbeatResponse(char *payload, int gun_index)
  13357. {
  13358. mtrace();
  13359. DEBUG_INFO("handleHeartbeatResponse...\n");
  13360. json_object *Heartbeat;
  13361. Heartbeat = json_tokener_parse(payload);
  13362. if(!is_error(Heartbeat))
  13363. {
  13364. // Required data
  13365. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13366. }
  13367. json_object_put(Heartbeat);
  13368. if(FirstHeartBeat == 0)
  13369. {
  13370. FirstHeartBeat = 1;
  13371. DEBUG_INFO("FirstHeartBeat \n");
  13372. }
  13373. HeartBeatWithNOResponse = 0;
  13374. refreshStartTimer(&clientTime.Heartbeat);
  13375. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  13376. }
  13377. void handleMeterValuesResponse(char *payload, int gun_index)
  13378. {
  13379. mtrace();
  13380. DEBUG_INFO("handleMeterValuesResponse...\n");
  13381. isQueueSendable = 1;
  13382. }
  13383. void handleStartTransactionResponse(char *payload, int gun_index)
  13384. {
  13385. mtrace();
  13386. //int transactionIdInt = 0;
  13387. FILE *outfile;
  13388. char data[100]={0};
  13389. DEBUG_INFO("handleStartTransactionResponse...\n");
  13390. json_object *StartTransaction;
  13391. StartTransaction = json_tokener_parse(payload);
  13392. if(!is_error(StartTransaction))
  13393. {
  13394. // Required data
  13395. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13396. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13397. // Optional data
  13398. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13399. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13400. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13401. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13402. }
  13403. json_object_put(StartTransaction);
  13404. isQueueSendable = 1;
  13405. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13406. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13407. //-----------Start : write to the Queue TransactionId file -----------------//
  13408. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  13409. {}
  13410. else
  13411. {
  13412. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  13413. if(log == NULL)
  13414. {
  13415. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13416. return ;
  13417. }
  13418. else
  13419. {
  13420. fclose(log);
  13421. }
  13422. }
  13423. // open file for writing
  13424. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13425. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  13426. {
  13427. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  13428. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13429. fputs(data, outfile);
  13430. fclose (outfile);
  13431. }
  13432. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13433. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13434. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13435. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  13436. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13437. }
  13438. void handleStatusNotificationResponse(char *payload, int gun_index)
  13439. {
  13440. mtrace();
  13441. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13442. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13443. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13444. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13445. }
  13446. void handleStopTransactionnResponse(char *payload, int gun_index)
  13447. {
  13448. mtrace();
  13449. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13450. json_object *StopTransaction;
  13451. StopTransaction = json_tokener_parse(payload);
  13452. if(!is_error(StopTransaction))
  13453. {
  13454. // Optional data
  13455. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13456. {
  13457. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13458. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13459. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13460. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13461. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13462. }
  13463. }
  13464. json_object_put(StopTransaction);
  13465. isQueueSendable = 1;
  13466. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13467. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13468. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13469. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13470. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13471. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13472. }
  13473. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13474. {
  13475. mtrace();
  13476. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13477. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  13478. }
  13479. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13480. {
  13481. mtrace();
  13482. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13483. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  13484. }
  13485. void handleSignCertificateResponse(char *payload, int gun_index)
  13486. {
  13487. mtrace();
  13488. DEBUG_INFO("handleSignCertificateResponse...\n");
  13489. json_object *SignCertificate;
  13490. SignCertificate = json_tokener_parse(payload);
  13491. if(!is_error(SignCertificate))
  13492. {
  13493. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13494. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  13495. }
  13496. json_object_put(SignCertificate);
  13497. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  13498. }
  13499. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13500. {
  13501. mtrace();
  13502. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13503. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13504. }
  13505. //==========================================
  13506. // Handle Error routine
  13507. //==========================================
  13508. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13509. {
  13510. mtrace();
  13511. #ifdef SystemLogMessage
  13512. DEBUG_INFO("errorCode: %s\n", errorCode);
  13513. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13514. DEBUG_INFO("errorDetails: %s\n", payload);
  13515. #endif
  13516. }
  13517. //===============================================
  13518. // Common routine
  13519. //===============================================
  13520. int initialConfigurationTable(void)
  13521. {
  13522. //clock_t start_t, end_t, total_t;
  13523. FILE *fp;
  13524. FILE *outfile;
  13525. char str[512]={0};
  13526. char sstr[256]={0};
  13527. int c = 0;
  13528. char *loc;
  13529. int confVersion = 12;
  13530. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13531. //start_t = clock();
  13532. //printf("Starting of the program, start_t = %ld\n", start_t);
  13533. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13534. // Check configuration file size is correct
  13535. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  13536. {
  13537. struct stat st;
  13538. stat("/Storage/OCPP/OCPPConfiguration", &st);
  13539. if(st.st_size < 3100)
  13540. {
  13541. system("rm -f /Storage/OCPP/OCPPConfiguration");
  13542. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13543. }
  13544. }
  13545. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  13546. {
  13547. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13548. if(outfile == NULL)
  13549. {
  13550. DEBUG_INFO("Error opening file\n");
  13551. return FALSE;
  13552. }
  13553. /*Core Profile*/
  13554. //AllowOfflineTxForUnknownId
  13555. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13558. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13559. //AuthorizationCacheEnabled
  13560. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13563. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13564. //AuthorizeRemoteTxRequests
  13565. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13568. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13569. //BlinkRepeat
  13570. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13573. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13574. //ClockAlignedDataInterval
  13575. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13578. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13579. //ConnectionTimeOut
  13580. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13583. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13584. //GetConfigurationMaxKeys
  13585. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13586. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13587. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13588. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13589. // HeartbeatInterval
  13590. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13592. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13593. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13594. // LightIntensity
  13595. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13598. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13599. // LocalAuthorizeOffline
  13600. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13603. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13604. // LocalPreAuthorize
  13605. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13607. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13608. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13609. // MaxEnergyOnInvalidId
  13610. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13613. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13614. // MeterValuesAlignedData
  13615. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13617. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13618. 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" );
  13619. else
  13620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13621. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13622. // MeterValuesAlignedDataMaxLength
  13623. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13625. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13627. else
  13628. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13629. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13630. // MeterValuesSampledData
  13631. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13633. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13634. 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" );
  13635. else
  13636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13637. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13638. // MeterValuesSampledDataMaxLength
  13639. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13641. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13643. else
  13644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13645. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13646. // MeterValueSampleInterval
  13647. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13650. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13651. // MinimumStatusDuration
  13652. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13655. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13656. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13657. // NumberOfConnectors
  13658. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13660. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13661. {
  13662. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13663. }
  13664. else
  13665. {
  13666. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13667. }
  13668. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13669. // ResetRetries
  13670. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13673. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13674. // ConnectorPhaseRotation
  13675. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13678. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13679. // ConnectorPhaseRotationMaxLength
  13680. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13683. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13684. // StopTransactionOnEVSideDisconnect
  13685. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13687. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13688. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13689. // StopTransactionOnInvalidId
  13690. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13693. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13694. // StopTxnAlignedData
  13695. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13698. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13699. // StopTxnAlignedDataMaxLength
  13700. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13703. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13704. // StopTxnSampledData
  13705. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13707. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13709. else
  13710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13711. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13712. // StopTxnSampledDataMaxLength
  13713. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13715. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13716. {
  13717. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13718. }
  13719. else
  13720. {
  13721. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13722. }
  13723. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13724. // SupportedFeatureProfiles
  13725. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13726. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13727. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13728. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13729. // SupportedFeatureProfilesMaxLength
  13730. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13732. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13733. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13734. // TransactionMessageAttempts
  13735. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13738. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13739. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13740. // TransactionMessageRetryInterval
  13741. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13742. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13744. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13745. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13746. // UnlockConnectorOnEVSideDisconnect
  13747. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13750. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13751. // WebSocketPingInterval
  13752. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13755. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13756. // QueueOffLineMeterValues
  13757. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13760. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13761. // AuthorizationKey
  13762. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  13765. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13766. // SecurityProfile
  13767. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13769. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  13770. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13771. // DefaultPrice
  13772. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13775. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13776. // CustomDisplayCostAndPrice
  13777. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13780. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13781. // CustomIdleFeeAfterStop
  13782. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13785. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13786. // TimeOffset
  13787. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  13790. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13791. // NextTimeOffsetTransitionDateTime
  13792. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  13795. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13796. // TimeOffsetNextTransition
  13797. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  13800. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13801. // SystemUptimeSec
  13802. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13806. // FreeVend
  13807. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "Free-FreeVend");
  13809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13810. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13811. // OcppServer
  13812. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13814. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13815. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13816. // MaintainServer
  13817. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13819. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13820. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13821. // StatusNotificationPeriodically
  13822. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13826. // StatusNotificationInterval
  13827. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13830. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13831. // Configuration Version
  13832. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13834. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13835. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13836. //* Local Auth List Management Profile*/
  13837. #if 0
  13838. //For OCTT Test Case
  13839. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13840. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13842. #endif
  13843. #if 1
  13844. //LocalAuthListEnabled
  13845. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13847. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13848. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13849. #endif
  13850. //LocalAuthListMaxLength
  13851. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  13854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13855. //SendLocalListMaxLength
  13856. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13859. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13860. //ReserveConnectorZeroSupported
  13861. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13864. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13865. //* Smart Charging Profile */
  13866. //ChargeProfileMaxStackLevel
  13867. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13870. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13871. // ChargingScheduleAllowedChargingRateUnit
  13872. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13875. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13876. // ChargingScheduleMaxPeriods
  13877. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13880. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13881. // ConnectorSwitch3to1PhaseSupported
  13882. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13884. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13885. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13886. // MaxChargingProfilesInstalled
  13887. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13889. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13890. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13891. fclose(outfile);
  13892. }
  13893. else
  13894. {
  13895. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  13896. char keystr[60]={0};
  13897. char readonlystr[10]={0};
  13898. char valuestr[256]={0};
  13899. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  13900. if(fp == NULL) {
  13901. DEBUG_INFO("Error opening file");
  13902. return FALSE;
  13903. }
  13904. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13905. {
  13906. //DEBUG_INFO("Get Configuration \n");
  13907. if(strlen(str) > 0)
  13908. {
  13909. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13910. //*************************key*********************************/
  13911. if(strstr(str, "key") != NULL)
  13912. {
  13913. loc = strstr(str, "key");
  13914. c = 0;
  13915. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13916. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13917. {
  13918. sstr[c] = loc[strlen("key")+3+c];
  13919. c++;
  13920. }
  13921. sstr[c] = '\0';
  13922. strcpy(keystr,sstr);
  13923. }
  13924. //*************************readonly*********************************/
  13925. if(strstr(str, "readonly") != NULL)
  13926. {
  13927. loc = strstr(str, "readonly");
  13928. c = 0;
  13929. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13930. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13931. {
  13932. sstr[c] = loc[strlen("readonly")+2+c];
  13933. c++;
  13934. }
  13935. sstr[c] = '\0';
  13936. strcpy(readonlystr,sstr);
  13937. }
  13938. //*************************value*********************************/
  13939. if(strstr(str, "value") != NULL)
  13940. {
  13941. loc = strstr(str, "value");
  13942. c = 0;
  13943. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13944. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13945. {
  13946. sstr[c] = loc[strlen("value")+3+c];
  13947. c++;
  13948. }
  13949. sstr[c] = '\0';
  13950. strcpy(valuestr,sstr);
  13951. }
  13952. // DEBUG_INFO("keystr=%s\n",keystr);
  13953. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13954. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13955. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13956. {
  13957. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13958. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13959. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13960. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13961. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13962. }
  13963. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13964. {
  13965. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13966. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13967. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13968. }
  13969. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13970. {
  13971. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13972. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13973. }
  13974. if(strcmp(keystr, "BlinkRepeat") == 0)
  13975. {
  13976. //Charger.BlinkRepeat = Integer.parseInt(value);
  13977. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13978. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13979. }
  13980. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13981. {
  13982. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13983. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13984. }
  13985. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13986. {
  13987. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13988. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13989. }
  13990. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13991. {
  13992. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13993. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13994. }
  13995. if(strcmp(keystr, "HeartbeatInterval") == 0)
  13996. {
  13997. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13998. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  13999. HeartBeatWaitTime = atoi(valuestr);
  14000. }
  14001. if(strcmp(keystr, "LightIntensity") == 0)
  14002. {
  14003. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14004. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14005. }
  14006. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14007. {
  14008. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14009. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14010. }
  14011. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14012. {
  14013. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14014. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14015. }
  14016. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14017. {
  14018. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14019. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14020. }
  14021. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14022. {
  14023. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14024. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14025. }
  14026. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14027. {
  14028. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14029. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14030. }
  14031. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14032. {
  14033. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14034. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14035. }
  14036. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14037. {
  14038. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14039. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14040. }
  14041. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14042. {
  14043. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14044. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14045. }
  14046. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14047. {
  14048. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14049. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14050. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14051. }
  14052. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14053. {
  14054. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14055. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14056. }
  14057. if(strcmp(keystr, "ResetRetries") == 0)
  14058. {
  14059. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14060. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14061. }
  14062. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14063. {
  14064. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14065. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14066. }
  14067. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14068. {
  14069. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14070. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14071. }
  14072. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14073. {
  14074. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14075. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14076. }
  14077. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14078. {
  14079. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14080. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14081. }
  14082. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14083. {
  14084. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14085. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14086. }
  14087. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14088. {
  14089. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14090. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14091. }
  14092. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14093. {
  14094. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14095. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14096. }
  14097. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14098. {
  14099. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14100. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14101. }
  14102. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14103. {
  14104. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14105. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14106. }
  14107. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14108. {
  14109. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14110. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14111. }
  14112. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14113. {
  14114. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14115. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14116. TransactionMessageAttemptsValue = atoi(valuestr);
  14117. }
  14118. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14119. {
  14120. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14121. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14122. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14123. }
  14124. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14125. {
  14126. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14127. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14128. }
  14129. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14130. {
  14131. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14132. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14133. }
  14134. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14135. {
  14136. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14137. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14138. }
  14139. if(strcmp(keystr, "AuthorizationKey") == 0)
  14140. {
  14141. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14142. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14143. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14144. }
  14145. if(strcmp(keystr, "SecurityProfile") == 0)
  14146. {
  14147. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14148. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14149. }
  14150. if(strcmp(keystr, "DefaultPrice") == 0)
  14151. {
  14152. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14153. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14154. }
  14155. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14156. {
  14157. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14158. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14159. }
  14160. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14161. {
  14162. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14163. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14164. }
  14165. if(strcmp(keystr, "TimeOffset") == 0)
  14166. {
  14167. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14168. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  14169. }
  14170. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  14171. {
  14172. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14173. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  14174. }
  14175. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  14176. {
  14177. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14178. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  14179. }
  14180. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14181. {
  14182. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14183. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  14184. }
  14185. if(strcmp(keystr, "FreeVend") == 0)
  14186. {
  14187. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14188. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14189. }
  14190. if(strcmp(keystr, "OcppServer") == 0)
  14191. {
  14192. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14193. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14194. }
  14195. if(strcmp(keystr, "MaintainServer") == 0)
  14196. {
  14197. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14198. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14199. }
  14200. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14201. {
  14202. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14204. }
  14205. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14206. {
  14207. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14208. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14209. }
  14210. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14211. {
  14212. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14213. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14214. }
  14215. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14216. {
  14217. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14218. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14219. }
  14220. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14221. {
  14222. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14223. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14224. }
  14225. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14226. {
  14227. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14228. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14229. }
  14230. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14231. {
  14232. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14233. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14234. }
  14235. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14236. {
  14237. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14238. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14239. }
  14240. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14241. {
  14242. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14243. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14244. }
  14245. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14246. {
  14247. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14248. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14249. }
  14250. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14251. {
  14252. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14253. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14254. }
  14255. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14256. {
  14257. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14258. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14259. }
  14260. }
  14261. }
  14262. fclose(fp);
  14263. }
  14264. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14265. {
  14266. return PASS;
  14267. }
  14268. else
  14269. {
  14270. return FAIL;
  14271. }
  14272. }
  14273. void StoreConfigurationTable(void)
  14274. {
  14275. FILE *outfile;
  14276. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14277. if(outfile == NULL)
  14278. {
  14279. DEBUG_INFO("Error opening file");
  14280. return ;
  14281. }
  14282. /*Core Profile*/
  14283. //AllowOfflineTxForUnknownId
  14284. /*
  14285. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14286. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14289. */
  14290. //DEBUG_INFO("data=%s\n",data);
  14291. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14292. //AuthorizationCacheEnabled
  14293. /*
  14294. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14297. */
  14298. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14299. //AuthorizeRemoteTxRequests
  14300. /*
  14301. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14303. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14304. */
  14305. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14306. //BlinkRepeat
  14307. /*
  14308. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14311. */
  14312. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14313. //ClockAlignedDataInterval
  14314. /*
  14315. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14318. */
  14319. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14320. //ConnectionTimeOut
  14321. /*
  14322. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14325. */
  14326. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14327. //GetConfigurationMaxKeys
  14328. /*
  14329. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14332. */
  14333. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14334. // HeartbeatInterval
  14335. /*
  14336. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14337. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14339. */
  14340. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14341. // LightIntensity
  14342. /*
  14343. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14346. */
  14347. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14348. // LocalAuthorizeOffline
  14349. /*
  14350. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14351. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14353. */
  14354. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14355. // LocalPreAuthorize
  14356. /*
  14357. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14360. */
  14361. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14362. // MaxEnergyOnInvalidId
  14363. /*
  14364. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14367. */
  14368. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14370. // MeterValuesAlignedData
  14371. /*
  14372. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14374. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14375. */
  14376. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14377. // MeterValuesAlignedDataMaxLength
  14378. /*
  14379. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14382. */
  14383. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14384. // MeterValuesSampledData
  14385. /*
  14386. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14388. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14389. */
  14390. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14391. // MeterValuesSampledDataMaxLength
  14392. /*
  14393. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14396. */
  14397. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14398. // MeterValueSampleInterval
  14399. /*
  14400. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14403. */
  14404. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14405. // MinimumStatusDuration
  14406. /*
  14407. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14409. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14410. */
  14411. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14412. // NumberOfConnectors
  14413. /*
  14414. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14416. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14417. {
  14418. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14419. }
  14420. else
  14421. {
  14422. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14423. }
  14424. */
  14425. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14426. // ResetRetries
  14427. /*
  14428. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14431. */
  14432. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14433. // ConnectorPhaseRotation
  14434. /*
  14435. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14436. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14438. */
  14439. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14440. // ConnectorPhaseRotationMaxLength
  14441. /*
  14442. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14445. */
  14446. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14447. // StopTransactionOnEVSideDisconnect
  14448. /*
  14449. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14450. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14451. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14452. */
  14453. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14454. // StopTransactionOnInvalidId
  14455. /*
  14456. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14457. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14459. */
  14460. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14461. // StopTxnAlignedData
  14462. /*
  14463. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14464. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14465. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14466. */
  14467. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14468. // StopTxnAlignedDataMaxLength
  14469. /*
  14470. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14471. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14473. */
  14474. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14475. // StopTxnSampledData
  14476. /*
  14477. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14479. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14480. */
  14481. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14482. // StopTxnSampledDataMaxLength
  14483. /*
  14484. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14485. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14486. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14487. */
  14488. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14489. // SupportedFeatureProfiles
  14490. /*
  14491. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14492. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14493. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14494. */
  14495. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14496. // SupportedFeatureProfilesMaxLength
  14497. /*
  14498. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14499. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14500. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14501. */
  14502. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14503. // TransactionMessageAttempts
  14504. /*
  14505. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14506. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14508. */
  14509. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14510. // TransactionMessageRetryInterval
  14511. /*
  14512. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14513. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14514. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14515. */
  14516. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14517. // UnlockConnectorOnEVSideDisconnect
  14518. /*
  14519. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14520. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14521. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14522. */
  14523. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14524. // WebSocketPingInterval
  14525. /*
  14526. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14529. */
  14530. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14531. // QueueOffLineMeterValues
  14532. /*
  14533. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14536. */
  14537. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14538. // AuthorizationKey
  14539. /*
  14540. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14543. */
  14544. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14545. // SecurityProfile
  14546. /*
  14547. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14550. */
  14551. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14552. // DefaultPrice
  14553. /*
  14554. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14557. */
  14558. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14559. // CustomDisplayCostAndPrice
  14560. /*
  14561. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14564. */
  14565. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14566. // CustomIdleFeeAfterStop
  14567. /*
  14568. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14571. */
  14572. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14573. // TimeOffset
  14574. /*
  14575. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  14578. */
  14579. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14580. // NextTimeOffsetTransitionDateTime
  14581. /*
  14582. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  14585. */
  14586. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14587. // TimeOffsetNextTransition
  14588. /*
  14589. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  14592. */
  14593. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14594. // SystemUptimeSec
  14595. /*
  14596. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14599. */
  14600. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14601. // FreeVend
  14602. /*
  14603. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14606. */
  14607. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14608. // OcppServer
  14609. /*
  14610. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14613. */
  14614. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14615. // MaintainServer
  14616. /*
  14617. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14620. */
  14621. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14622. // StatusNotificationPeriodically
  14623. /*
  14624. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14627. */
  14628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14629. // StatusNotificationInterval
  14630. /*
  14631. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14634. */
  14635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14636. // ConfigurationVersion
  14637. /*
  14638. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14641. */
  14642. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14643. //* Local Auth List Management Profile*/
  14644. //LocalAuthListEnabled
  14645. /*
  14646. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14649. */
  14650. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14651. //LocalAuthListMaxLength
  14652. /*
  14653. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14656. */
  14657. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14658. //SendLocalListMaxLength
  14659. /*
  14660. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14663. */
  14664. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14665. //ReserveConnectorZeroSupported
  14666. /*
  14667. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14670. */
  14671. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14672. //* Smart Charging Profile */
  14673. //ChargeProfileMaxStackLevel
  14674. /*
  14675. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14678. */
  14679. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14680. // ChargingScheduleAllowedChargingRateUnit
  14681. /*
  14682. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14685. */
  14686. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14687. // ChargingScheduleMaxPeriods
  14688. /*
  14689. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14692. */
  14693. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14694. // ConnectorSwitch3to1PhaseSupported
  14695. /*
  14696. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14699. */
  14700. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14701. // MaxChargingProfilesInstalled
  14702. /*
  14703. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14705. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14706. */
  14707. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14708. fclose(outfile);
  14709. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14710. }
  14711. void getKeyValue(char *keyReq)
  14712. {
  14713. int isEmpty = FALSE;
  14714. int isKnowKey = FALSE;
  14715. DEBUG_INFO("keyReq = %s\n", keyReq);
  14716. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14717. isEmpty = TRUE;
  14718. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14719. {
  14720. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14722. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14723. {
  14724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14725. }
  14726. else
  14727. {
  14728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14729. }
  14730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14731. isKnowKey = TRUE;
  14732. }
  14733. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14734. {
  14735. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14737. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14738. {
  14739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14740. }
  14741. else
  14742. {
  14743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14744. }
  14745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14746. isKnowKey = TRUE;
  14747. }
  14748. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14749. {
  14750. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14752. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14753. {
  14754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14755. }
  14756. else
  14757. {
  14758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14759. }
  14760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14761. isKnowKey = TRUE;
  14762. }
  14763. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14764. {
  14765. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14767. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14768. {
  14769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14770. }
  14771. else
  14772. {
  14773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14774. }
  14775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14776. isKnowKey = TRUE;
  14777. }
  14778. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14779. {
  14780. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14782. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14783. {
  14784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14785. }
  14786. else
  14787. {
  14788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14789. }
  14790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14791. isKnowKey = TRUE;
  14792. }
  14793. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14794. {
  14795. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14797. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14798. {
  14799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14800. }
  14801. else
  14802. {
  14803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14804. }
  14805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14806. isKnowKey = TRUE;
  14807. }
  14808. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14809. {
  14810. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14812. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14813. {
  14814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14815. }
  14816. else
  14817. {
  14818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14819. }
  14820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14821. isKnowKey = TRUE;
  14822. }
  14823. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14824. {
  14825. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14827. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14828. {
  14829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14830. }
  14831. else
  14832. {
  14833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14834. }
  14835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14836. isKnowKey = TRUE;
  14837. }
  14838. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14839. {
  14840. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14842. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14843. {
  14844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14845. }
  14846. else
  14847. {
  14848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14849. }
  14850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14851. isKnowKey = TRUE;
  14852. }
  14853. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14854. {
  14855. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14856. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14857. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14858. {
  14859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14860. }
  14861. else
  14862. {
  14863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14864. }
  14865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14866. isKnowKey = TRUE;
  14867. }
  14868. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14869. {
  14870. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14871. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14872. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14873. {
  14874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14875. }
  14876. else
  14877. {
  14878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14879. }
  14880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14881. isKnowKey = TRUE;
  14882. }
  14883. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14884. {
  14885. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14886. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14887. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14888. {
  14889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14890. }
  14891. else
  14892. {
  14893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14894. }
  14895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14896. isKnowKey = TRUE;
  14897. }
  14898. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14899. {
  14900. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14901. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14902. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14903. {
  14904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14905. }
  14906. else
  14907. {
  14908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14909. }
  14910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14911. isKnowKey = TRUE;
  14912. }
  14913. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14914. {
  14915. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14916. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14917. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14918. {
  14919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14920. }
  14921. else
  14922. {
  14923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14924. }
  14925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14926. isKnowKey = TRUE;
  14927. }
  14928. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14929. {
  14930. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14932. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14933. {
  14934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14935. }
  14936. else
  14937. {
  14938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14939. }
  14940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14941. isKnowKey = TRUE;
  14942. }
  14943. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14944. {
  14945. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14947. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14948. {
  14949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14950. }
  14951. else
  14952. {
  14953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14954. }
  14955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14956. isKnowKey = TRUE;
  14957. }
  14958. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14959. {
  14960. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14962. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14963. {
  14964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14965. }
  14966. else
  14967. {
  14968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14969. }
  14970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14971. isKnowKey = TRUE;
  14972. }
  14973. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14974. {
  14975. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14977. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14978. {
  14979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14980. }
  14981. else
  14982. {
  14983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14984. }
  14985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  14986. isKnowKey = TRUE;
  14987. }
  14988. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14989. {
  14990. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14992. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14993. {
  14994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14995. }
  14996. else
  14997. {
  14998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14999. }
  15000. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15002. isKnowKey = TRUE;
  15003. }
  15004. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15005. {
  15006. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15008. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15009. {
  15010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15011. }
  15012. else
  15013. {
  15014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15015. }
  15016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15017. isKnowKey = TRUE;
  15018. }
  15019. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15020. {
  15021. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15022. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15023. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15024. {
  15025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15026. }
  15027. else
  15028. {
  15029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15030. }
  15031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15032. isKnowKey = TRUE;
  15033. }
  15034. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15035. {
  15036. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15037. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15038. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15039. {
  15040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15041. }
  15042. else
  15043. {
  15044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15045. }
  15046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15047. isKnowKey = TRUE;
  15048. }
  15049. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15050. {
  15051. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15053. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15054. {
  15055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15056. }
  15057. else
  15058. {
  15059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15060. }
  15061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15062. isKnowKey = TRUE;
  15063. }
  15064. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15065. {
  15066. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15067. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15068. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15069. {
  15070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15071. }
  15072. else
  15073. {
  15074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15075. }
  15076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15077. isKnowKey = TRUE;
  15078. }
  15079. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15080. {
  15081. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15082. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15083. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15084. {
  15085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15086. }
  15087. else
  15088. {
  15089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15090. }
  15091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15092. isKnowKey = TRUE;
  15093. }
  15094. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15095. {
  15096. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15097. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15098. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15099. {
  15100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15101. }
  15102. else
  15103. {
  15104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15105. }
  15106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15107. isKnowKey = TRUE;
  15108. }
  15109. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15110. {
  15111. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15112. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15113. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15114. {
  15115. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15116. }
  15117. else
  15118. {
  15119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15120. }
  15121. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15122. isKnowKey = TRUE;
  15123. }
  15124. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15125. {
  15126. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15127. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15128. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15129. {
  15130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15131. }
  15132. else
  15133. {
  15134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15135. }
  15136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15137. isKnowKey = TRUE;
  15138. }
  15139. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15140. {
  15141. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15143. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15144. {
  15145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15146. }
  15147. else
  15148. {
  15149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15150. }
  15151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15152. isKnowKey = TRUE;
  15153. }
  15154. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15155. {
  15156. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15158. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15159. {
  15160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15161. }
  15162. else
  15163. {
  15164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15165. }
  15166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15167. isKnowKey = TRUE;
  15168. }
  15169. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15170. {
  15171. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15173. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15174. {
  15175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15176. }
  15177. else
  15178. {
  15179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15180. }
  15181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15182. isKnowKey = TRUE;
  15183. }
  15184. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15185. {
  15186. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15188. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15189. {
  15190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15191. }
  15192. else
  15193. {
  15194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15195. }
  15196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15197. isKnowKey = TRUE;
  15198. }
  15199. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15200. {
  15201. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15203. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15204. {
  15205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15206. }
  15207. else
  15208. {
  15209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15210. }
  15211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15212. isKnowKey = TRUE;
  15213. }
  15214. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15215. {
  15216. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15218. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15219. {
  15220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15221. }
  15222. else
  15223. {
  15224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15225. }
  15226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15227. isKnowKey = TRUE;
  15228. }
  15229. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15230. {
  15231. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15233. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15234. {
  15235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15236. }
  15237. else
  15238. {
  15239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15240. }
  15241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15242. isKnowKey = TRUE;
  15243. }
  15244. /*
  15245. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15246. {
  15247. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15249. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15250. {
  15251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15252. }
  15253. else
  15254. {
  15255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15256. }
  15257. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15258. isKnowKey = TRUE;
  15259. }*/
  15260. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15261. {
  15262. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15264. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15265. {
  15266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15267. }
  15268. else
  15269. {
  15270. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15271. }
  15272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15273. isKnowKey = TRUE;
  15274. }
  15275. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15276. {
  15277. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15279. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15280. {
  15281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15282. }
  15283. else
  15284. {
  15285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15286. }
  15287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15288. isKnowKey = TRUE;
  15289. }
  15290. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15291. {
  15292. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15294. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15295. {
  15296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15297. }
  15298. else
  15299. {
  15300. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15301. }
  15302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15303. isKnowKey = TRUE;
  15304. }
  15305. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15306. {
  15307. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15309. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15310. {
  15311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15312. }
  15313. else
  15314. {
  15315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15316. }
  15317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15318. isKnowKey = TRUE;
  15319. }
  15320. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  15321. {
  15322. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  15323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  15324. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15325. {
  15326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  15327. }
  15328. else
  15329. {
  15330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  15331. }
  15332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  15333. isKnowKey = TRUE;
  15334. }
  15335. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  15336. {
  15337. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  15338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  15339. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15340. {
  15341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  15342. }
  15343. else
  15344. {
  15345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  15346. }
  15347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  15348. isKnowKey = TRUE;
  15349. }
  15350. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  15351. {
  15352. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  15353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  15354. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15355. {
  15356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  15357. }
  15358. else
  15359. {
  15360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  15361. }
  15362. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  15363. isKnowKey = TRUE;
  15364. }
  15365. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15366. {
  15367. struct sysinfo s_info;
  15368. int error = sysinfo(&s_info);
  15369. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15371. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15372. {
  15373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15374. }
  15375. else
  15376. {
  15377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15378. }
  15379. if(error != 0)
  15380. {
  15381. DEBUG_WARN("System uptime get error: %d\n", error);
  15382. }
  15383. else
  15384. {
  15385. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15386. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15387. }
  15388. isKnowKey = TRUE;
  15389. }
  15390. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15391. {
  15392. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15394. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15395. {
  15396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15397. }
  15398. else
  15399. {
  15400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15401. }
  15402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  15403. isKnowKey = TRUE;
  15404. }
  15405. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15406. {
  15407. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15409. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15410. {
  15411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15412. }
  15413. else
  15414. {
  15415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15416. }
  15417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15418. isKnowKey = TRUE;
  15419. }
  15420. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15421. {
  15422. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15424. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15425. {
  15426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15427. }
  15428. else
  15429. {
  15430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15431. }
  15432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15433. isKnowKey = TRUE;
  15434. }
  15435. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15436. {
  15437. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15439. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15440. {
  15441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15442. }
  15443. else
  15444. {
  15445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15446. }
  15447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15448. isKnowKey = TRUE;
  15449. }
  15450. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15451. {
  15452. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15454. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15455. {
  15456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15457. }
  15458. else
  15459. {
  15460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15461. }
  15462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15463. isKnowKey = TRUE;
  15464. }
  15465. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15466. {
  15467. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15469. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15470. {
  15471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15472. }
  15473. else
  15474. {
  15475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15476. }
  15477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15478. isKnowKey = TRUE;
  15479. }
  15480. #if 1
  15481. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15482. {
  15483. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15485. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15486. {
  15487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15488. }
  15489. else
  15490. {
  15491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15492. }
  15493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15494. isKnowKey = TRUE;
  15495. }
  15496. #endif
  15497. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15498. {
  15499. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15501. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15502. {
  15503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15504. }
  15505. else
  15506. {
  15507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15508. }
  15509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15510. isKnowKey = TRUE;
  15511. }
  15512. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15513. {
  15514. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15516. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15517. {
  15518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15519. }
  15520. else
  15521. {
  15522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15523. }
  15524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15525. isKnowKey = TRUE;
  15526. }
  15527. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15528. {
  15529. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15531. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15532. {
  15533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15534. }
  15535. else
  15536. {
  15537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15538. }
  15539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15540. isKnowKey = TRUE;
  15541. }
  15542. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15543. {
  15544. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15546. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15547. {
  15548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15549. }
  15550. else
  15551. {
  15552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15553. }
  15554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15555. isKnowKey = TRUE;
  15556. }
  15557. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15558. {
  15559. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15561. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15562. {
  15563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15564. }
  15565. else
  15566. {
  15567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15568. }
  15569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15570. isKnowKey = TRUE;
  15571. }
  15572. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15573. {
  15574. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15576. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15577. {
  15578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15579. }
  15580. else
  15581. {
  15582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15583. }
  15584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15585. isKnowKey = TRUE;
  15586. }
  15587. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15588. {
  15589. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15591. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15592. {
  15593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15594. }
  15595. else
  15596. {
  15597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15598. }
  15599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15600. isKnowKey = TRUE;
  15601. }
  15602. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15603. {
  15604. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15606. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15607. {
  15608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15609. }
  15610. else
  15611. {
  15612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15613. }
  15614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15615. isKnowKey = TRUE;
  15616. }
  15617. //=========================================================
  15618. if(!isEmpty && !isKnowKey)
  15619. {
  15620. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15621. strcpy(unknownkey[UnknownKeynum], keyReq);
  15622. UnknownKeynum = UnknownKeynum + 1;
  15623. }
  15624. }
  15625. void processUnkownKey(void)
  15626. {
  15627. DEBUG_INFO("processUnkownKey...\n");
  15628. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15629. for(int index=0; index < UnknownKeynum; index++)
  15630. {
  15631. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15632. {
  15633. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15634. }
  15635. }
  15636. }
  15637. int setKeyValue(char *key, char *value)
  15638. {
  15639. int isSuccess = NotSupported;
  15640. int check_ascii=0;
  15641. char str[501]={0};
  15642. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15643. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15644. {
  15645. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15646. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15647. {
  15648. strcpy(str, (const char*)value);
  15649. for(int i = 0; str[i]; i++){
  15650. str[i] = tolower(str[i]);
  15651. }
  15652. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15653. isSuccess = ConfigurationStatus_Accepted;
  15654. }
  15655. else
  15656. {
  15657. isSuccess = ConfigurationStatus_Rejected;
  15658. }
  15659. }
  15660. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15661. {
  15662. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15663. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15664. {
  15665. strcpy(str, (const char*)value);
  15666. for(int i = 0; str[i]; i++){
  15667. str[i] = tolower(str[i]);
  15668. }
  15669. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15670. isSuccess = ConfigurationStatus_Accepted;
  15671. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  15672. }
  15673. else
  15674. {
  15675. isSuccess = ConfigurationStatus_Rejected;
  15676. }
  15677. }
  15678. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15679. {
  15680. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15681. {
  15682. strcpy(str, (const char*)value);
  15683. for(int i = 0; str[i]; i++)
  15684. {
  15685. str[i] = tolower(str[i]);
  15686. }
  15687. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15688. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15689. isSuccess = ConfigurationStatus_Accepted;
  15690. }
  15691. else
  15692. {
  15693. isSuccess = ConfigurationStatus_Rejected;
  15694. }
  15695. }
  15696. if(strcmp(key, "BlinkRepeat") == 0)
  15697. {
  15698. //Charger.BlinkRepeat = Integer.parseInt(value);
  15699. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15700. {
  15701. check_ascii = value[0];
  15702. if( (check_ascii < 48) || (check_ascii > 57) )
  15703. {
  15704. isSuccess = ConfigurationStatus_Rejected;
  15705. }
  15706. else
  15707. {
  15708. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15709. isSuccess = ConfigurationStatus_Accepted;
  15710. }
  15711. }
  15712. else
  15713. {
  15714. isSuccess = ConfigurationStatus_Rejected;
  15715. }
  15716. }
  15717. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15718. {
  15719. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15720. {
  15721. check_ascii = value[0];
  15722. if( (check_ascii < 48) || (check_ascii > 57) )
  15723. {
  15724. isSuccess = ConfigurationStatus_Rejected;
  15725. }
  15726. else
  15727. {
  15728. if((atoi(value) == 0) || (atoi(value) >= 5))
  15729. {
  15730. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15731. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15732. isSuccess = ConfigurationStatus_Accepted;
  15733. }
  15734. else
  15735. isSuccess = ConfigurationStatus_Rejected;
  15736. }
  15737. }
  15738. else
  15739. {
  15740. isSuccess = ConfigurationStatus_Rejected;
  15741. }
  15742. }
  15743. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15744. {
  15745. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15746. {
  15747. check_ascii = value[0];
  15748. if( (check_ascii < 48) || (check_ascii > 57) )
  15749. {
  15750. isSuccess = ConfigurationStatus_Rejected;
  15751. }
  15752. else
  15753. {
  15754. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15755. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15756. isSuccess = ConfigurationStatus_Accepted;
  15757. }
  15758. }
  15759. else
  15760. {
  15761. isSuccess = ConfigurationStatus_Rejected;
  15762. }
  15763. }
  15764. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15765. {
  15766. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15767. {
  15768. check_ascii = value[0];
  15769. if( (check_ascii < 48) || (check_ascii > 57) )
  15770. {
  15771. isSuccess = ConfigurationStatus_Rejected;
  15772. }
  15773. else
  15774. {
  15775. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15776. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15777. isSuccess = ConfigurationStatus_Accepted;
  15778. }
  15779. }
  15780. else
  15781. {
  15782. isSuccess = ConfigurationStatus_Rejected;
  15783. }
  15784. }
  15785. if(strcmp(key, "HeartbeatInterval") == 0)
  15786. {
  15787. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15788. {
  15789. check_ascii = value[0];
  15790. if( (check_ascii < 48) || (check_ascii > 57) )
  15791. {
  15792. isSuccess = ConfigurationStatus_Rejected;
  15793. }
  15794. else
  15795. {
  15796. if((atoi(value) == 0) || (atoi(value) >= 10))
  15797. {
  15798. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15799. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15800. HeartBeatWaitTime = atoi(value);
  15801. isSuccess = ConfigurationStatus_Accepted;
  15802. }
  15803. else
  15804. {
  15805. isSuccess = ConfigurationStatus_Rejected;
  15806. }
  15807. }
  15808. }
  15809. else
  15810. {
  15811. isSuccess = ConfigurationStatus_Rejected;
  15812. }
  15813. }
  15814. if(strcmp(key, "LightIntensity") == 0)
  15815. {
  15816. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15817. {
  15818. check_ascii = value[0];
  15819. if( (check_ascii < 48) || (check_ascii > 57) )
  15820. {
  15821. isSuccess = ConfigurationStatus_Rejected;
  15822. }
  15823. else
  15824. {
  15825. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15826. isSuccess = ConfigurationStatus_Accepted;
  15827. }
  15828. }
  15829. else
  15830. {
  15831. isSuccess = ConfigurationStatus_Rejected;
  15832. }
  15833. }
  15834. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15835. {
  15836. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15837. {
  15838. strcpy(str, (const char*)value);
  15839. for(int i = 0; str[i]; i++)
  15840. {
  15841. str[i] = tolower(str[i]);
  15842. }
  15843. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15844. isSuccess = ConfigurationStatus_Accepted;
  15845. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15846. }
  15847. else
  15848. {
  15849. isSuccess = ConfigurationStatus_Rejected;
  15850. }
  15851. }
  15852. if(strcmp(key, "LocalPreAuthorize") == 0)
  15853. {
  15854. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15855. {
  15856. strcpy(str, (const char*)value);
  15857. for(int i = 0; str[i]; i++)
  15858. {
  15859. str[i] = tolower(str[i]);
  15860. }
  15861. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15862. isSuccess = ConfigurationStatus_Accepted;
  15863. }
  15864. else
  15865. {
  15866. isSuccess = ConfigurationStatus_Rejected;
  15867. }
  15868. }
  15869. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15870. {
  15871. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15872. {
  15873. check_ascii = value[0];
  15874. if( (check_ascii < 48) || (check_ascii > 57) )
  15875. {
  15876. isSuccess = ConfigurationStatus_Rejected;
  15877. }
  15878. else
  15879. {
  15880. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15881. isSuccess = ConfigurationStatus_Accepted;
  15882. }
  15883. }
  15884. else
  15885. {
  15886. isSuccess = ConfigurationStatus_Rejected;
  15887. }
  15888. }
  15889. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15890. {
  15891. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15892. {
  15893. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15894. isSuccess = ConfigurationStatus_Accepted;
  15895. }
  15896. else
  15897. {
  15898. isSuccess = ConfigurationStatus_Rejected;
  15899. }
  15900. }
  15901. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15902. {
  15903. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15904. {
  15905. check_ascii = value[0];
  15906. if( (check_ascii < 48) || (check_ascii > 57) )
  15907. {
  15908. isSuccess = ConfigurationStatus_Rejected;
  15909. }
  15910. else
  15911. {
  15912. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15913. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15914. isSuccess = ConfigurationStatus_Accepted;
  15915. }
  15916. }
  15917. else
  15918. {
  15919. isSuccess = ConfigurationStatus_Rejected;
  15920. }
  15921. }
  15922. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15923. {
  15924. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15925. {
  15926. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15927. isSuccess = ConfigurationStatus_Accepted;
  15928. }
  15929. else
  15930. {
  15931. isSuccess = ConfigurationStatus_Rejected;
  15932. }
  15933. }
  15934. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15935. {
  15936. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15937. {
  15938. check_ascii = value[0];
  15939. if( (check_ascii < 48) || (check_ascii > 57) )
  15940. {
  15941. isSuccess = ConfigurationStatus_Rejected;
  15942. }
  15943. else
  15944. {
  15945. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15946. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15947. isSuccess = ConfigurationStatus_Accepted;
  15948. }
  15949. }
  15950. else
  15951. {
  15952. isSuccess = ConfigurationStatus_Rejected;
  15953. }
  15954. }
  15955. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15956. {
  15957. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15958. {
  15959. check_ascii = value[0];
  15960. if( (check_ascii < 48) || (check_ascii > 57) )
  15961. {
  15962. isSuccess = ConfigurationStatus_Rejected;
  15963. }
  15964. else
  15965. {
  15966. if((atoi(value) == 0) || (atoi(value) >= 3))
  15967. {
  15968. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15969. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15970. isSuccess = ConfigurationStatus_Accepted;
  15971. }
  15972. else
  15973. {
  15974. isSuccess = ConfigurationStatus_Rejected;
  15975. }
  15976. }
  15977. }
  15978. else
  15979. {
  15980. isSuccess = ConfigurationStatus_Rejected;
  15981. }
  15982. }
  15983. if(strcmp(key, "MinimumStatusDuration") == 0)
  15984. {
  15985. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15986. {
  15987. check_ascii = value[0];
  15988. if( (check_ascii < 48) || (check_ascii > 57) )
  15989. {
  15990. isSuccess = ConfigurationStatus_Rejected;
  15991. }
  15992. else
  15993. {
  15994. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15995. {
  15996. isSuccess = ConfigurationStatus_Rejected;
  15997. }
  15998. else
  15999. {
  16000. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16001. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16002. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16003. isSuccess = ConfigurationStatus_Accepted;
  16004. }
  16005. }
  16006. }
  16007. else
  16008. {
  16009. isSuccess = ConfigurationStatus_Rejected;
  16010. }
  16011. }
  16012. if(strcmp(key, "NumberOfConnectors") == 0)
  16013. {
  16014. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16015. {
  16016. check_ascii = value[0];
  16017. if( (check_ascii < 48) || (check_ascii > 57) )
  16018. {
  16019. isSuccess = ConfigurationStatus_Rejected;
  16020. }
  16021. else
  16022. {
  16023. //Charger.ResetRetries = Integer.parseInt(value);
  16024. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16025. isSuccess = ConfigurationStatus_Accepted;
  16026. }
  16027. }
  16028. else
  16029. {
  16030. isSuccess = ConfigurationStatus_Rejected;
  16031. }
  16032. }
  16033. if(strcmp(key, "ResetRetries") == 0)
  16034. {
  16035. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16036. {
  16037. check_ascii = value[0];
  16038. if( (check_ascii < 48) || (check_ascii > 57) )
  16039. {
  16040. isSuccess = ConfigurationStatus_Rejected;
  16041. }
  16042. else
  16043. {
  16044. //Charger.ResetRetries = Integer.parseInt(value);
  16045. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16046. isSuccess = ConfigurationStatus_Accepted;
  16047. }
  16048. }
  16049. else
  16050. {
  16051. isSuccess = ConfigurationStatus_Rejected;
  16052. }
  16053. }
  16054. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16055. {
  16056. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16057. {
  16058. strcpy(str, (const char*)value);
  16059. for(int i = 0; str[i]; i++)
  16060. {
  16061. str[i] = tolower(str[i]);
  16062. }
  16063. if(strcmp(str, "notapplicable")== 0)
  16064. {
  16065. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16066. isSuccess = ConfigurationStatus_Accepted;
  16067. }
  16068. else if(strcmp(str, "unknown")== 0)
  16069. {
  16070. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16071. isSuccess = ConfigurationStatus_Accepted;
  16072. }
  16073. else if(strcmp(str, "rst")== 0)
  16074. {
  16075. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16076. isSuccess = ConfigurationStatus_Accepted;
  16077. }
  16078. else if(strcmp(str, "rts")== 0)
  16079. {
  16080. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16081. isSuccess = ConfigurationStatus_Accepted;
  16082. }
  16083. else if(strcmp(str, "srt")== 0)
  16084. {
  16085. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16086. isSuccess = ConfigurationStatus_Accepted;
  16087. }
  16088. else if(strcmp(str, "str")== 0)
  16089. {
  16090. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16091. isSuccess = ConfigurationStatus_Accepted;
  16092. }
  16093. else if(strcmp(str, "trs")== 0)
  16094. {
  16095. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16096. isSuccess = ConfigurationStatus_Accepted;
  16097. }
  16098. else if(strcmp(str, "tsr")== 0)
  16099. {
  16100. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16101. isSuccess = ConfigurationStatus_Accepted;
  16102. }
  16103. else
  16104. {
  16105. isSuccess = ConfigurationStatus_Rejected;
  16106. }
  16107. }
  16108. else
  16109. {
  16110. isSuccess = ConfigurationStatus_Rejected;
  16111. }
  16112. }
  16113. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16114. {
  16115. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16116. {
  16117. check_ascii = value[0];
  16118. if( (check_ascii < 48) || (check_ascii > 57) )
  16119. {
  16120. isSuccess = ConfigurationStatus_Rejected;
  16121. }
  16122. else
  16123. {
  16124. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16125. isSuccess = ConfigurationStatus_Accepted;
  16126. }
  16127. }
  16128. else
  16129. {
  16130. isSuccess = ConfigurationStatus_Rejected;
  16131. }
  16132. }
  16133. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16134. {
  16135. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16136. {
  16137. strcpy(str, (const char*)value);
  16138. for(int i = 0; str[i]; i++)
  16139. {
  16140. str[i] = tolower(str[i]);
  16141. }
  16142. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16143. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16144. isSuccess = ConfigurationStatus_Accepted;
  16145. }
  16146. else
  16147. {
  16148. isSuccess = ConfigurationStatus_Rejected;
  16149. }
  16150. }
  16151. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16152. {
  16153. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16154. {
  16155. strcpy(str, (const char*)value);
  16156. for(int i = 0; str[i]; i++)
  16157. {
  16158. str[i] = tolower(str[i]);
  16159. }
  16160. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16161. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16162. isSuccess = ConfigurationStatus_Accepted;
  16163. }
  16164. else
  16165. {
  16166. isSuccess = ConfigurationStatus_Rejected;
  16167. }
  16168. }
  16169. if(strcmp(key, "StopTxnAlignedData") == 0)
  16170. {
  16171. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16172. {
  16173. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16174. isSuccess = ConfigurationStatus_Accepted;
  16175. }
  16176. else
  16177. {
  16178. isSuccess = ConfigurationStatus_Rejected;
  16179. }
  16180. }
  16181. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16182. {
  16183. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16184. {
  16185. check_ascii = value[0];
  16186. if( (check_ascii < 48) || (check_ascii > 57) )
  16187. {
  16188. isSuccess = ConfigurationStatus_Rejected;
  16189. }
  16190. else
  16191. {
  16192. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16193. isSuccess = ConfigurationStatus_Accepted;
  16194. }
  16195. }
  16196. else
  16197. {
  16198. isSuccess = ConfigurationStatus_Rejected;
  16199. }
  16200. }
  16201. if(strcmp(key, "StopTxnSampledData") == 0)
  16202. {
  16203. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16204. {
  16205. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16206. isSuccess = ConfigurationStatus_Accepted;
  16207. }
  16208. else
  16209. {
  16210. isSuccess = ConfigurationStatus_Rejected;
  16211. }
  16212. }
  16213. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16214. {
  16215. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16216. {
  16217. check_ascii = value[0];
  16218. if( (check_ascii < 48) || (check_ascii > 57) )
  16219. {
  16220. isSuccess = ConfigurationStatus_Rejected;
  16221. }
  16222. else
  16223. {
  16224. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16225. isSuccess = ConfigurationStatus_Accepted;
  16226. }
  16227. }
  16228. else
  16229. {
  16230. isSuccess = ConfigurationStatus_Rejected;
  16231. }
  16232. }
  16233. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16234. {
  16235. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16236. {
  16237. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16238. isSuccess = ConfigurationStatus_Accepted;
  16239. }
  16240. else
  16241. {
  16242. isSuccess = ConfigurationStatus_Rejected;
  16243. }
  16244. }
  16245. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16246. {
  16247. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16248. {
  16249. check_ascii = value[0];
  16250. if( (check_ascii < 48) || (check_ascii > 57) )
  16251. {
  16252. isSuccess = ConfigurationStatus_Rejected;
  16253. }
  16254. else
  16255. {
  16256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16257. isSuccess = ConfigurationStatus_Accepted;
  16258. }
  16259. }
  16260. else
  16261. {
  16262. isSuccess = ConfigurationStatus_Rejected;
  16263. }
  16264. }
  16265. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16266. {
  16267. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16268. {
  16269. check_ascii = value[0];
  16270. if( (check_ascii < 48) || (check_ascii > 57) )
  16271. {
  16272. isSuccess = ConfigurationStatus_Rejected;
  16273. }
  16274. else
  16275. {
  16276. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16277. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16278. TransactionMessageAttemptsValue = atoi(value);
  16279. isSuccess = ConfigurationStatus_Accepted;
  16280. }
  16281. }
  16282. else
  16283. {
  16284. isSuccess = ConfigurationStatus_Rejected;
  16285. }
  16286. }
  16287. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16288. {
  16289. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16290. {
  16291. check_ascii = value[0];
  16292. if( (check_ascii < 48) || (check_ascii > 57) )
  16293. {
  16294. isSuccess = ConfigurationStatus_Rejected;
  16295. }
  16296. else
  16297. {
  16298. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16299. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16300. TransactionMessageRetryIntervalValue = atoi(value);
  16301. isSuccess = ConfigurationStatus_Accepted;
  16302. }
  16303. }
  16304. else
  16305. {
  16306. isSuccess = ConfigurationStatus_Rejected;
  16307. }
  16308. }
  16309. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16310. {
  16311. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16312. {
  16313. strcpy(str, (const char*)value);
  16314. for(int i = 0; str[i]; i++)
  16315. {
  16316. str[i] = tolower(str[i]);
  16317. }
  16318. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16319. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16320. isSuccess = ConfigurationStatus_Accepted;
  16321. }
  16322. else
  16323. {
  16324. isSuccess = ConfigurationStatus_Rejected;
  16325. }
  16326. }
  16327. if(strcmp(key, "WebSocketPingInterval") == 0)
  16328. {
  16329. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16330. {
  16331. check_ascii = value[0];
  16332. if( (check_ascii < 48) || (check_ascii > 57) )
  16333. {
  16334. isSuccess = ConfigurationStatus_Rejected;
  16335. }
  16336. else
  16337. {
  16338. if((atoi(value) == 0) || (atoi(value) >= 10))
  16339. {
  16340. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16341. isSuccess = ConfigurationStatus_Accepted;
  16342. }
  16343. else
  16344. isSuccess = ConfigurationStatus_Rejected;
  16345. }
  16346. }
  16347. else
  16348. {
  16349. isSuccess = ConfigurationStatus_Rejected;
  16350. }
  16351. }
  16352. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16353. {
  16354. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16355. {
  16356. strcpy(str, (const char*)value);
  16357. for(int i = 0; str[i]; i++)
  16358. {
  16359. str[i] = tolower(str[i]);
  16360. }
  16361. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16362. isSuccess = ConfigurationStatus_Accepted;
  16363. }
  16364. else
  16365. {
  16366. isSuccess = ConfigurationStatus_Rejected;
  16367. }
  16368. }
  16369. if(strcmp(key, "AuthorizationKey") == 0)
  16370. {
  16371. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16372. {
  16373. strcpy(str, (const char*)value);
  16374. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16375. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16376. isSuccess = ConfigurationStatus_Accepted;
  16377. }
  16378. else
  16379. {
  16380. isSuccess = ConfigurationStatus_Rejected;
  16381. }
  16382. }
  16383. if(strcmp(key, "SecurityProfile") == 0)
  16384. {
  16385. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16386. {
  16387. check_ascii = value[0];
  16388. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16389. {
  16390. isSuccess = ConfigurationStatus_Rejected;
  16391. }
  16392. else if(check_ascii == 0x33)
  16393. {
  16394. isSuccess = NotSupported;
  16395. }
  16396. else
  16397. {
  16398. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16399. {
  16400. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16401. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  16402. isSuccess = ConfigurationStatus_Accepted;
  16403. }
  16404. else
  16405. isSuccess = ConfigurationStatus_Rejected;
  16406. }
  16407. }
  16408. else
  16409. {
  16410. isSuccess = ConfigurationStatus_Rejected;
  16411. }
  16412. }
  16413. if(strcmp(key, "DefaultPrice") == 0)
  16414. {
  16415. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16416. {
  16417. strcpy(str, (const char*)value);
  16418. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16419. isSuccess = ConfigurationStatus_Accepted;
  16420. }
  16421. else
  16422. {
  16423. isSuccess = ConfigurationStatus_Rejected;
  16424. }
  16425. }
  16426. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16427. {
  16428. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16429. {
  16430. strcpy(str, (const char*)value);
  16431. for(int i = 0; str[i]; i++)
  16432. {
  16433. str[i] = tolower(str[i]);
  16434. }
  16435. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16436. isSuccess = ConfigurationStatus_Accepted;
  16437. }
  16438. else
  16439. {
  16440. isSuccess = ConfigurationStatus_Rejected;
  16441. }
  16442. }
  16443. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16444. {
  16445. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16446. {
  16447. strcpy(str, (const char*)value);
  16448. for(int i = 0; str[i]; i++)
  16449. {
  16450. str[i] = tolower(str[i]);
  16451. }
  16452. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16453. isSuccess = ConfigurationStatus_Accepted;
  16454. }
  16455. else
  16456. {
  16457. isSuccess = ConfigurationStatus_Rejected;
  16458. }
  16459. }
  16460. if(strcmp(key, "TimeOffset") == 0)
  16461. {
  16462. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16463. {
  16464. strcpy(str, (const char*)value);
  16465. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  16466. isSuccess = ConfigurationStatus_Accepted;
  16467. }
  16468. else
  16469. {
  16470. isSuccess = ConfigurationStatus_Rejected;
  16471. }
  16472. }
  16473. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  16474. {
  16475. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  16476. {
  16477. strcpy(str, (const char*)value);
  16478. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  16479. isSuccess = ConfigurationStatus_Accepted;
  16480. }
  16481. else
  16482. {
  16483. isSuccess = ConfigurationStatus_Rejected;
  16484. }
  16485. }
  16486. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  16487. {
  16488. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  16489. {
  16490. strcpy(str, (const char*)value);
  16491. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  16492. isSuccess = ConfigurationStatus_Accepted;
  16493. }
  16494. else
  16495. {
  16496. isSuccess = ConfigurationStatus_Rejected;
  16497. }
  16498. }
  16499. if(strcmp(key, "SystemUptimeSec") == 0)
  16500. {
  16501. isSuccess = NotSupported;
  16502. }
  16503. if(strcmp(key, "FreeVend") == 0)
  16504. {
  16505. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16506. {
  16507. strcpy(str, (const char*)value);
  16508. for(int i = 0; str[i]; i++)
  16509. {
  16510. str[i] = tolower(str[i]);
  16511. }
  16512. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16513. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16514. isSuccess = ConfigurationStatus_Accepted;
  16515. }
  16516. else
  16517. {
  16518. isSuccess = ConfigurationStatus_Rejected;
  16519. }
  16520. }
  16521. if(strcmp(key, "OcppServer") == 0)
  16522. {
  16523. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16524. {
  16525. strcpy(str, (const char*)value);
  16526. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16527. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16528. isSuccess = ConfigurationStatus_Accepted;
  16529. }
  16530. else
  16531. {
  16532. isSuccess = ConfigurationStatus_Rejected;
  16533. }
  16534. }
  16535. if(strcmp(key, "MaintainServer") == 0)
  16536. {
  16537. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16538. {
  16539. strcpy(str, (const char*)value);
  16540. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16541. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16542. isSuccess = ConfigurationStatus_Accepted;
  16543. }
  16544. else
  16545. {
  16546. isSuccess = ConfigurationStatus_Rejected;
  16547. }
  16548. }
  16549. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16550. {
  16551. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16552. {
  16553. strcpy(str, (const char*)value);
  16554. for(int i = 0; str[i]; i++)
  16555. {
  16556. str[i] = tolower(str[i]);
  16557. }
  16558. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16559. isSuccess = ConfigurationStatus_Accepted;
  16560. }
  16561. else
  16562. {
  16563. isSuccess = ConfigurationStatus_Rejected;
  16564. }
  16565. }
  16566. if(strcmp(key, "StatusNotificationInterval") == 0)
  16567. {
  16568. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16569. {
  16570. check_ascii = value[0];
  16571. if( (check_ascii < 48) || (check_ascii > 57) )
  16572. {
  16573. isSuccess = ConfigurationStatus_Rejected;
  16574. }
  16575. else
  16576. {
  16577. if((atoi(value) == 0) || (atoi(value) >= 10))
  16578. {
  16579. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16580. isSuccess = ConfigurationStatus_Accepted;
  16581. }
  16582. else
  16583. isSuccess = ConfigurationStatus_Rejected;
  16584. }
  16585. }
  16586. else
  16587. {
  16588. isSuccess = ConfigurationStatus_Rejected;
  16589. }
  16590. }
  16591. #if 0
  16592. //For OCPP Test Case
  16593. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16594. {
  16595. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16596. {
  16597. strcpy(str, (const char*)value);
  16598. for(int i = 0; str[i]; i++)
  16599. {
  16600. str[i] = tolower(str[i]);
  16601. }
  16602. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16603. isSuccess = ConfigurationStatus_Accepted;
  16604. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16605. }
  16606. else
  16607. {
  16608. isSuccess = ConfigurationStatus_Rejected;
  16609. }
  16610. }
  16611. #endif
  16612. #if 1
  16613. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16614. {
  16615. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16616. {
  16617. strcpy(str, (const char*)value);
  16618. for(int i = 0; str[i]; i++)
  16619. {
  16620. str[i] = tolower(str[i]);
  16621. }
  16622. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16623. isSuccess = ConfigurationStatus_Accepted;
  16624. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16625. }
  16626. else
  16627. {
  16628. isSuccess = ConfigurationStatus_Rejected;
  16629. }
  16630. }
  16631. #endif
  16632. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16633. {
  16634. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16635. {
  16636. check_ascii = value[0];
  16637. if( (check_ascii < 48) || (check_ascii > 57) )
  16638. {
  16639. isSuccess = ConfigurationStatus_Rejected;
  16640. }
  16641. else
  16642. {
  16643. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16644. isSuccess = ConfigurationStatus_Accepted;
  16645. }
  16646. }
  16647. else
  16648. {
  16649. isSuccess = ConfigurationStatus_Rejected;
  16650. }
  16651. }
  16652. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16653. {
  16654. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16655. {
  16656. check_ascii = value[0];
  16657. if( (check_ascii < 48) || (check_ascii > 57) )
  16658. {
  16659. isSuccess = ConfigurationStatus_Rejected;
  16660. }
  16661. else
  16662. {
  16663. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16664. isSuccess = ConfigurationStatus_Accepted;
  16665. }
  16666. }
  16667. else
  16668. {
  16669. isSuccess = ConfigurationStatus_Rejected;
  16670. }
  16671. }
  16672. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16673. {
  16674. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16675. {
  16676. strcpy(str, (const char*)value);
  16677. for(int i = 0; str[i]; i++)
  16678. {
  16679. str[i] = tolower(str[i]);
  16680. }
  16681. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16682. isSuccess = ConfigurationStatus_Accepted;
  16683. }
  16684. else
  16685. {
  16686. isSuccess = ConfigurationStatus_Rejected;
  16687. }
  16688. }
  16689. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16690. {
  16691. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16692. {
  16693. check_ascii = value[0];
  16694. if( (check_ascii < 48) || (check_ascii > 57) )
  16695. {
  16696. isSuccess = ConfigurationStatus_Rejected;
  16697. }
  16698. else
  16699. {
  16700. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16701. isSuccess = ConfigurationStatus_Accepted;
  16702. }
  16703. }
  16704. else
  16705. {
  16706. isSuccess = ConfigurationStatus_Rejected;
  16707. }
  16708. }
  16709. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16710. {
  16711. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16712. {
  16713. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16714. isSuccess = ConfigurationStatus_Accepted;
  16715. }
  16716. else
  16717. {
  16718. isSuccess = ConfigurationStatus_Rejected;
  16719. }
  16720. }
  16721. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16722. {
  16723. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16724. {
  16725. check_ascii = value[0];
  16726. if( (check_ascii < 48) || (check_ascii > 57) )
  16727. {
  16728. isSuccess = ConfigurationStatus_Rejected;
  16729. }
  16730. else
  16731. {
  16732. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16733. isSuccess = ConfigurationStatus_Accepted;
  16734. }
  16735. }
  16736. else
  16737. {
  16738. isSuccess = ConfigurationStatus_Rejected;
  16739. }
  16740. }
  16741. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16742. {
  16743. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16744. {
  16745. strcpy(str, (const char*)value);
  16746. for(int i = 0; str[i]; i++)
  16747. {
  16748. str[i] = tolower(str[i]);
  16749. }
  16750. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16751. isSuccess = ConfigurationStatus_Accepted;
  16752. }
  16753. else
  16754. {
  16755. isSuccess = ConfigurationStatus_Rejected;
  16756. }
  16757. }
  16758. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16759. {
  16760. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16761. {
  16762. check_ascii = value[0];
  16763. if( (check_ascii < 48) || (check_ascii > 57) )
  16764. {
  16765. isSuccess = ConfigurationStatus_Rejected;
  16766. }
  16767. else
  16768. {
  16769. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16770. isSuccess = ConfigurationStatus_Accepted;
  16771. }
  16772. }
  16773. else
  16774. {
  16775. isSuccess = ConfigurationStatus_Rejected;
  16776. }
  16777. }
  16778. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16779. return isSuccess;
  16780. }
  16781. int TransactionMessageAttemptsGet(void)
  16782. {
  16783. return TransactionMessageAttemptsValue;
  16784. }
  16785. int FirstHeartBeatResponse(void)
  16786. {
  16787. return FirstHeartBeat;
  16788. }
  16789. int TransactionMessageRetryIntervalGet(void)
  16790. {
  16791. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16792. }
  16793. int ReadHttpStatus(int sock)
  16794. {
  16795. //char c;
  16796. char buff[1024]="",*ptr=buff+1;
  16797. int bytes_received, status;
  16798. DEBUG_INFO("Begin Response ..\n");
  16799. while((bytes_received = recv(sock, ptr, 1, 0))){
  16800. if(bytes_received==-1){
  16801. perror("ReadHttpStatus");
  16802. exit(1);
  16803. }
  16804. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16805. ptr++;
  16806. }
  16807. *ptr=0;
  16808. ptr=buff+1;
  16809. sscanf(ptr,"%*s %d ", &status);
  16810. DEBUG_INFO("%s\n",ptr);
  16811. DEBUG_INFO("status=%d\n",status);
  16812. DEBUG_INFO("End Response ..\n");
  16813. return (bytes_received>0)?status:0;
  16814. }
  16815. //the only filed that it parsed is 'Content-Length'
  16816. int ParseHeader(int sock)
  16817. {
  16818. //char c;
  16819. char buff[1024]="",*ptr=buff+4;
  16820. int bytes_received;
  16821. DEBUG_INFO("Begin HEADER ..\n");
  16822. while((bytes_received = recv(sock, ptr, 1, 0))){
  16823. if(bytes_received==-1){
  16824. perror("Parse Header");
  16825. exit(1);
  16826. }
  16827. if(
  16828. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16829. (ptr[-1]=='\r') && (*ptr=='\n' )
  16830. ) break;
  16831. ptr++;
  16832. }
  16833. *ptr=0;
  16834. ptr=buff+4;
  16835. //printf("%s",ptr);
  16836. if(bytes_received){
  16837. ptr=strstr(ptr,"Content-Length:");
  16838. if(ptr){
  16839. sscanf(ptr,"%*s %d",&bytes_received);
  16840. }else
  16841. bytes_received=-1; //unknown size
  16842. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16843. }
  16844. DEBUG_INFO("End HEADER ..\n");
  16845. return bytes_received ;
  16846. }
  16847. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16848. {
  16849. int result = TRUE;
  16850. char rmFileCmd[100]={0};
  16851. char FilePath[100]={0};
  16852. char ftpbuf[200];
  16853. int systemresult;
  16854. sprintf(FilePath,"/mnt/%s",filename);
  16855. system("ping 8.8.8.8 &");
  16856. if((access(FilePath,F_OK))!=-1)
  16857. {
  16858. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16859. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16860. system(rmFileCmd);
  16861. }
  16862. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16863. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16864. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16865. systemresult = system(ftpbuf);
  16866. if(systemresult != 0)
  16867. {
  16868. DEBUG_INFO("http DownLoad error!\n");
  16869. result = FALSE;
  16870. }
  16871. system("pkill ping");
  16872. return result;
  16873. }
  16874. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16875. {
  16876. int result = TRUE;
  16877. char rmFileCmd[100]={0};
  16878. char FilePath[100]={0};
  16879. char ftpbuf[200];
  16880. int systemresult;
  16881. sprintf(FilePath,"/mnt/%s",filename);
  16882. system("ping 8.8.8.8 &");
  16883. if((access(FilePath,F_OK))!=-1)
  16884. {
  16885. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16886. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16887. system(rmFileCmd);
  16888. }
  16889. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16890. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16891. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16892. systemresult = system(ftpbuf);
  16893. if(systemresult != 0)
  16894. {
  16895. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16896. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16897. systemresult = system(ftpbuf);
  16898. if(systemresult != 0)
  16899. {
  16900. DEBUG_WARN("wget error!\n");
  16901. result = FALSE;
  16902. }
  16903. }
  16904. system("pkill ping");
  16905. return result;
  16906. }
  16907. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16908. {
  16909. char rmFileCmd[100]={0};
  16910. char FilePath[100]={0};
  16911. char buf[512];
  16912. int systemresult = 0;
  16913. //DEBUG_INFO("filename=%s\n",filename);
  16914. //DEBUG_INFO("url=%s\n",url);
  16915. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16916. if((access(FilePath,F_OK))!=-1)
  16917. {
  16918. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16919. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16920. system(rmFileCmd);
  16921. }
  16922. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16923. if(fp == NULL)
  16924. {
  16925. DEBUG_INFO("log is NULL\n");
  16926. return FALSE;
  16927. }
  16928. else
  16929. {
  16930. fprintf(fp, "%s\n", url);
  16931. fprintf(fp, "%s\n", filename);
  16932. fclose(fp);
  16933. }
  16934. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16935. if(phpFP == NULL)
  16936. {
  16937. DEBUG_INFO("PHP upload fail.\n");
  16938. return FALSE;
  16939. }
  16940. else
  16941. {
  16942. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16943. {
  16944. if(strstr(buf, "result") != NULL)
  16945. {
  16946. sscanf(buf, "result: %d", &systemresult);
  16947. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16948. }
  16949. }
  16950. pclose(phpFP);
  16951. }
  16952. if(systemresult != 1)
  16953. {
  16954. DEBUG_INFO("HTTP upload error!\n");
  16955. return FALSE;
  16956. }
  16957. return TRUE;
  16958. }
  16959. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16960. {
  16961. int result = FALSE;
  16962. char ftpbuf[200];
  16963. int systemresult;
  16964. /*
  16965. // Domaind name transfer to IP address
  16966. struct hostent* server;
  16967. char *IPbuffer;
  16968. server = gethostbyname(location);
  16969. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16970. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16971. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16972. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16973. systemresult = system(ftpbuf);
  16974. if(systemresult != 0)
  16975. {
  16976. DEBUG_INFO("ftpput error!\n");
  16977. }
  16978. else
  16979. {
  16980. result = TRUE;
  16981. DEBUG_INFO("ftpput OK!\n");
  16982. }
  16983. return result;
  16984. }
  16985. int GetOcppServerURL()
  16986. {
  16987. int result = FALSE;
  16988. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16989. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16990. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16991. struct yuarel url;
  16992. char urlStr[512];
  16993. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  16994. {
  16995. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  16996. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16997. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16998. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  16999. if(yuarel_parse(&url, urlStr) != -1)
  17000. {
  17001. sprintf(OcppProtocol, "%s", url.scheme);
  17002. sprintf(OcppHost, "%s", url.host);
  17003. if(url.path == NULL)
  17004. OcppTempPath[0] = '\0';
  17005. else
  17006. {
  17007. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  17008. {
  17009. sprintf(OcppTempPath, "%s/", url.path);
  17010. }
  17011. else
  17012. {
  17013. sprintf(OcppTempPath, "%s", url.path);
  17014. }
  17015. }
  17016. if(url.port == 0)
  17017. {
  17018. if(strcmp(OcppProtocol, "wss") == 0)
  17019. OcppPort = 443;
  17020. else
  17021. OcppPort = 80;
  17022. }
  17023. else
  17024. OcppPort = url.port;
  17025. result = TRUE;
  17026. }
  17027. }
  17028. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  17029. {
  17030. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  17031. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17032. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17033. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  17034. if(yuarel_parse(&url, urlStr) != -1)
  17035. {
  17036. sprintf(OcppProtocol, "%s", url.scheme);
  17037. sprintf(OcppHost, "%s", url.host);
  17038. if(url.path == NULL)
  17039. OcppTempPath[0] = '\0';
  17040. else
  17041. sprintf(OcppTempPath, "%s", url.path);
  17042. if(url.port == 0)
  17043. {
  17044. if(strcmp(OcppProtocol, "wss") == 0)
  17045. OcppPort = 443;
  17046. else
  17047. OcppPort = 80;
  17048. }
  17049. else
  17050. OcppPort = url.port;
  17051. result = TRUE;
  17052. }
  17053. }
  17054. else
  17055. {
  17056. strcpy(OcppHost,"");
  17057. }
  17058. return result;
  17059. }
  17060. int GetOcppPath()
  17061. {
  17062. int result = FALSE;
  17063. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  17064. {
  17065. if(OcppTempPath == NULL)
  17066. {
  17067. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17068. }
  17069. else
  17070. {
  17071. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17072. }
  17073. result = TRUE;
  17074. goto End;
  17075. }
  17076. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  17077. {
  17078. if(OcppTempPath == NULL)
  17079. {
  17080. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  17081. }
  17082. else
  17083. {
  17084. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  17085. }
  17086. result = TRUE;
  17087. goto End;
  17088. }
  17089. else
  17090. {
  17091. strcpy(OcppPath,"");
  17092. }
  17093. End:
  17094. return result;
  17095. }
  17096. int GetOcppPort()
  17097. {
  17098. return OcppPort;
  17099. }
  17100. int GetOcppConnStatus(void)
  17101. {
  17102. return ShmOCPP16Data->OcppConnStatus;
  17103. }
  17104. void SetOcppConnStatus(uint8_t status)
  17105. {
  17106. ShmOCPP16Data->OcppConnStatus = status;
  17107. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  17108. }
  17109. int GetHeartBeatWithNOResponse(void)
  17110. {
  17111. return HeartBeatWithNOResponse;
  17112. }
  17113. void SetHeartBeatWithNOResponse(void)
  17114. {
  17115. HeartBeatWithNOResponse = 0;
  17116. }
  17117. void GetStartTransactionIdTag(int gun_index)
  17118. {
  17119. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17120. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17121. }
  17122. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17123. {
  17124. char ch;
  17125. FILE *fptr1;
  17126. int temptransactionId;
  17127. char str[100]={0};
  17128. temptransactionId = 0;
  17129. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17130. {
  17131. DEBUG_INFO("IdTag is empty.\n");
  17132. return temptransactionId;
  17133. }
  17134. /*------ Read the file ----------------*/
  17135. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  17136. if (!fptr1)
  17137. {
  17138. DEBUG_INFO("QueueTransactionId file open error.\n");
  17139. //printf(" File not found or unable to open the input file!!\n");
  17140. return temptransactionId;
  17141. }
  17142. ch=fgetc(fptr1);
  17143. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  17144. rewind(fptr1);
  17145. if(ch!=EOF)
  17146. {
  17147. // printf("%c",ch);
  17148. while (fgets(str, 100, fptr1) != NULL)
  17149. {
  17150. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17151. if(str[0]=='\0')
  17152. {
  17153. break;
  17154. }
  17155. char *revbuf[8] = {0}; // Variable store string split
  17156. int num = 0;// Quantity after string split
  17157. DEBUG_INFO("Transaction queue data= %s\n", str);
  17158. splitstring(str,",",revbuf,&num); // String split
  17159. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17160. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17161. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17162. DEBUG_INFO("------------------------------\n");
  17163. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17164. {
  17165. if(isStopTransaction)
  17166. {
  17167. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17168. {
  17169. temptransactionId = atoi(revbuf[2]);
  17170. //break;
  17171. }
  17172. }
  17173. else
  17174. {
  17175. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17176. {
  17177. temptransactionId = atoi(revbuf[2]);
  17178. //break;
  17179. }
  17180. }
  17181. }
  17182. }
  17183. }
  17184. else
  17185. DEBUG_INFO("EOF\n");
  17186. fclose(fptr1);
  17187. /*------- End of reading ---------------*/
  17188. return temptransactionId;
  17189. }
  17190. void SetTransactionIdZero(int transactionId)
  17191. {
  17192. char ch;
  17193. FILE *fptr1, *fptr2;
  17194. int temptransactionId = 0;
  17195. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  17196. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  17197. if (!fptr1)
  17198. {
  17199. //printf(" File not found or unable to open the input file!!\n");
  17200. return ;
  17201. }
  17202. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17203. if (!fptr2)
  17204. {
  17205. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17206. fclose(fptr1);
  17207. return ;
  17208. }
  17209. ch=fgetc(fptr1);
  17210. rewind(fptr1);
  17211. if(ch!=EOF)
  17212. {
  17213. // copy all contents to the temporary file except the specific line
  17214. while (fgets(str, 100, fptr1) != NULL)
  17215. {
  17216. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17217. if(str[0]=='\0')
  17218. {
  17219. break;
  17220. }
  17221. char *revbuf[8] = {0};
  17222. int num = 0;
  17223. strcpy(strtemp, str);
  17224. splitstring(str,",",revbuf,&num);
  17225. if(revbuf[2][0] != '\0')
  17226. {
  17227. temptransactionId = atoi(revbuf[2]);
  17228. if(transactionId != temptransactionId)
  17229. {
  17230. fprintf(fptr2, "%s\n", strtemp);
  17231. }
  17232. }
  17233. }
  17234. }
  17235. fclose(fptr1);
  17236. fclose(fptr2);
  17237. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  17238. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  17239. /*------ Read the file ----------------*/
  17240. }
  17241. int InternetDisconnect(void)
  17242. {
  17243. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17244. }
  17245. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17246. void storeTempStopTransaction(int gun_index)
  17247. {
  17248. char guid[37]={0};
  17249. int tempIndex = 0;
  17250. char TempStopTransaction[256];
  17251. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  17252. DEBUG_INFO("storeTempStopTransaction...\n");
  17253. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17254. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  17255. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17256. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17257. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17258. {
  17259. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17260. {
  17261. tempIndex = ((gun_index==2) ? 1: 0);
  17262. }
  17263. else
  17264. {
  17265. tempIndex = gun_index;
  17266. }
  17267. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17268. {
  17269. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17270. {
  17271. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17272. }
  17273. }// END OF CHAdeMO_QUANTITY
  17274. }
  17275. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17276. {
  17277. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17278. {
  17279. tempIndex = ((gun_index==2) ? 1: 0);
  17280. }
  17281. else
  17282. {
  17283. tempIndex = gun_index;
  17284. }
  17285. for (int index = 0; index < CCS_QUANTITY; index++)
  17286. {
  17287. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17288. {
  17289. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17290. }
  17291. }// END OF CCS_QUANTITY
  17292. }
  17293. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17294. {
  17295. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17296. {
  17297. tempIndex = ((gun_index==2) ? 1: 0);
  17298. }
  17299. else
  17300. {
  17301. tempIndex = gun_index;
  17302. }
  17303. for (int index = 0; index < GB_QUANTITY; index++)
  17304. {
  17305. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17306. {
  17307. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17308. }
  17309. }// END OF GB_QUANTITY
  17310. }
  17311. else if(gunType[gun_index] == GUN_TYPE_DO)
  17312. {
  17313. tempIndex = gun_index;
  17314. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17315. {
  17316. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17317. {
  17318. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17319. }
  17320. }
  17321. }
  17322. else
  17323. {
  17324. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17325. {
  17326. tempIndex = 2;
  17327. }
  17328. else
  17329. {
  17330. tempIndex = gun_index;
  17331. }
  17332. for (int index = 0; index < AC_QUANTITY; index++)
  17333. {
  17334. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17335. {
  17336. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17337. }
  17338. }// END OF AC_QUANTITY
  17339. }
  17340. //Stop Transaction Time
  17341. struct timeval tmnow;
  17342. struct tm *tm;
  17343. char buf[28];//, usec_buf[6];
  17344. gettimeofday(&tmnow, NULL);
  17345. time_t t;
  17346. t = time(NULL);
  17347. /*UTC time and date*/
  17348. tm = gmtime(&t);
  17349. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17350. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  17351. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  17352. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17353. random_uuid(guid);
  17354. /***********************************transactionData******************************************************/
  17355. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17356. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17357. //=================================
  17358. //1. Transaction_Begin
  17359. //=================================
  17360. //============================== Energy.Active.Import.Interval ===========================================
  17361. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17362. {
  17363. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  17364. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17365. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  17366. 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*/]);
  17367. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17368. 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))
  17369. {
  17370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  17371. }
  17372. else
  17373. {
  17374. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  17375. }
  17376. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  17377. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17378. }
  17379. //=================================
  17380. //2. Transaction_End
  17381. //=================================
  17382. //2.1====================================== Current.Import L1 ==============================================
  17383. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17384. {
  17385. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17386. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17387. {
  17388. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17389. {
  17390. tempIndex = ((gun_index==2) ? 1: 0);
  17391. }
  17392. else
  17393. {
  17394. tempIndex = gun_index;
  17395. }
  17396. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17397. {
  17398. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17399. {
  17400. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17401. }
  17402. }// End of for CHAdeMO_QUANTITY
  17403. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17404. }
  17405. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17406. {
  17407. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17408. {
  17409. tempIndex = ((gun_index==2) ? 1: 0);
  17410. }
  17411. else
  17412. {
  17413. tempIndex = gun_index;
  17414. }
  17415. for (int index = 0; index < CCS_QUANTITY; index++)
  17416. {
  17417. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17418. {
  17419. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17420. }
  17421. }// End of for CCS_QUANTITY
  17422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17423. }
  17424. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17425. {
  17426. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17427. {
  17428. tempIndex = ((gun_index==2) ? 1: 0);
  17429. }
  17430. else
  17431. {
  17432. tempIndex = gun_index;
  17433. }
  17434. for (int index = 0; index < GB_QUANTITY; index++)
  17435. {
  17436. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17437. {
  17438. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17439. }
  17440. }// End of for GB_QUANTITY
  17441. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17442. }
  17443. else if(gunType[gun_index] == GUN_TYPE_DO)
  17444. {
  17445. tempIndex = gun_index;
  17446. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17447. {
  17448. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17449. {
  17450. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17451. }
  17452. }
  17453. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17454. }
  17455. else
  17456. {
  17457. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17458. {
  17459. tempIndex = 2;
  17460. }
  17461. else
  17462. {
  17463. tempIndex = gun_index;
  17464. }
  17465. for (int index = 0; index < AC_QUANTITY; index++)
  17466. {
  17467. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17468. {
  17469. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17470. }
  17471. }// End of for AC_QUANTITY
  17472. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17473. }
  17474. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17475. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17476. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17477. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17479. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17480. }
  17481. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17482. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17483. {
  17484. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17485. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17486. {
  17487. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17488. {
  17489. tempIndex = ((gun_index==2) ? 1: 0);
  17490. }
  17491. else
  17492. {
  17493. tempIndex = gun_index;
  17494. }
  17495. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17496. {
  17497. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17498. {
  17499. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17500. }
  17501. }// END OF CHAdeMO_QUANTITY
  17502. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17503. }
  17504. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17505. {
  17506. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17507. {
  17508. tempIndex = ((gun_index==2) ? 1: 0);
  17509. }
  17510. else
  17511. {
  17512. tempIndex = gun_index;
  17513. }
  17514. for (int index = 0; index < CCS_QUANTITY; index++)
  17515. {
  17516. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17517. {
  17518. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17519. }
  17520. }// END OF CCS_QUANTITY
  17521. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17522. }
  17523. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17524. {
  17525. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17526. {
  17527. tempIndex = ((gun_index==2) ? 1: 0);
  17528. }
  17529. else
  17530. {
  17531. tempIndex = gun_index;
  17532. }
  17533. for (int index = 0; index < GB_QUANTITY; index++)
  17534. {
  17535. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17536. {
  17537. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17538. }
  17539. }// END OF GB_QUANTITY
  17540. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17541. }
  17542. else if(gunType[gun_index] == GUN_TYPE_DO)
  17543. {
  17544. tempIndex = gun_index;
  17545. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17546. {
  17547. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17548. {
  17549. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17550. }
  17551. }
  17552. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17553. }
  17554. else
  17555. {
  17556. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17557. {
  17558. tempIndex = 2;
  17559. }
  17560. else
  17561. {
  17562. tempIndex = gun_index;
  17563. }
  17564. for (int index = 0; index < AC_QUANTITY; index++)
  17565. {
  17566. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17567. {
  17568. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17569. }
  17570. }// END OF AC_QUANTITY
  17571. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17572. }
  17573. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17574. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17575. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17576. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17577. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17578. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17579. }
  17580. //2.3====================================== Power.Active.Import =========================================
  17581. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17582. {
  17583. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17584. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17585. {
  17586. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17587. {
  17588. tempIndex = ((gun_index==2) ? 1: 0);
  17589. }
  17590. else
  17591. {
  17592. tempIndex = gun_index;
  17593. }
  17594. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17595. {
  17596. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17597. {
  17598. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17599. }
  17600. } // End for CHAdeMO_QUANTITY
  17601. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17602. }
  17603. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17604. {
  17605. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17606. {
  17607. tempIndex = ((gun_index==2) ? 1: 0);
  17608. }
  17609. else
  17610. {
  17611. tempIndex = gun_index;
  17612. }
  17613. for (int index = 0; index < CCS_QUANTITY; index++)
  17614. {
  17615. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17616. {
  17617. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17618. }
  17619. } // END for CCS_QUANTITY
  17620. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17621. }
  17622. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17623. {
  17624. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17625. {
  17626. tempIndex = ((gun_index==2) ? 1: 0);
  17627. }
  17628. else
  17629. {
  17630. tempIndex = gun_index;
  17631. }
  17632. for (int index = 0; index < GB_QUANTITY; index++)
  17633. {
  17634. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17635. {
  17636. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17637. }
  17638. }// END for GB_QUANTITY
  17639. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17640. }
  17641. else if(gunType[gun_index] == GUN_TYPE_DO)
  17642. {
  17643. tempIndex = gun_index;
  17644. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17645. {
  17646. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17647. {
  17648. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17649. }
  17650. }
  17651. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17652. }
  17653. else
  17654. {
  17655. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17656. {
  17657. tempIndex = 2;
  17658. }
  17659. else
  17660. {
  17661. tempIndex = gun_index;
  17662. }
  17663. for (int index = 0; index < AC_QUANTITY; index++)
  17664. {
  17665. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17666. {
  17667. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17668. }
  17669. } // END for AC_QUANTITY
  17670. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17671. }
  17672. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17673. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17674. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17675. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17676. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17677. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17678. }
  17679. //2.4====================================== Voltage L1 ====================================================
  17680. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17681. {
  17682. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17683. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17684. {
  17685. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17686. {
  17687. tempIndex = ((gun_index==2) ? 1: 0);
  17688. }
  17689. else
  17690. {
  17691. tempIndex = gun_index;
  17692. }
  17693. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17694. {
  17695. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17696. {
  17697. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17698. }
  17699. } // END OF FOR CHAdeMO_QUANTITY
  17700. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17701. }
  17702. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17703. {
  17704. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17705. {
  17706. tempIndex = ((gun_index==2) ? 1: 0);
  17707. }
  17708. else
  17709. {
  17710. tempIndex = gun_index;
  17711. }
  17712. for (int index = 0; index < CCS_QUANTITY; index++)
  17713. {
  17714. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17715. {
  17716. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17717. }
  17718. } // END OF FOR CCS_QUANTITY
  17719. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17720. }
  17721. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17722. {
  17723. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17724. {
  17725. tempIndex = ((gun_index==2) ? 1: 0);
  17726. }
  17727. else
  17728. {
  17729. tempIndex = gun_index;
  17730. }
  17731. for (int index = 0; index < GB_QUANTITY; index++)
  17732. {
  17733. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17734. {
  17735. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17736. }
  17737. } // END OF FOR GB_QUANTITY
  17738. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17739. }
  17740. else if(gunType[gun_index] == GUN_TYPE_DO)
  17741. {
  17742. tempIndex = gun_index;
  17743. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17744. {
  17745. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17746. {
  17747. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17748. }
  17749. }
  17750. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17751. }
  17752. else
  17753. {
  17754. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17755. {
  17756. tempIndex = 2;
  17757. }
  17758. else
  17759. {
  17760. tempIndex = gun_index;
  17761. }
  17762. for (int index = 0; index < AC_QUANTITY; index++)
  17763. {
  17764. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17765. {
  17766. 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
  17767. }
  17768. } // END OF FOR AC_QUANTITY
  17769. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17770. }
  17771. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17772. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17773. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17774. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17775. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17776. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17777. }
  17778. //2.5============================================== End SoC =========================================================
  17779. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17780. {
  17781. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17782. 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))
  17783. {
  17784. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17785. {
  17786. tempIndex = ((gun_index==2) ? 1: 0);
  17787. }
  17788. else
  17789. {
  17790. tempIndex = gun_index;
  17791. }
  17792. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17793. {
  17794. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17795. {
  17796. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17797. {
  17798. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17799. }
  17800. }
  17801. }
  17802. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17803. {
  17804. for (int index = 0; index < CCS_QUANTITY; index++)
  17805. {
  17806. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17807. {
  17808. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17809. }
  17810. }
  17811. }
  17812. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17813. {
  17814. for (int index = 0; index < GB_QUANTITY; index++)
  17815. {
  17816. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17817. {
  17818. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17819. }
  17820. }
  17821. }
  17822. else if(gunType[gun_index] == GUN_TYPE_DO)
  17823. {
  17824. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17825. {
  17826. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17827. {
  17828. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17829. }
  17830. }
  17831. }
  17832. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17833. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17834. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17835. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17836. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17837. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17838. } // END FOR DC CASE
  17839. }
  17840. //2.6====================================== Current.Import L2 ==============================================
  17841. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17842. {
  17843. // AC 3 phase L2 current
  17844. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17845. {
  17846. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17847. {
  17848. tempIndex = 2;
  17849. }
  17850. else
  17851. {
  17852. tempIndex = gun_index;
  17853. }
  17854. for (int index = 0; index < AC_QUANTITY; index++)
  17855. {
  17856. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17857. {
  17858. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17859. }
  17860. }// End of for AC_QUANTITY
  17861. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17862. }
  17863. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17864. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17865. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17866. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17867. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17868. }
  17869. //2.7====================================== Current.Import L3 ==============================================
  17870. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17871. {
  17872. // AC 3 phase L3 current
  17873. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17874. {
  17875. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17876. {
  17877. tempIndex = 2;
  17878. }
  17879. else
  17880. {
  17881. tempIndex = gun_index;
  17882. }
  17883. for (int index = 0; index < AC_QUANTITY; index++)
  17884. {
  17885. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17886. {
  17887. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17888. }
  17889. }// End of for AC_QUANTITY
  17890. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17891. }
  17892. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17893. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17894. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17895. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17896. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17897. }
  17898. //2.9====================================== Voltage L2 ====================================================
  17899. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17900. {
  17901. // AC 3 phase L2 volatge
  17902. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17903. {
  17904. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17905. {
  17906. tempIndex = 2;
  17907. }
  17908. else
  17909. {
  17910. tempIndex = gun_index;
  17911. }
  17912. for (int index = 0; index < AC_QUANTITY; index++)
  17913. {
  17914. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17915. {
  17916. 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
  17917. }
  17918. } // END OF FOR AC_QUANTITY
  17919. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  17920. }
  17921. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17922. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17923. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17924. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17925. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17926. }
  17927. //2.10====================================== Voltage L3 ====================================================
  17928. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17929. {
  17930. // AC 3 phase L3 volatge
  17931. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17932. {
  17933. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17934. {
  17935. tempIndex = 2;
  17936. }
  17937. else
  17938. {
  17939. tempIndex = gun_index;
  17940. }
  17941. for (int index = 0; index < AC_QUANTITY; index++)
  17942. {
  17943. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17944. {
  17945. 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
  17946. }
  17947. } // END OF FOR AC_QUANTITY
  17948. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  17949. }
  17950. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17951. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  17952. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  17953. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  17954. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17955. }
  17956. //====================== Start SoC ================================
  17957. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17958. {
  17959. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17960. 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))
  17961. {
  17962. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17963. {
  17964. tempIndex = ((gun_index==2) ? 1: 0);
  17965. }
  17966. else
  17967. {
  17968. tempIndex = gun_index;
  17969. }
  17970. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17971. {
  17972. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17973. {
  17974. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17975. {
  17976. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  17977. }
  17978. }
  17979. }
  17980. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17981. {
  17982. for (int index = 0; index < CCS_QUANTITY; index++)
  17983. {
  17984. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17985. {
  17986. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  17987. }
  17988. }
  17989. }
  17990. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17991. {
  17992. for (int index = 0; index < GB_QUANTITY; index++)
  17993. {
  17994. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17995. {
  17996. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  17997. }
  17998. }
  17999. }
  18000. else if(gunType[gun_index] == GUN_TYPE_DO)
  18001. {
  18002. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18003. {
  18004. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18005. {
  18006. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18007. }
  18008. }
  18009. }
  18010. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18011. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18012. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18013. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18014. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18015. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18016. } // END FOR DC CASE
  18017. }
  18018. //======================================== Message create ==============================================
  18019. json_object *StopTransaction = json_object_new_object();
  18020. json_object *transactionDatas = json_object_new_array();
  18021. json_object *sampledValues = json_object_new_array();
  18022. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  18023. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  18024. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  18025. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  18026. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  18027. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18028. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  18029. {
  18030. json_object *transactionData = json_object_new_object();
  18031. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18032. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18033. {
  18034. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18035. {
  18036. json_object *sampledValue = json_object_new_object();
  18037. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18038. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18039. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18040. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18041. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18042. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18043. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18044. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18045. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18046. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18047. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18048. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18049. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18050. json_object_array_add(sampledValues, sampledValue);
  18051. }
  18052. }
  18053. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18054. json_object_array_add(transactionDatas, transactionData);
  18055. }
  18056. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18057. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18058. ,MESSAGE_TYPE_CALL
  18059. ,guid
  18060. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18061. json_object_put(StopTransaction);
  18062. // Check File "TempStopTransaction" Exist
  18063. if((access(TempStopTransaction,F_OK))!=-1)
  18064. {
  18065. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18066. fclose(fopen(TempStopTransaction, "w"));
  18067. }
  18068. else
  18069. {
  18070. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18071. FILE *log = fopen(TempStopTransaction, "w+");
  18072. if(log == NULL)
  18073. {
  18074. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18075. return ;
  18076. }
  18077. else
  18078. {
  18079. fclose(log);
  18080. }
  18081. }
  18082. //Add TempStopTransaction | Update TempStopTransaction
  18083. // open file for writing
  18084. FILE *outfile;
  18085. outfile = fopen (TempStopTransaction, "a");
  18086. //DEBUG_INFO("data = %s\n", queuedata);
  18087. fputs(queuedata, outfile);
  18088. fputs("\n", outfile);
  18089. fclose (outfile);
  18090. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18091. OCPP_updatePeriodEnergy(gun_index);
  18092. }
  18093. void checkTempStopTransaction(int gun_index)
  18094. {
  18095. FILE *fptr1;
  18096. char ch;
  18097. char str[QUEUE_MESSAGE_LENGTH]={0};
  18098. char guid[37]={0};
  18099. char tempdata[65]={0};
  18100. char connectorStr[2]={0};
  18101. char TempStopTransaction[256];
  18102. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18103. fptr1 = fopen(TempStopTransaction, "r");
  18104. //TempStopTransaction格式: 槍號,StopTransaction封包
  18105. if (!fptr1)
  18106. {
  18107. //printf(" File not found or unable to open the input file!!\n");
  18108. return ;
  18109. }
  18110. ch=fgetc(fptr1);
  18111. //printf(" Now the content of the file %s is : \n",fname);
  18112. rewind(fptr1);
  18113. if(ch!=EOF)
  18114. {
  18115. // copy all contents to the temporary file except the specific line
  18116. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18117. {
  18118. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18119. if(str[0]=='\0')
  18120. {
  18121. break;
  18122. }
  18123. //TempStopTransaction格式: 槍號,StopTransaction封包
  18124. strncpy(connectorStr, str, 1);
  18125. if(atoi(connectorStr) != (gun_index+1))
  18126. {
  18127. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18128. fclose(fptr1);
  18129. return ;
  18130. }
  18131. //random_uuid(guid);
  18132. strncpy(guid, str+6, 36); //copy guid
  18133. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18134. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18135. {
  18136. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18137. }
  18138. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18139. OCPP_insert_transaction_msg(NO, str);
  18140. memset(str,0,ARRAY_SIZE(str));
  18141. }
  18142. }
  18143. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18144. fclose(fptr1);
  18145. remove(TempStopTransaction); // remove the original file
  18146. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18147. }
  18148. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18149. {
  18150. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18151. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18152. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18153. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18154. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18155. }
  18156. int GetWebSocketPingInterval(void)
  18157. {
  18158. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18159. }
  18160. int GetServerSign(void)
  18161. {
  18162. return server_sign;
  18163. }
  18164. uint8_t GetOcppSecurityProfile()
  18165. {
  18166. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18167. }
  18168. void GetOcppChargerBoxId(uint8_t *data)
  18169. {
  18170. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18171. }
  18172. void GetOcppSecurityPassword(uint8_t *data)
  18173. {
  18174. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18175. }
  18176. void SetOcppVersion(uint8_t *version)
  18177. {
  18178. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18179. DEBUG_INFO("ocpp version: %s\n", version);
  18180. if(strstr((char*)version, "ocpp1.6") != NULL)
  18181. {
  18182. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18183. }
  18184. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18185. {
  18186. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18187. system("pkill OcppBackend");
  18188. }
  18189. }
  18190. void SetServerSign(int value)
  18191. {
  18192. server_sign = value;
  18193. }
  18194. int GetBootNotificationInterval(void)
  18195. {
  18196. return BootNotificationInterval;
  18197. }
  18198. int GetInternetConn(void)
  18199. {
  18200. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18201. }
  18202. int GetBackendConnectionTimeout(void)
  18203. {
  18204. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18205. }
  18206. int isConnectorInitMode(int gun_index)
  18207. {
  18208. int tempIndex = 0;
  18209. int result = TRUE;
  18210. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18211. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18212. {
  18213. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18214. {
  18215. tempIndex = ((gun_index==2) ? 1: 0);
  18216. }
  18217. else
  18218. {
  18219. tempIndex = gun_index;
  18220. }
  18221. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18222. {
  18223. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18224. {
  18225. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18226. } //end of the same index
  18227. }//end of for CHAdeMO_QUANTITY
  18228. }
  18229. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18230. {
  18231. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18232. {
  18233. tempIndex = ((gun_index==2) ? 1: 0);
  18234. }
  18235. else
  18236. {
  18237. tempIndex = gun_index;
  18238. }
  18239. for (int index = 0; index < CCS_QUANTITY; index++)
  18240. {
  18241. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18242. {
  18243. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18244. } //end of the same index
  18245. } // end of for CCS_QUANTITY
  18246. }
  18247. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18248. {
  18249. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18250. {
  18251. tempIndex = ((gun_index==2) ? 1: 0);
  18252. }
  18253. else
  18254. {
  18255. tempIndex = gun_index;
  18256. }
  18257. for (int index = 0; index < GB_QUANTITY; index++)
  18258. {
  18259. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18260. {
  18261. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18262. } //end of the same index
  18263. } // end of for GB_QUANTITY
  18264. }
  18265. else if(gunType[gun_index] == GUN_TYPE_DO)
  18266. {
  18267. tempIndex = gun_index;
  18268. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18269. {
  18270. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18271. {
  18272. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18273. } //end of the same index
  18274. }
  18275. }
  18276. else
  18277. {
  18278. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18279. {
  18280. tempIndex = 2;
  18281. }
  18282. else
  18283. {
  18284. tempIndex = gun_index;
  18285. }
  18286. for (int index = 0; index < AC_QUANTITY; index++)
  18287. {
  18288. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18289. {
  18290. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18291. }//end of the same index
  18292. }//end of for AC_QUANTITY
  18293. }
  18294. return result;
  18295. }
  18296. void refreshProcDogTimer()
  18297. {
  18298. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  18299. }
  18300. void InitialSystemValue(void)
  18301. {
  18302. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18303. locallistVersion=0;
  18304. BootNotificationInterval = 0;
  18305. authorizeRetryTimes = 0;
  18306. GunStatusInterval = 10;
  18307. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18308. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18309. //Hear Beat
  18310. HeartBeatWithNOResponse = 0;
  18311. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18312. FirstHeartBeat = 0;
  18313. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18314. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18315. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18316. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18317. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18318. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18319. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18320. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18321. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18322. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18323. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18324. //Status && ConnectorPlugIn Setting
  18325. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18326. {
  18327. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18328. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18329. }
  18330. for (int index = 0; index < CCS_QUANTITY; index++)
  18331. {
  18332. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18333. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18334. }
  18335. for (int index = 0; index < GB_QUANTITY; index++)
  18336. {
  18337. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18338. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18339. }
  18340. for (int index = 0; index < AC_QUANTITY; index++)
  18341. {
  18342. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18343. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18344. }
  18345. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18346. {
  18347. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18348. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18349. }
  18350. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18351. {
  18352. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18353. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18354. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18355. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18356. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18357. }
  18358. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18359. refreshStartTimer(&clientTime.Heartbeat);
  18360. sleep(1);
  18361. }
  18362. void LWS_Send(char *str)
  18363. {
  18364. //=====================================================
  18365. // Check InternetConn 0: disconnected, 1: connected
  18366. //====================================================
  18367. if(GetOcppConnStatus() == 0)
  18368. {
  18369. DEBUG_INFO("offline now !!!\n");
  18370. return;
  18371. }
  18372. // Only disable isWebsocketSendable operation initiated by charger
  18373. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18374. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18375. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18376. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18377. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18378. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18379. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18380. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18381. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18382. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18383. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18384. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18385. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18386. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18387. {
  18388. isWebsocketSendable = 0;
  18389. }
  18390. pthread_mutex_lock(&lock_send);
  18391. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18392. sprintf((char *)SendBuffer, "%s", str);
  18393. SendBufLen = strlen(str);
  18394. pthread_mutex_unlock(&lock_send);
  18395. lws_callback_on_writable(wsi_client);
  18396. //lws_service(context, 0);
  18397. //sleep(1);
  18398. }
  18399. void LWS_SendNow(char *str)
  18400. {
  18401. //=====================================================
  18402. // Check InternetConn 0: disconnected, 1: connected
  18403. //====================================================
  18404. if(GetOcppConnStatus() == 0)
  18405. {
  18406. DEBUG_INFO("offline now !!!\n");
  18407. return;
  18408. }
  18409. // Only disable isWebsocketSendable operation initiated by charger
  18410. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18411. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18412. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18413. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18414. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18415. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18416. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18417. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18418. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18419. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18420. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18421. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18422. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18423. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18424. {
  18425. isWebsocketSendable = 0;
  18426. }
  18427. pthread_mutex_lock(&lock_send);
  18428. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18429. sprintf((char *)SendBuffer, "%s", str);
  18430. SendBufLen = strlen(str);
  18431. pthread_mutex_unlock(&lock_send);
  18432. lws_callback_on_writable(wsi_client);
  18433. lws_service(context, 0);
  18434. //sleep(1);
  18435. }