MessageHandler.c 929 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213
  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 YesCustomCallReader;
  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. //==========================================
  1102. // Check time passed since today
  1103. //==========================================
  1104. long long DiffTimebWithNow(struct timeb ST)
  1105. {
  1106. //return milli-second
  1107. struct timeb ET;
  1108. long long StartTime,StopTime;
  1109. ftime(&ET);
  1110. StartTime=(long long)ST.time;
  1111. StopTime=(long long)ET.time;
  1112. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1113. }
  1114. int getTimePassSinceToday(uint8_t gun_index)
  1115. {
  1116. int result = -1;
  1117. static time_t lastTime[4];
  1118. time_t t;
  1119. struct tm *tmStartToday;
  1120. struct timeb tbStartToday;
  1121. t=time(NULL);
  1122. if(difftime(t, lastTime[gun_index])>0)
  1123. {
  1124. tmStartToday=localtime(&t);
  1125. tmStartToday->tm_hour = 0;
  1126. tmStartToday->tm_min = 0;
  1127. tmStartToday->tm_sec = 0;
  1128. tbStartToday.time = mktime(tmStartToday);
  1129. tbStartToday.millitm = 0;
  1130. result = DiffTimebWithNow(tbStartToday)/1000;
  1131. lastTime[gun_index] = t;
  1132. }
  1133. return result;
  1134. }
  1135. void getNowDatetime(uint8_t *data)
  1136. {
  1137. time_t t = time(NULL);
  1138. struct tm tm = *localtime(&t);
  1139. 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);
  1140. }
  1141. int syncDateTimeRTC(uint8_t *data)
  1142. {
  1143. struct ParsingResult
  1144. {
  1145. int result;
  1146. int scanedElement;
  1147. int year;
  1148. int month;
  1149. int mday;
  1150. int hour;
  1151. int min;
  1152. int sec;
  1153. int tz_hour;
  1154. int tz_min;
  1155. float minSec;
  1156. }result;
  1157. struct tm tmOrg;
  1158. struct tm *tmTarget;
  1159. struct timeb tbTarget;
  1160. char buf[128];
  1161. memset(&result, 0x00, sizeof(struct ParsingResult));
  1162. result.result = PASS;
  1163. if(strstr((char*)data, ".") != NULL)
  1164. {
  1165. // Original data with mini second
  1166. if(strstr((char*)data, "Z") != NULL)
  1167. {
  1168. // Original data with Z
  1169. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1170. &result.year,
  1171. &result.month,
  1172. &result.mday,
  1173. &result.hour,
  1174. &result.min,
  1175. &result.sec,
  1176. &result.minSec);
  1177. }
  1178. else
  1179. {
  1180. // Original data without Z
  1181. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1182. &result.year,
  1183. &result.month,
  1184. &result.mday,
  1185. &result.hour,
  1186. &result.min,
  1187. &result.sec,
  1188. &result.minSec,
  1189. &result.tz_hour,
  1190. &result.tz_min);
  1191. }
  1192. }
  1193. else
  1194. {
  1195. // Original data without mini second
  1196. if(strstr((char*)data, "Z") != NULL)
  1197. {
  1198. // Original data with Z
  1199. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1200. &result.year,
  1201. &result.month,
  1202. &result.mday,
  1203. &result.hour,
  1204. &result.min,
  1205. &result.sec);
  1206. }
  1207. else
  1208. {
  1209. // Original data without Z
  1210. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1211. &result.year,
  1212. &result.month,
  1213. &result.mday,
  1214. &result.hour,
  1215. &result.min,
  1216. &result.sec,
  1217. &result.tz_hour,
  1218. &result.tz_min);
  1219. }
  1220. }
  1221. tmOrg.tm_year = result.year - 1900;
  1222. tmOrg.tm_mon = result.month - 1;
  1223. tmOrg.tm_mday = result.mday;
  1224. tmOrg.tm_hour = result.hour;
  1225. tmOrg.tm_min = result.min;
  1226. tmOrg.tm_sec = result.sec;
  1227. tmOrg.tm_gmtoff = 0;
  1228. tbTarget.time = mktime(&tmOrg);
  1229. tbTarget.timezone = 0;
  1230. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1231. tmTarget = gmtime(&tbTarget.time);
  1232. 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);
  1233. //DEBUG_INFO(" org date time: %s\n", data);
  1234. //DEBUG_INFO("parse date time: %s\n", buf);
  1235. system(buf);
  1236. system("/sbin/hwclock -w --systohc");
  1237. if(result.scanedElement < 6)
  1238. result.result = FAIL;
  1239. return result.result;
  1240. }
  1241. //==========================================
  1242. // GetCompositeSchedule logic related function
  1243. //==========================================
  1244. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1245. {
  1246. //return milli-second
  1247. unsigned int StartTime,StopTime;
  1248. StartTime=(unsigned int)ST.time;
  1249. StopTime=(unsigned int)ET.time;
  1250. return (StopTime-StartTime);
  1251. }
  1252. int DiffTimebWithNowSec(struct timeb ST)
  1253. {
  1254. //return milli-second
  1255. struct timeb ET;
  1256. unsigned int StartTime,StopTime;
  1257. ftime(&ET);
  1258. StartTime=(unsigned int)ST.time;
  1259. StopTime=(unsigned int)ET.time;
  1260. return (StopTime-StartTime);
  1261. }
  1262. int getStartStop(uint8_t *start, uint8_t *stop)
  1263. {
  1264. int result = -1;
  1265. struct tm tmStart;
  1266. struct timeb tbStart;
  1267. struct tm tmStop;
  1268. struct timeb tbStop;
  1269. 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) &&
  1270. (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))
  1271. {
  1272. //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);
  1273. //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);
  1274. tmStart.tm_year -= 1900;
  1275. tmStart.tm_mon -= 1;
  1276. tbStart.time = mktime(&tmStart);
  1277. tbStart.millitm = 0;
  1278. tmStop.tm_year -= 1900;
  1279. tmStop.tm_mon -= 1;
  1280. tbStop.time = mktime(&tmStop);
  1281. tbStop.millitm = 0;
  1282. result = DiffTimebSec(tbStart, tbStop);
  1283. //DEBUG_INFO("getStartStop(): %d\n", result);
  1284. }
  1285. else
  1286. {
  1287. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1288. }
  1289. return result;
  1290. }
  1291. int isOvertNow(uint8_t *start)
  1292. {
  1293. int result = NO;
  1294. struct ParsingResult
  1295. {
  1296. int result;
  1297. int scanedElement;
  1298. int year;
  1299. int month;
  1300. int mday;
  1301. int hour;
  1302. int min;
  1303. int sec;
  1304. int tz_hour;
  1305. int tz_min;
  1306. float minSec;
  1307. }parsingResult;
  1308. struct tm tmStart;
  1309. struct timeb tbStart;
  1310. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1311. if(strstr((char*)start, ".") != NULL)
  1312. {
  1313. // Original data with mini second
  1314. if(strstr((char*)start, "Z") != NULL)
  1315. {
  1316. // Original data with Z
  1317. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1318. &parsingResult.year,
  1319. &parsingResult.month,
  1320. &parsingResult.mday,
  1321. &parsingResult.hour,
  1322. &parsingResult.min,
  1323. &parsingResult.sec,
  1324. &parsingResult.minSec);
  1325. }
  1326. else
  1327. {
  1328. // Original data without Z
  1329. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1330. &parsingResult.year,
  1331. &parsingResult.month,
  1332. &parsingResult.mday,
  1333. &parsingResult.hour,
  1334. &parsingResult.min,
  1335. &parsingResult.sec,
  1336. &parsingResult.minSec,
  1337. &parsingResult.tz_hour,
  1338. &parsingResult.tz_min);
  1339. }
  1340. }
  1341. else
  1342. {
  1343. // Original data without mini second
  1344. if(strstr((char*)start, "Z") != NULL)
  1345. {
  1346. // Original data with Z
  1347. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1348. &parsingResult.year,
  1349. &parsingResult.month,
  1350. &parsingResult.mday,
  1351. &parsingResult.hour,
  1352. &parsingResult.min,
  1353. &parsingResult.sec);
  1354. }
  1355. else
  1356. {
  1357. // Original data without Z
  1358. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1359. &parsingResult.year,
  1360. &parsingResult.month,
  1361. &parsingResult.mday,
  1362. &parsingResult.hour,
  1363. &parsingResult.min,
  1364. &parsingResult.sec,
  1365. &parsingResult.tz_hour,
  1366. &parsingResult.tz_min);
  1367. }
  1368. }
  1369. if(parsingResult.scanedElement >= 6)
  1370. {
  1371. tmStart.tm_year = parsingResult.year - 1900;
  1372. tmStart.tm_mon = parsingResult.month - 1;
  1373. tmStart.tm_mday = parsingResult.mday;
  1374. tmStart.tm_hour = parsingResult.hour;
  1375. tmStart.tm_min = parsingResult.min;
  1376. tmStart.tm_sec = parsingResult.sec;
  1377. tmStart.tm_gmtoff = 0;
  1378. tbStart.time = mktime(&tmStart);
  1379. tbStart.timezone = 0;
  1380. tbStart.millitm = 0;
  1381. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1382. if(DiffTimebWithNowSec(tbStart) <= 0)
  1383. result = NO;
  1384. else
  1385. result = YES;
  1386. }
  1387. else
  1388. {
  1389. DEBUG_WARN("Start date parsing error.\n");
  1390. }
  1391. return result;
  1392. }
  1393. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1394. {
  1395. int result = -1;
  1396. struct tm tmStart;
  1397. struct timeb tbStart;
  1398. struct tm tmStop;
  1399. struct timeb tbStop;
  1400. 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) &&
  1401. (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))
  1402. {
  1403. tmStart.tm_year -= 1900;
  1404. tmStart.tm_mon -= 1;
  1405. tbStart.time = mktime(&tmStart);
  1406. tbStart.millitm = 0;
  1407. tmStop.tm_year -= 1900;
  1408. tmStop.tm_mon -= 1;
  1409. tbStop.time = mktime(&tmStop);
  1410. tbStop.millitm = 0;
  1411. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1412. }
  1413. return result;
  1414. }
  1415. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1416. {
  1417. FILE *fp;
  1418. char profileFileName[128];
  1419. char *line = NULL;
  1420. size_t len = 0;
  1421. time_t CurrentTime;
  1422. struct tm *tmComposite;
  1423. struct StructChargingProfile maxProfile;
  1424. uint8_t limitMax=0;
  1425. int compositePeriodIdx = 0;
  1426. CurrentTime = time(NULL);
  1427. tmComposite=localtime(&CurrentTime);
  1428. 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);
  1429. if(isUnitA)
  1430. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1431. else
  1432. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1433. compositeProfile->ChargingSchedule.Duration = durationReq;
  1434. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1435. {
  1436. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1437. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1438. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1439. }
  1440. compositeProfile->ChargingProfileId = 0;
  1441. compositeProfile->StackLevel = 99 ;
  1442. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1443. maxProfile.ChargingProfileId = -1;
  1444. maxProfile.ChargingSchedule.Duration = -1;
  1445. system("rm -f /tmp/*.json");
  1446. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1447. // Search max profile
  1448. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1449. if((access(profileFileName, F_OK))!=-1)
  1450. {
  1451. fp = fopen(profileFileName, "r");
  1452. while(getline(&line, &len, fp) != -1)
  1453. {
  1454. json_object *obj = NULL;
  1455. obj = json_tokener_parse(line);
  1456. if(is_error(obj))
  1457. {
  1458. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1459. }
  1460. else
  1461. {
  1462. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1463. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1464. )
  1465. {
  1466. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1467. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1468. )
  1469. {
  1470. struct tm tmFrom, tmTo;
  1471. struct timeb tbFrom, tbTo;
  1472. 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) &&
  1473. (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))
  1474. {
  1475. tmFrom.tm_year -= 1900;
  1476. tmFrom.tm_mon -= 1;
  1477. tbFrom.time = mktime(&tmFrom);
  1478. tmTo.tm_year -= 1900;
  1479. tmTo.tm_mon -= 1;
  1480. tbTo.time = mktime(&tmTo);
  1481. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1482. {
  1483. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1484. {
  1485. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1486. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1487. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1488. }
  1489. maxProfile.ChargingProfileId = -1;
  1490. maxProfile.StackLevel = -1;
  1491. if(maxProfile.ChargingProfileId == -1)
  1492. DEBUG_INFO("MaxProfile found.\n");
  1493. else
  1494. DEBUG_INFO("MaxProfile updated.\n");
  1495. // Required item
  1496. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1497. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1498. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1499. if(isUnitA)
  1500. {
  1501. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1502. 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++)
  1503. {
  1504. 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"));
  1505. 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?
  1506. 3:
  1507. 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")));
  1508. 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")));
  1509. }
  1510. }
  1511. else
  1512. {
  1513. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1514. 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++)
  1515. {
  1516. 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"));
  1517. 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?
  1518. 3:
  1519. 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")));
  1520. 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));
  1521. }
  1522. }
  1523. // Optional item
  1524. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1525. {
  1526. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1527. }
  1528. else
  1529. {
  1530. sprintf((char*)maxProfile.ValidFrom, " ");
  1531. }
  1532. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1533. {
  1534. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1535. }
  1536. else
  1537. {
  1538. sprintf((char*)maxProfile.ValidTo, " ");
  1539. }
  1540. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1541. {
  1542. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1543. }
  1544. else
  1545. {
  1546. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1547. }
  1548. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1549. {
  1550. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1551. }
  1552. else
  1553. {
  1554. maxProfile.TransactionId = -1;
  1555. }
  1556. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1557. {
  1558. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1559. }
  1560. else
  1561. {
  1562. maxProfile.ChargingSchedule.Duration = 86400;
  1563. }
  1564. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1565. {
  1566. 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")));
  1567. }
  1568. else
  1569. {
  1570. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1571. }
  1572. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1573. {
  1574. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1575. }
  1576. else
  1577. {
  1578. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1579. }
  1580. }
  1581. }
  1582. }
  1583. else
  1584. {
  1585. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1586. {
  1587. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1588. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1589. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1590. }
  1591. maxProfile.ChargingProfileId = -1;
  1592. maxProfile.StackLevel = -1;
  1593. if(maxProfile.ChargingProfileId == -1)
  1594. DEBUG_INFO("MaxProfile found.\n");
  1595. else
  1596. DEBUG_INFO("MaxProfile updated.\n");
  1597. // Required item
  1598. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1599. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1600. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1601. if(isUnitA)
  1602. {
  1603. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1604. 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++)
  1605. {
  1606. 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"));
  1607. 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?
  1608. 3:
  1609. 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")));
  1610. 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")));
  1611. }
  1612. }
  1613. else
  1614. {
  1615. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1616. 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++)
  1617. {
  1618. 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"));
  1619. 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?
  1620. 3:
  1621. 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")));
  1622. 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));
  1623. }
  1624. }
  1625. // Optional item
  1626. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1627. {
  1628. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1629. }
  1630. else
  1631. {
  1632. sprintf((char*)maxProfile.ValidFrom, " ");
  1633. }
  1634. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1635. {
  1636. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1637. }
  1638. else
  1639. {
  1640. sprintf((char*)maxProfile.ValidTo, " ");
  1641. }
  1642. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1643. {
  1644. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1645. }
  1646. else
  1647. {
  1648. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1649. }
  1650. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1651. {
  1652. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1653. }
  1654. else
  1655. {
  1656. maxProfile.TransactionId = -1;
  1657. }
  1658. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1659. {
  1660. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1661. }
  1662. else
  1663. {
  1664. maxProfile.ChargingSchedule.Duration = 86400;
  1665. }
  1666. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1667. {
  1668. 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")));
  1669. }
  1670. else
  1671. {
  1672. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1673. }
  1674. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1675. {
  1676. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1677. }
  1678. else
  1679. {
  1680. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1681. }
  1682. }
  1683. }
  1684. }
  1685. json_object_put(obj);
  1686. }
  1687. fclose(fp);
  1688. /*
  1689. if(maxProfile.ChargingProfileId !=-1)
  1690. {
  1691. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1692. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1693. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1694. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1695. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1696. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1697. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1698. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1699. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1700. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1701. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1702. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1703. {
  1704. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1705. {
  1706. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1707. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1708. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1709. }
  1710. }
  1711. }
  1712. else
  1713. DEBUG_INFO("MaxProfile not found.\n");
  1714. DEBUG_INFO("------------------------------------\n");*/
  1715. }
  1716. if(maxProfile.ChargingProfileId != -1)
  1717. {
  1718. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1719. {
  1720. if(maxProfile.ChargingSchedule.Duration != -1)
  1721. {
  1722. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1723. 0:
  1724. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1725. }
  1726. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1727. {
  1728. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1729. {
  1730. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1731. 0:
  1732. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1733. if(idxPeriod > 0)
  1734. {
  1735. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1736. {
  1737. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1738. }
  1739. }
  1740. }
  1741. }
  1742. }
  1743. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1744. {
  1745. if(maxProfile.ChargingSchedule.Duration != -1)
  1746. {
  1747. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1748. }
  1749. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1750. {
  1751. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1752. {
  1753. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1754. if(idxPeriod > 0)
  1755. {
  1756. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1757. {
  1758. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1759. }
  1760. }
  1761. }
  1762. }
  1763. }
  1764. else
  1765. {
  1766. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1767. {
  1768. if(maxProfile.ChargingSchedule.Duration != -1)
  1769. {
  1770. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1771. 0:
  1772. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1773. }
  1774. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1775. {
  1776. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1777. {
  1778. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1779. 0:
  1780. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1781. if(idxPeriod > 0)
  1782. {
  1783. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1784. {
  1785. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1786. }
  1787. }
  1788. }
  1789. }
  1790. }
  1791. else
  1792. {
  1793. if(maxProfile.ChargingSchedule.Duration != -1)
  1794. {
  1795. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1796. 0:
  1797. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1798. }
  1799. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1800. {
  1801. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1802. {
  1803. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1804. 0:
  1805. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1806. if(idxPeriod > 0)
  1807. {
  1808. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1809. {
  1810. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1811. }
  1812. }
  1813. }
  1814. }
  1815. }
  1816. }
  1817. /*
  1818. DEBUG_INFO("MaxProfile after align.\n");
  1819. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1820. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1821. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1822. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1823. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1824. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1825. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1826. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1827. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1828. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1829. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1830. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1831. {
  1832. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1833. {
  1834. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1835. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1836. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1837. }
  1838. }
  1839. DEBUG_INFO("------------------------------------\n");*/
  1840. }
  1841. // Find each profile period quantity
  1842. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1843. {
  1844. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1845. limitMax = idx+1;
  1846. }
  1847. if(maxProfile.ChargingProfileId != -1)
  1848. {
  1849. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1850. {
  1851. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1852. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1853. (maxProfile.ChargingSchedule.Duration > 0))
  1854. {
  1855. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1856. {
  1857. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1858. compositePeriodIdx++;
  1859. }
  1860. else
  1861. {
  1862. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1863. }
  1864. }
  1865. }
  1866. }
  1867. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1868. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1869. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1870. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1871. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1872. {
  1873. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1874. {
  1875. compositeProfile->ChargingProfileId = 1;
  1876. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1877. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1878. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1879. }
  1880. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1881. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1882. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1883. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1884. }
  1885. if(line)
  1886. free(line);
  1887. }
  1888. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1889. {
  1890. FILE *fp;
  1891. char profileFileName[128];
  1892. char *line = NULL;
  1893. size_t len = 0;
  1894. time_t CurrentTime;
  1895. struct tm *tmComposite;
  1896. struct StructChargingProfile maxProfile;
  1897. struct StructChargingProfile defaultTxProfile;
  1898. struct StructChargingProfile txProfile;
  1899. struct StructChargingSchedulePeriod tmpPeriod;
  1900. uint8_t limitMax=0;
  1901. uint8_t limitDef=0;
  1902. uint8_t limitTx=0;
  1903. int compositePeriodIdx = 0;
  1904. CurrentTime = time(NULL);
  1905. tmComposite=localtime(&CurrentTime);
  1906. 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);
  1907. if(isUnitA)
  1908. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1909. else
  1910. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1911. compositeProfile->ChargingSchedule.Duration = durationReq;
  1912. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1913. {
  1914. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1915. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1916. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1917. }
  1918. compositeProfile->ChargingProfileId = 0;
  1919. compositeProfile->StackLevel = 99 ;
  1920. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1921. maxProfile.ChargingProfileId = -1;
  1922. defaultTxProfile.ChargingProfileId = -1;
  1923. txProfile.ChargingProfileId = -1;
  1924. maxProfile.ChargingSchedule.Duration = -1;
  1925. defaultTxProfile.ChargingSchedule.Duration = -1;
  1926. txProfile.ChargingSchedule.Duration = -1;
  1927. system("rm -f /tmp/*.json");
  1928. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1929. /*
  1930. * Search valid charging profile
  1931. */
  1932. //DEBUG_INFO("====================================\n");
  1933. // Search tx profile
  1934. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1935. if((access(profileFileName, F_OK))!=-1)
  1936. {
  1937. fp = fopen(profileFileName, "r");
  1938. while(getline(&line, &len, fp) != -1)
  1939. {
  1940. json_object *obj = NULL;
  1941. obj = json_tokener_parse(line);
  1942. if(is_error(obj))
  1943. {
  1944. DEBUG_ERROR("Parse txProfile from file error.\n");
  1945. }
  1946. else
  1947. {
  1948. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1949. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1950. )
  1951. {
  1952. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1953. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1954. )
  1955. {
  1956. struct tm tmFrom, tmTo;
  1957. struct timeb tbFrom, tbTo;
  1958. 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) &&
  1959. (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))
  1960. {
  1961. tmFrom.tm_year -= 1900;
  1962. tmFrom.tm_mon -= 1;
  1963. tbFrom.time = mktime(&tmFrom);
  1964. tmTo.tm_year -= 1900;
  1965. tmTo.tm_mon -= 1;
  1966. tbTo.time = mktime(&tmTo);
  1967. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1968. {
  1969. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1970. {
  1971. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1972. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1973. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1974. }
  1975. txProfile.ChargingProfileId = -1;
  1976. txProfile.StackLevel = -1;
  1977. if(txProfile.ChargingProfileId == -1)
  1978. DEBUG_INFO("TxProfile found.\n");
  1979. else
  1980. DEBUG_INFO("TxProfile updated.\n");
  1981. // Required item
  1982. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1983. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1984. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1985. if(isUnitA)
  1986. {
  1987. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1988. 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++)
  1989. {
  1990. 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"));
  1991. 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?
  1992. 3:
  1993. 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")));
  1994. 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")));
  1995. }
  1996. }
  1997. else
  1998. {
  1999. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2000. 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++)
  2001. {
  2002. 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"));
  2003. 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?
  2004. 3:
  2005. 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")));
  2006. 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));
  2007. }
  2008. }
  2009. // Optional item
  2010. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2011. {
  2012. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2013. }
  2014. else
  2015. {
  2016. sprintf((char*)txProfile.ValidFrom, " ");
  2017. }
  2018. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2019. {
  2020. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2021. }
  2022. else
  2023. {
  2024. sprintf((char*)txProfile.ValidTo, " ");
  2025. }
  2026. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2027. {
  2028. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2029. }
  2030. else
  2031. {
  2032. sprintf((char*)txProfile.RecurrencyKind, " ");
  2033. }
  2034. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2035. {
  2036. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2037. }
  2038. else
  2039. {
  2040. txProfile.TransactionId = -1;
  2041. }
  2042. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2043. {
  2044. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2045. }
  2046. else
  2047. {
  2048. txProfile.ChargingSchedule.Duration = 86400;
  2049. }
  2050. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2051. {
  2052. 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")));
  2053. }
  2054. else
  2055. {
  2056. 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));
  2057. }
  2058. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2059. {
  2060. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2061. }
  2062. else
  2063. {
  2064. txProfile.ChargingSchedule.MinChargingRate = -1;
  2065. }
  2066. }
  2067. }
  2068. }
  2069. else
  2070. {
  2071. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2072. {
  2073. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2074. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2075. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2076. }
  2077. txProfile.ChargingProfileId = -1;
  2078. txProfile.StackLevel = -1;
  2079. if(txProfile.ChargingProfileId == -1)
  2080. DEBUG_INFO("TxProfile found.\n");
  2081. else
  2082. DEBUG_INFO("TxProfile updated.\n");
  2083. // Required item
  2084. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2085. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2086. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2087. if(isUnitA)
  2088. {
  2089. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2090. 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++)
  2091. {
  2092. 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"));
  2093. 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?
  2094. 3:
  2095. 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")));
  2096. 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")));
  2097. }
  2098. }
  2099. else
  2100. {
  2101. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2102. 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++)
  2103. {
  2104. 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"));
  2105. 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?
  2106. 3:
  2107. 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")));
  2108. 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));
  2109. }
  2110. }
  2111. // Optional item
  2112. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2113. {
  2114. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2115. }
  2116. else
  2117. {
  2118. sprintf((char*)txProfile.ValidFrom, " ");
  2119. }
  2120. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2121. {
  2122. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2123. }
  2124. else
  2125. {
  2126. sprintf((char*)txProfile.ValidTo, " ");
  2127. }
  2128. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2129. {
  2130. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2131. }
  2132. else
  2133. {
  2134. sprintf((char*)txProfile.RecurrencyKind, " ");
  2135. }
  2136. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2137. {
  2138. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2139. }
  2140. else
  2141. {
  2142. txProfile.TransactionId = -1;
  2143. }
  2144. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2145. {
  2146. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2147. }
  2148. else
  2149. {
  2150. txProfile.ChargingSchedule.Duration = 86400;
  2151. }
  2152. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2153. {
  2154. 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")));
  2155. }
  2156. else
  2157. {
  2158. 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));
  2159. }
  2160. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2161. {
  2162. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2163. }
  2164. else
  2165. {
  2166. txProfile.ChargingSchedule.MinChargingRate = -1;
  2167. }
  2168. }
  2169. }
  2170. }
  2171. json_object_put(obj);
  2172. }
  2173. fclose(fp);
  2174. /*
  2175. if(txProfile.ChargingProfileId != -1)
  2176. {
  2177. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2178. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2179. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2180. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2181. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2182. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2183. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2184. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2185. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2186. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2187. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2188. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2189. {
  2190. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2191. {
  2192. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2193. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2194. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2195. }
  2196. }
  2197. }
  2198. else
  2199. DEBUG_INFO("TxProfile not found.\n");*/
  2200. }
  2201. // Search default tx profile
  2202. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2203. if((access(profileFileName, F_OK))==-1)
  2204. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2205. if((access(profileFileName, F_OK))!=-1)
  2206. {
  2207. fp = fopen(profileFileName, "r");
  2208. while(getline(&line, &len, fp) != -1)
  2209. {
  2210. json_object *obj = NULL;
  2211. obj = json_tokener_parse(line);
  2212. if(is_error(obj))
  2213. {
  2214. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2215. }
  2216. else
  2217. {
  2218. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2219. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2220. )
  2221. {
  2222. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2223. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2224. )
  2225. {
  2226. struct tm tmFrom, tmTo;
  2227. struct timeb tbFrom, tbTo;
  2228. 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) &&
  2229. (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))
  2230. {
  2231. tmFrom.tm_year -= 1900;
  2232. tmFrom.tm_mon -= 1;
  2233. tbFrom.time = mktime(&tmFrom);
  2234. tmTo.tm_year -= 1900;
  2235. tmTo.tm_mon -= 1;
  2236. tbTo.time = mktime(&tmTo);
  2237. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2238. {
  2239. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2240. {
  2241. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2242. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2243. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2244. }
  2245. defaultTxProfile.ChargingProfileId = -1;
  2246. defaultTxProfile.StackLevel = -1;
  2247. if(defaultTxProfile.ChargingProfileId == -1)
  2248. DEBUG_INFO("TxDefaultProfile found.\n");
  2249. else
  2250. DEBUG_INFO("TxDefaultProfile updated.\n");
  2251. // Required item
  2252. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2253. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2254. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2255. if(isUnitA)
  2256. {
  2257. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2258. 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++)
  2259. {
  2260. 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"));
  2261. 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?
  2262. 3:
  2263. 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")));
  2264. 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")));
  2265. }
  2266. }
  2267. else
  2268. {
  2269. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2270. 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++)
  2271. {
  2272. 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"));
  2273. 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?
  2274. 3:
  2275. 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")));
  2276. 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));
  2277. }
  2278. }
  2279. // Optional item
  2280. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2281. {
  2282. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2283. }
  2284. else
  2285. {
  2286. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2287. }
  2288. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2289. {
  2290. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2291. }
  2292. else
  2293. {
  2294. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2295. }
  2296. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2297. {
  2298. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2299. }
  2300. else
  2301. {
  2302. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2303. }
  2304. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2305. {
  2306. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2307. }
  2308. else
  2309. {
  2310. defaultTxProfile.TransactionId = -1;
  2311. }
  2312. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2313. {
  2314. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2315. }
  2316. else
  2317. {
  2318. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2319. }
  2320. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2321. {
  2322. 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")));
  2323. }
  2324. else
  2325. {
  2326. 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));
  2327. }
  2328. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2329. {
  2330. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2331. }
  2332. else
  2333. {
  2334. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2335. }
  2336. }
  2337. }
  2338. }
  2339. else
  2340. {
  2341. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2342. {
  2343. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2344. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2345. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2346. }
  2347. defaultTxProfile.ChargingProfileId = -1;
  2348. defaultTxProfile.StackLevel = -1;
  2349. if(defaultTxProfile.ChargingProfileId == -1)
  2350. DEBUG_INFO("TxDefaultProfile found.\n");
  2351. else
  2352. DEBUG_INFO("TxDefaultProfile updated.\n");
  2353. // Required item
  2354. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2355. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2356. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2357. if(isUnitA)
  2358. {
  2359. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2360. 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++)
  2361. {
  2362. 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"));
  2363. 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?
  2364. 3:
  2365. 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")));
  2366. 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")));
  2367. }
  2368. }
  2369. else
  2370. {
  2371. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2372. 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++)
  2373. {
  2374. 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"));
  2375. 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?
  2376. 3:
  2377. 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")));
  2378. 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));
  2379. }
  2380. }
  2381. // Optional item
  2382. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2383. {
  2384. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2385. }
  2386. else
  2387. {
  2388. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2389. }
  2390. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2391. {
  2392. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2393. }
  2394. else
  2395. {
  2396. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2397. }
  2398. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2399. {
  2400. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2401. }
  2402. else
  2403. {
  2404. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2405. }
  2406. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2407. {
  2408. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2409. }
  2410. else
  2411. {
  2412. defaultTxProfile.TransactionId = -1;
  2413. }
  2414. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2415. {
  2416. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2417. }
  2418. else
  2419. {
  2420. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2421. }
  2422. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2423. {
  2424. 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")));
  2425. }
  2426. else
  2427. {
  2428. 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));
  2429. }
  2430. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2431. {
  2432. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2433. }
  2434. else
  2435. {
  2436. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2437. }
  2438. }
  2439. }
  2440. }
  2441. json_object_put(obj);
  2442. }
  2443. fclose(fp);
  2444. /*
  2445. if(defaultTxProfile.ChargingProfileId != -1)
  2446. {
  2447. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2448. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2449. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2450. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2451. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2452. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2453. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2454. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2455. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2456. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2457. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2458. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2459. {
  2460. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2461. {
  2462. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2463. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2464. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2465. }
  2466. }
  2467. }
  2468. else
  2469. DEBUG_INFO("TxDefaultProfile not found.\n");
  2470. DEBUG_INFO("------------------------------------\n");*/
  2471. }
  2472. // Search max profile
  2473. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2474. if((access(profileFileName, F_OK))!=-1)
  2475. {
  2476. fp = fopen(profileFileName, "r");
  2477. while(getline(&line, &len, fp) != -1)
  2478. {
  2479. json_object *obj = NULL;
  2480. obj = json_tokener_parse(line);
  2481. if(is_error(obj))
  2482. {
  2483. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2484. }
  2485. else
  2486. {
  2487. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2488. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2489. )
  2490. {
  2491. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2492. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2493. )
  2494. {
  2495. struct tm tmFrom, tmTo;
  2496. struct timeb tbFrom, tbTo;
  2497. 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) &&
  2498. (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))
  2499. {
  2500. tmFrom.tm_year -= 1900;
  2501. tmFrom.tm_mon -= 1;
  2502. tbFrom.time = mktime(&tmFrom);
  2503. tmTo.tm_year -= 1900;
  2504. tmTo.tm_mon -= 1;
  2505. tbTo.time = mktime(&tmTo);
  2506. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2507. {
  2508. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2509. {
  2510. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2511. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2512. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2513. }
  2514. maxProfile.ChargingProfileId = -1;
  2515. maxProfile.StackLevel = -1;
  2516. if(maxProfile.ChargingProfileId == -1)
  2517. DEBUG_INFO("MaxProfile found.\n");
  2518. else
  2519. DEBUG_INFO("MaxProfile updated.\n");
  2520. // Required item
  2521. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2522. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2523. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2524. if(isUnitA)
  2525. {
  2526. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2527. 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++)
  2528. {
  2529. 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"));
  2530. 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?
  2531. 3:
  2532. 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")));
  2533. 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")));
  2534. }
  2535. }
  2536. else
  2537. {
  2538. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2539. 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++)
  2540. {
  2541. 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"));
  2542. 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?
  2543. 3:
  2544. 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")));
  2545. 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));
  2546. }
  2547. }
  2548. // Optional item
  2549. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2550. {
  2551. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2552. }
  2553. else
  2554. {
  2555. sprintf((char*)maxProfile.ValidFrom, " ");
  2556. }
  2557. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2558. {
  2559. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2560. }
  2561. else
  2562. {
  2563. sprintf((char*)maxProfile.ValidTo, " ");
  2564. }
  2565. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2566. {
  2567. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2568. }
  2569. else
  2570. {
  2571. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2572. }
  2573. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2574. {
  2575. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2576. }
  2577. else
  2578. {
  2579. maxProfile.TransactionId = -1;
  2580. }
  2581. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2582. {
  2583. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2584. }
  2585. else
  2586. {
  2587. maxProfile.ChargingSchedule.Duration = 86400;
  2588. }
  2589. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2590. {
  2591. 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")));
  2592. }
  2593. else
  2594. {
  2595. 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));
  2596. }
  2597. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2598. {
  2599. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2600. }
  2601. else
  2602. {
  2603. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2604. }
  2605. }
  2606. }
  2607. }
  2608. else
  2609. {
  2610. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2611. {
  2612. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2613. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2614. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2615. }
  2616. maxProfile.ChargingProfileId = -1;
  2617. maxProfile.StackLevel = -1;
  2618. if(maxProfile.ChargingProfileId == -1)
  2619. DEBUG_INFO("MaxProfile found.\n");
  2620. else
  2621. DEBUG_INFO("MaxProfile updated.\n");
  2622. // Required item
  2623. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2624. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2625. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2626. if(isUnitA)
  2627. {
  2628. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2629. 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++)
  2630. {
  2631. 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"));
  2632. 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?
  2633. 3:
  2634. 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")));
  2635. 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")));
  2636. }
  2637. }
  2638. else
  2639. {
  2640. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2641. 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++)
  2642. {
  2643. 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"));
  2644. 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?
  2645. 3:
  2646. 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")));
  2647. 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));
  2648. }
  2649. }
  2650. // Optional item
  2651. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2652. {
  2653. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2654. }
  2655. else
  2656. {
  2657. sprintf((char*)maxProfile.ValidFrom, " ");
  2658. }
  2659. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2660. {
  2661. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2662. }
  2663. else
  2664. {
  2665. sprintf((char*)maxProfile.ValidTo, " ");
  2666. }
  2667. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2668. {
  2669. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2670. }
  2671. else
  2672. {
  2673. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2674. }
  2675. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2676. {
  2677. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2678. }
  2679. else
  2680. {
  2681. maxProfile.TransactionId = -1;
  2682. }
  2683. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2684. {
  2685. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2686. }
  2687. else
  2688. {
  2689. maxProfile.ChargingSchedule.Duration = 86400;
  2690. }
  2691. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2692. {
  2693. 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")));
  2694. }
  2695. else
  2696. {
  2697. 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));
  2698. }
  2699. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2700. {
  2701. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2702. }
  2703. else
  2704. {
  2705. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2706. }
  2707. }
  2708. }
  2709. }
  2710. json_object_put(obj);
  2711. }
  2712. fclose(fp);
  2713. /*
  2714. if(maxProfile.ChargingProfileId !=-1)
  2715. {
  2716. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2717. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2718. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2719. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2720. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2721. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2722. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2723. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2724. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2725. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2726. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2727. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2728. {
  2729. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2730. {
  2731. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2732. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2733. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2734. }
  2735. }
  2736. }
  2737. else
  2738. DEBUG_INFO("MaxProfile not found.\n");
  2739. DEBUG_INFO("------------------------------------\n");*/
  2740. }
  2741. /*
  2742. * Align found profile start schedule & periods
  2743. */
  2744. //DEBUG_INFO("====================================\n");
  2745. /*
  2746. // For local test usage, force modify found profile start schedule info
  2747. 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);
  2748. 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);
  2749. 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);
  2750. */
  2751. if(txProfile.ChargingProfileId != -1)
  2752. {
  2753. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2754. {
  2755. if(txProfile.ChargingSchedule.Duration != -1)
  2756. {
  2757. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2758. 0:
  2759. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2760. }
  2761. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2762. {
  2763. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2764. {
  2765. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2766. 0:
  2767. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2768. if(idxPeriod > 0)
  2769. {
  2770. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2771. {
  2772. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2773. }
  2774. }
  2775. }
  2776. }
  2777. }
  2778. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2779. {
  2780. if(txProfile.ChargingSchedule.Duration != -1)
  2781. {
  2782. 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?
  2783. 0:
  2784. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2785. }
  2786. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2787. {
  2788. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2789. {
  2790. 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?
  2791. 0:
  2792. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2793. if(idxPeriod > 0)
  2794. {
  2795. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2796. {
  2797. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2798. }
  2799. }
  2800. }
  2801. }
  2802. }
  2803. else
  2804. {
  2805. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2806. {
  2807. if(txProfile.ChargingSchedule.Duration != -1)
  2808. {
  2809. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2810. 0:
  2811. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2812. }
  2813. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2814. {
  2815. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2816. {
  2817. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2818. 0:
  2819. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2820. if(idxPeriod > 0)
  2821. {
  2822. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2823. {
  2824. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2825. }
  2826. }
  2827. }
  2828. }
  2829. }
  2830. else
  2831. {
  2832. if(txProfile.ChargingSchedule.Duration != -1)
  2833. {
  2834. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2835. 0:
  2836. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2837. }
  2838. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2839. {
  2840. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2841. {
  2842. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2843. 0:
  2844. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2845. if(idxPeriod > 0)
  2846. {
  2847. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2848. {
  2849. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2850. }
  2851. }
  2852. }
  2853. }
  2854. }
  2855. }
  2856. /*
  2857. DEBUG_INFO("txProfile after align.\n");
  2858. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2859. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2860. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2861. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2862. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2863. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2864. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2865. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2866. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2867. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2868. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2869. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2870. {
  2871. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2872. {
  2873. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2874. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2875. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2876. }
  2877. }*/
  2878. }
  2879. if(defaultTxProfile.ChargingProfileId != -1)
  2880. {
  2881. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2882. {
  2883. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2884. {
  2885. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2886. 0:
  2887. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2888. }
  2889. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2890. {
  2891. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2892. {
  2893. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2894. 0:
  2895. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2896. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2897. {
  2898. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2899. }
  2900. if(idxPeriod > 0)
  2901. {
  2902. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2903. {
  2904. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2905. }
  2906. }
  2907. }
  2908. }
  2909. }
  2910. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2911. {
  2912. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2913. {
  2914. 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?
  2915. 0:
  2916. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2917. }
  2918. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2919. {
  2920. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2921. {
  2922. 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?
  2923. 0:
  2924. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2925. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2926. {
  2927. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2928. }
  2929. if(idxPeriod > 0)
  2930. {
  2931. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2932. {
  2933. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2934. }
  2935. }
  2936. }
  2937. }
  2938. }
  2939. else
  2940. {
  2941. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2942. {
  2943. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2944. {
  2945. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2946. 0:
  2947. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2948. }
  2949. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2950. {
  2951. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2952. {
  2953. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2954. 0:
  2955. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2956. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2957. {
  2958. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2959. }
  2960. if(idxPeriod > 0)
  2961. {
  2962. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2963. {
  2964. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2965. }
  2966. }
  2967. }
  2968. }
  2969. }
  2970. else
  2971. {
  2972. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2973. {
  2974. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2975. 0:
  2976. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2977. }
  2978. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2979. {
  2980. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2981. {
  2982. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2983. 0:
  2984. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2985. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2986. {
  2987. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2988. }
  2989. if(idxPeriod > 0)
  2990. {
  2991. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2992. {
  2993. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2994. }
  2995. }
  2996. }
  2997. }
  2998. }
  2999. }
  3000. /*
  3001. DEBUG_INFO("defaultTxProfile after align.\n");
  3002. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3003. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3004. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3005. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3006. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3007. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3008. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3009. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3010. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3011. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3012. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3013. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3014. {
  3015. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3016. {
  3017. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3018. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3019. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3020. }
  3021. }
  3022. DEBUG_INFO("------------------------------------\n");*/
  3023. }
  3024. if(maxProfile.ChargingProfileId != -1)
  3025. {
  3026. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3027. {
  3028. if(maxProfile.ChargingSchedule.Duration != -1)
  3029. {
  3030. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  3031. 0:
  3032. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  3033. }
  3034. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3035. {
  3036. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3037. {
  3038. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  3039. 0:
  3040. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  3041. if(idxPeriod > 0)
  3042. {
  3043. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3044. {
  3045. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3046. }
  3047. }
  3048. }
  3049. }
  3050. }
  3051. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3052. {
  3053. if(maxProfile.ChargingSchedule.Duration != -1)
  3054. {
  3055. 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?
  3056. 0:
  3057. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  3058. }
  3059. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3060. {
  3061. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3062. {
  3063. 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?
  3064. 0:
  3065. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  3066. if(idxPeriod > 0)
  3067. {
  3068. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3069. {
  3070. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3071. }
  3072. }
  3073. }
  3074. }
  3075. }
  3076. else
  3077. {
  3078. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3079. {
  3080. if(maxProfile.ChargingSchedule.Duration != -1)
  3081. {
  3082. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  3083. 0:
  3084. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  3085. }
  3086. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3087. {
  3088. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3089. {
  3090. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  3091. 0:
  3092. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  3093. if(idxPeriod > 0)
  3094. {
  3095. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3096. {
  3097. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3098. }
  3099. }
  3100. }
  3101. }
  3102. }
  3103. else
  3104. {
  3105. if(maxProfile.ChargingSchedule.Duration != -1)
  3106. {
  3107. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  3108. 0:
  3109. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  3110. }
  3111. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3112. {
  3113. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3114. {
  3115. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  3116. 0:
  3117. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  3118. if(idxPeriod > 0)
  3119. {
  3120. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3121. {
  3122. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3123. }
  3124. }
  3125. }
  3126. }
  3127. }
  3128. }
  3129. /*
  3130. DEBUG_INFO("MaxProfile after align.\n");
  3131. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3132. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3133. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3134. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3135. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3136. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3137. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3138. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3139. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3140. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3141. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3142. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3143. {
  3144. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3145. {
  3146. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3147. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3148. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3149. }
  3150. }
  3151. DEBUG_INFO("------------------------------------\n");*/
  3152. }
  3153. /*
  3154. * Merge to conposite schedule
  3155. */
  3156. //DEBUG_INFO("====================================\n");
  3157. // Find each profile period quantity
  3158. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3159. {
  3160. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3161. limitMax = idx+1;
  3162. }
  3163. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3164. {
  3165. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3166. limitDef = idx+1;
  3167. }
  3168. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3169. {
  3170. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3171. limitTx = idx+1;
  3172. }
  3173. // TxProfile found, composite schedule based on it
  3174. if(txProfile.ChargingProfileId != -1)
  3175. {
  3176. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3177. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3178. {
  3179. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3180. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3181. (txProfile.ChargingSchedule.Duration > 0))
  3182. {
  3183. if(maxProfile.ChargingProfileId != -1)
  3184. {
  3185. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3186. {
  3187. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3188. {
  3189. if((maxProfile.ChargingSchedule.Duration > 0))
  3190. {
  3191. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3192. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3193. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3194. }
  3195. else
  3196. {
  3197. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3198. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3199. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3200. }
  3201. }
  3202. if(idxMaxPeriod == (limitMax-1))
  3203. {
  3204. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3205. {
  3206. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3207. {
  3208. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3209. compositePeriodIdx++;
  3210. }
  3211. else
  3212. {
  3213. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3214. }
  3215. }
  3216. }
  3217. }
  3218. }
  3219. else
  3220. {
  3221. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3222. {
  3223. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3224. compositePeriodIdx++;
  3225. }
  3226. else
  3227. {
  3228. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3229. }
  3230. }
  3231. }
  3232. if(idxTxPeriod == (limitTx-1))
  3233. {
  3234. if(defaultTxProfile.ChargingProfileId != -1)
  3235. {
  3236. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  3237. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3238. {
  3239. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3240. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3241. (defaultTxProfile.ChargingSchedule.Duration>0))
  3242. {
  3243. if(maxProfile.ChargingProfileId != -1)
  3244. {
  3245. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3246. {
  3247. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3248. {
  3249. if((maxProfile.ChargingSchedule.Duration > 0))
  3250. {
  3251. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3252. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3253. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3254. }
  3255. else
  3256. {
  3257. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3258. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3259. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3260. }
  3261. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3262. {
  3263. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3264. {
  3265. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3266. compositePeriodIdx++;
  3267. }
  3268. else
  3269. {
  3270. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3271. }
  3272. }
  3273. // Delete duplicate period
  3274. if(compositePeriodIdx > 1)
  3275. {
  3276. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3277. {
  3278. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3279. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3280. compositePeriodIdx -= 1;
  3281. }
  3282. }
  3283. }
  3284. else
  3285. {
  3286. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3287. {
  3288. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3289. compositePeriodIdx++;
  3290. }
  3291. else
  3292. {
  3293. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3294. }
  3295. break;
  3296. }
  3297. }
  3298. }
  3299. else
  3300. {
  3301. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3302. {
  3303. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3304. compositePeriodIdx++;
  3305. }
  3306. else
  3307. {
  3308. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3309. }
  3310. }
  3311. }
  3312. }
  3313. }
  3314. }
  3315. }
  3316. }
  3317. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3318. else if(defaultTxProfile.ChargingProfileId != -1)
  3319. {
  3320. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3321. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3322. {
  3323. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3324. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3325. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3326. {
  3327. if(maxProfile.ChargingProfileId != -1)
  3328. {
  3329. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3330. {
  3331. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3332. {
  3333. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3334. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3335. if((maxProfile.ChargingSchedule.Duration > 0))
  3336. {
  3337. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3338. }
  3339. else
  3340. {
  3341. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3342. }
  3343. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3344. {
  3345. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3346. {
  3347. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3348. compositePeriodIdx++;
  3349. }
  3350. else
  3351. {
  3352. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3353. }
  3354. }
  3355. // Delete duplicate period
  3356. if(compositePeriodIdx > 1)
  3357. {
  3358. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3359. {
  3360. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3361. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3362. compositePeriodIdx -= 1;
  3363. }
  3364. }
  3365. }
  3366. else
  3367. {
  3368. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3369. {
  3370. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3371. compositePeriodIdx++;
  3372. }
  3373. else
  3374. {
  3375. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3376. }
  3377. break;
  3378. }
  3379. }
  3380. }
  3381. else
  3382. {
  3383. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3384. {
  3385. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3386. compositePeriodIdx++;
  3387. }
  3388. else
  3389. {
  3390. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3391. }
  3392. }
  3393. }
  3394. }
  3395. }
  3396. // Fill other period by MaxProfile
  3397. if(maxProfile.ChargingProfileId != -1)
  3398. {
  3399. if(compositePeriodIdx==0)
  3400. {
  3401. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3402. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3403. {
  3404. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3405. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3406. (maxProfile.ChargingSchedule.Duration > 0))
  3407. {
  3408. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3409. {
  3410. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3411. compositePeriodIdx++;
  3412. }
  3413. else
  3414. {
  3415. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3416. }
  3417. }
  3418. }
  3419. }
  3420. else
  3421. {
  3422. int lastCompositePeriodIdx = compositePeriodIdx;
  3423. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3424. {
  3425. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3426. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3427. (maxProfile.ChargingSchedule.Duration > 0))
  3428. {
  3429. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3430. {
  3431. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3432. {
  3433. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3434. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3435. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3436. }
  3437. else
  3438. {
  3439. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3440. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3441. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3442. }
  3443. }
  3444. if(tmpPeriod.Limit != -1)
  3445. {
  3446. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3447. {
  3448. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3449. {
  3450. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3451. compositePeriodIdx++;
  3452. }
  3453. else
  3454. {
  3455. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3456. }
  3457. }
  3458. // Delete duplicate period
  3459. if(compositePeriodIdx > 1)
  3460. {
  3461. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3462. {
  3463. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3464. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3465. compositePeriodIdx -= 1;
  3466. }
  3467. }
  3468. }
  3469. }
  3470. }
  3471. }
  3472. }
  3473. compositeProfile->ChargingSchedule.Duration = durationReq;
  3474. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3475. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3476. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3477. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3478. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3479. {
  3480. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3481. {
  3482. compositeProfile->ChargingProfileId = 1;
  3483. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3484. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3485. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3486. }
  3487. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3488. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3489. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3490. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3491. }
  3492. if(line)
  3493. free(line);
  3494. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3495. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3496. }
  3497. //==========================================
  3498. // Init all share memory
  3499. //==========================================
  3500. int InitShareMemory()
  3501. {
  3502. int result = PASS;
  3503. int MeterSMId;
  3504. //creat ShmSysConfigAndInfo
  3505. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3506. {
  3507. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3508. result = FAIL;
  3509. }
  3510. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3511. {
  3512. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3513. result = FAIL;
  3514. }
  3515. else
  3516. {}
  3517. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3518. {
  3519. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3520. result = FAIL;
  3521. }
  3522. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3523. {
  3524. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3525. result = FAIL;
  3526. }
  3527. else
  3528. {}
  3529. //creat ShmPsuData
  3530. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3531. {
  3532. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3533. result = FAIL;
  3534. }
  3535. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3536. {
  3537. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3538. result = FAIL;
  3539. }
  3540. else
  3541. {}
  3542. //creat ShmOCPP16Data
  3543. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3544. {
  3545. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3546. result = FAIL;
  3547. }
  3548. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3549. {
  3550. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3551. result = FAIL;
  3552. }
  3553. else
  3554. {}
  3555. /****************************** For Initial Settings************************************************/
  3556. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3557. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3558. // allocate Configuration memory address
  3559. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3560. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3561. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3562. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3563. //offline MeterValue Interval
  3564. TempMeterValueInterval = 0;
  3565. return result;
  3566. }
  3567. int ProcessShareMemory()
  3568. {
  3569. int result = PASS;
  3570. if(InitShareMemory() == FAIL)
  3571. {
  3572. DEBUG_ERROR("InitShareMemory NG\n");
  3573. if(ShmStatusCodeData!=NULL)
  3574. {
  3575. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3576. }
  3577. result = FAIL;
  3578. }
  3579. // Model name parsing
  3580. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3581. {
  3582. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3583. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3584. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3585. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3586. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3587. ) // 'D' means DC
  3588. {
  3589. // DO series
  3590. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3591. {
  3592. SystemInitial += 1;
  3593. gunTotalNumber += 1;
  3594. gunType[gun_index] = GUN_TYPE_DO;
  3595. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3596. {
  3597. case Gun_Type_Chademo:
  3598. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3599. break;
  3600. case Gun_Type_CCS_2:
  3601. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3602. break;
  3603. case Gun_Type_GB:
  3604. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3605. break;
  3606. case Gun_Type_AC:
  3607. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3608. break;
  3609. default:
  3610. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3611. break;
  3612. }
  3613. }
  3614. }
  3615. else
  3616. {
  3617. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3618. {
  3619. SystemInitial += 1;
  3620. gunTotalNumber += 1;
  3621. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3622. {
  3623. case Gun_Type_Chademo:
  3624. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3625. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3626. break;
  3627. case Gun_Type_CCS_2:
  3628. gunType[gun_index] = GUN_TYPE_CCS;
  3629. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3630. break;
  3631. case Gun_Type_GB:
  3632. gunType[gun_index] = GUN_TYPE_GBT;
  3633. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3634. break;
  3635. case Gun_Type_AC:
  3636. gunType[gun_index] = GUN_TYPE_AC;
  3637. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3638. break;
  3639. default:
  3640. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3641. break;
  3642. }
  3643. }
  3644. }
  3645. }
  3646. else
  3647. {
  3648. DEBUG_ERROR("Model name parsing fail.\n");
  3649. result = FAIL;
  3650. }
  3651. if(result != PASS)sleep(5);
  3652. return result;
  3653. }
  3654. void checkRemoteStart(uint8_t connectorIdInt)
  3655. {
  3656. uint8_t tempIndex;
  3657. int result = PASS;
  3658. char cmdBuf[512];
  3659. //check Transaction active
  3660. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3661. {
  3662. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3663. {
  3664. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3665. }
  3666. else
  3667. {
  3668. tempIndex = connectorIdInt -1;
  3669. }
  3670. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3671. {
  3672. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3673. {
  3674. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3675. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3676. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3677. {
  3678. //Reserved
  3679. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3680. }
  3681. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3682. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3683. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3684. {
  3685. //Reserved
  3686. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3687. result = FAIL;
  3688. goto end;
  3689. }
  3690. else
  3691. {
  3692. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3693. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3694. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3695. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3696. {
  3697. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  3698. result = FAIL;
  3699. goto end;
  3700. }
  3701. }//END FOR ELSE
  3702. }
  3703. }// END FOR CHAdeMO_QUANTITY
  3704. }
  3705. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3706. {
  3707. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3708. {
  3709. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3710. }
  3711. else
  3712. {
  3713. tempIndex = connectorIdInt -1;
  3714. }
  3715. for (int index = 0; index < CCS_QUANTITY; index++)
  3716. {
  3717. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3718. {
  3719. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3720. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3721. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3722. {
  3723. //Reserved
  3724. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3725. }
  3726. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3727. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3728. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3729. {
  3730. //Reserved
  3731. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3732. result = FAIL;
  3733. goto end;
  3734. }
  3735. else
  3736. {
  3737. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3738. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3739. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3740. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3741. {
  3742. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3743. result = FAIL;
  3744. goto end;
  3745. }
  3746. }// END FOR ELSE
  3747. }
  3748. }// END FOR CCS_QUANTITY
  3749. }
  3750. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3751. {
  3752. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3753. {
  3754. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3755. }
  3756. else
  3757. {
  3758. tempIndex = connectorIdInt -1;
  3759. }
  3760. for (int index = 0; index < GB_QUANTITY; index++)
  3761. {
  3762. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3763. {
  3764. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3765. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3766. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3767. {
  3768. //Reserved
  3769. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3770. }
  3771. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3772. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3773. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3774. {
  3775. //Reserved
  3776. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3777. result = FAIL;
  3778. goto end;
  3779. }
  3780. else
  3781. {
  3782. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3783. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3784. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3785. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3786. {
  3787. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  3788. result = FAIL;
  3789. goto end;
  3790. }
  3791. }// END FOR ELSE
  3792. }
  3793. } // END FOR GB_QUANTITY
  3794. }
  3795. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3796. {
  3797. tempIndex = connectorIdInt -1;
  3798. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3799. {
  3800. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3801. {
  3802. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3803. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3804. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3805. {
  3806. //Reserved
  3807. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3808. }
  3809. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3810. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3811. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3812. {
  3813. //Reserved
  3814. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3815. result = FAIL;
  3816. goto end;
  3817. }
  3818. else
  3819. {
  3820. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3821. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3822. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3823. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3824. {
  3825. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  3826. result = FAIL;
  3827. goto end;
  3828. }
  3829. }// END FOR ELSE
  3830. }
  3831. } // END FOR GB_QUANTITY
  3832. }
  3833. else
  3834. {
  3835. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3836. {
  3837. tempIndex = 2;
  3838. }
  3839. else
  3840. {
  3841. tempIndex = connectorIdInt -1;
  3842. }
  3843. for (int index = 0; index < AC_QUANTITY; index++)
  3844. {
  3845. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3846. {
  3847. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3848. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3849. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3850. {
  3851. //Reserved
  3852. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3853. }
  3854. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3855. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3856. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3857. {
  3858. //Reserved
  3859. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3860. result = FAIL;
  3861. goto end;
  3862. }
  3863. else
  3864. {
  3865. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3866. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3867. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3868. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3869. {
  3870. DEBUG_WARN("AC connector not allow start cause busy.\n");
  3871. result = FAIL;
  3872. goto end;
  3873. }
  3874. }//END FOR ELSE
  3875. }
  3876. }// END FOR AC_QUANTITY
  3877. }
  3878. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3879. {
  3880. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3881. {
  3882. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  3883. {
  3884. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3885. system(cmdBuf);
  3886. }
  3887. }
  3888. else
  3889. {
  3890. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3891. result = FAIL;
  3892. }
  3893. }
  3894. end:
  3895. if(result == PASS)
  3896. {
  3897. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3898. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3899. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3900. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3901. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3902. }
  3903. }
  3904. void CheckSystemValue(void)
  3905. {
  3906. char filenmae[100]={0};
  3907. char str[100]={0};
  3908. int tempIndex = 0;
  3909. //===============================
  3910. // send Heartbeat
  3911. //===============================
  3912. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3913. {
  3914. //parameter for test
  3915. sendHeartbeatRequest(0);
  3916. //==============================================
  3917. // Reset Waiting Time
  3918. //==============================================
  3919. HeartBeatWithNOResponse += 1;
  3920. }
  3921. //===============================
  3922. // send YES CallReader
  3923. //===============================
  3924. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->YesCustomData.CallReaderReq == 1) && (getDiffSecNow(clientTime.YesCustomCallReader) >= 5))
  3925. {
  3926. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3927. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"call_reader");
  3928. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data," ");
  3929. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  3930. //ShmOCPP16Data->YesCustomData.CallReaderReq = 0;
  3931. refreshStartTimer(&clientTime.YesCustomCallReader);
  3932. }
  3933. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3934. {
  3935. // ClockAlign MeterValue
  3936. 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))
  3937. {
  3938. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3939. {
  3940. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3941. {
  3942. tempIndex = ((gun_index==2) ? 1: 0);
  3943. }
  3944. else
  3945. {
  3946. tempIndex = gun_index;
  3947. }
  3948. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3949. {
  3950. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3951. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3952. {
  3953. reqClockAlignMeter[gun_index] = 1;
  3954. }
  3955. }// End for CHAdeMO
  3956. }
  3957. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3958. {
  3959. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3960. {
  3961. tempIndex = ((gun_index==2) ? 1: 0);
  3962. }
  3963. else
  3964. {
  3965. tempIndex = gun_index;
  3966. }
  3967. for (int index = 0; index < CCS_QUANTITY; index++)
  3968. {
  3969. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3970. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3971. {
  3972. reqClockAlignMeter[gun_index] = 1;
  3973. }
  3974. } // End for CCS
  3975. }
  3976. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3977. {
  3978. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3979. {
  3980. tempIndex = ((gun_index==2) ? 1: 0);
  3981. }
  3982. else
  3983. {
  3984. tempIndex = gun_index;
  3985. }
  3986. for (int index = 0; index < GB_QUANTITY; index++)
  3987. {
  3988. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3989. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3990. {
  3991. reqClockAlignMeter[gun_index] = 1;
  3992. }
  3993. }// End for GB
  3994. }
  3995. else if(gunType[gun_index] == GUN_TYPE_DO)
  3996. {
  3997. tempIndex = gun_index;
  3998. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3999. {
  4000. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4001. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4002. {
  4003. reqClockAlignMeter[gun_index] = 1;
  4004. }
  4005. }
  4006. }
  4007. else
  4008. {
  4009. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4010. {
  4011. tempIndex = 2;
  4012. }
  4013. else
  4014. {
  4015. tempIndex = gun_index;
  4016. }
  4017. for (int index = 0; index < AC_QUANTITY; index++)
  4018. {
  4019. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4020. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4021. {
  4022. reqClockAlignMeter[gun_index] = 1;
  4023. }
  4024. }//End for AC
  4025. }
  4026. }
  4027. }
  4028. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4029. {
  4030. //==========================================
  4031. // Check remote start without connector id
  4032. //==========================================
  4033. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4034. {
  4035. int connectorIdInt = -1;
  4036. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4037. {
  4038. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4039. {
  4040. connectorIdInt = (gun_index+1);
  4041. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4042. checkRemoteStart(connectorIdInt);
  4043. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4044. break;
  4045. }
  4046. }
  4047. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4048. {
  4049. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4050. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4051. }
  4052. }
  4053. //==========================================
  4054. // csu trigger DataTransferReq
  4055. //==========================================
  4056. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4057. {
  4058. sendDataTransferRequest(gun_index);
  4059. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4060. }
  4061. //==========================================
  4062. // CSU Trigger Authorize Request
  4063. //==========================================
  4064. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4065. {
  4066. sendAuthorizeRequest(0);
  4067. authorizeRetryTimes = authorizeRetryTimes + 1;
  4068. if(authorizeRetryTimes < 3)
  4069. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4070. }
  4071. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4072. {
  4073. authorizeRetryTimes = 0;
  4074. SetOcppConnStatus(FALSE);
  4075. server_sign = FALSE;
  4076. }
  4077. 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))
  4078. {
  4079. sendAuthorizeRequest(0);
  4080. }
  4081. //==========================================
  4082. // Charger start transaction
  4083. //==========================================
  4084. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4085. {
  4086. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4087. sendStartTransactionRequest(gun_index);
  4088. refreshStartTimer(&clientTime.StartTransaction);
  4089. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4090. storeTempStopTransaction(gun_index);
  4091. }
  4092. //==========================================
  4093. // Charger stop transaction
  4094. //==========================================
  4095. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4096. {
  4097. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4098. sendStopTransactionRequest(gun_index);
  4099. OCPP_updatePeriodEnergy(gun_index);
  4100. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4101. refreshStartTimer(&clientTime.StopTransaction);
  4102. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4103. }
  4104. //==========================================
  4105. // Charger status report
  4106. //==========================================
  4107. //--- Check Mode Change ---//
  4108. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4109. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4110. {
  4111. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4112. {
  4113. tempIndex = ((gun_index==2) ? 1: 0);
  4114. }
  4115. else
  4116. {
  4117. tempIndex = gun_index;
  4118. }
  4119. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4120. {
  4121. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4122. {
  4123. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4124. {
  4125. // Sent unplug message for California pricing logic
  4126. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  4127. {
  4128. uint8_t ts[20];
  4129. getNowDatetime(ts);
  4130. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4131. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4132. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4133. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4134. }
  4135. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4136. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4137. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4138. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4139. {
  4140. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4141. if((access(filenmae,F_OK))!=-1)
  4142. {
  4143. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4144. sprintf(str,"rm -f %s",filenmae);
  4145. system(str);
  4146. }
  4147. }
  4148. }
  4149. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4150. #if 1 // for TempStopTransaction
  4151. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4152. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4153. {
  4154. checkTempStopTransaction(gun_index);
  4155. }
  4156. #endif
  4157. }
  4158. }
  4159. }
  4160. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4161. {
  4162. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4163. {
  4164. tempIndex = ((gun_index==2) ? 1: 0);
  4165. }
  4166. else
  4167. {
  4168. tempIndex = gun_index;
  4169. }
  4170. for (int index = 0; index < CCS_QUANTITY; index++)
  4171. {
  4172. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4173. {
  4174. 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]*/ )
  4175. {
  4176. // Sent unplug message for California pricing logic
  4177. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  4178. {
  4179. uint8_t ts[20];
  4180. getNowDatetime(ts);
  4181. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4182. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4183. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4184. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4185. }
  4186. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4187. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4188. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4189. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4190. {
  4191. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4192. if((access(filenmae,F_OK))!=-1)
  4193. {
  4194. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4195. sprintf(str,"rm -f %s",filenmae);
  4196. system(str);
  4197. }
  4198. }
  4199. }
  4200. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4201. #if 1 // for TempStopTransaction
  4202. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4203. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4204. {
  4205. checkTempStopTransaction(gun_index);
  4206. }
  4207. #endif
  4208. }
  4209. }
  4210. }
  4211. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4212. {
  4213. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4214. {
  4215. tempIndex = ((gun_index==2) ? 1: 0);
  4216. }
  4217. else
  4218. {
  4219. tempIndex = gun_index;
  4220. }
  4221. for (int index = 0; index < GB_QUANTITY; index++)
  4222. {
  4223. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4224. {
  4225. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4226. {
  4227. // Sent unplug message for California pricing logic
  4228. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  4229. {
  4230. uint8_t ts[20];
  4231. getNowDatetime(ts);
  4232. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4233. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4234. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4235. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4236. }
  4237. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4238. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4239. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4240. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4241. {
  4242. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4243. if((access(filenmae,F_OK))!=-1)
  4244. {
  4245. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4246. sprintf(str,"rm -f %s",filenmae);
  4247. system(str);
  4248. }
  4249. }
  4250. }
  4251. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4252. #if 1 // for TempStopTransaction
  4253. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4254. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4255. {
  4256. checkTempStopTransaction(gun_index);
  4257. }
  4258. #endif
  4259. }
  4260. }
  4261. }
  4262. else if(gunType[gun_index] == GUN_TYPE_DO)
  4263. {
  4264. tempIndex = gun_index;
  4265. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4266. {
  4267. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4268. {
  4269. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4270. {
  4271. // Sent unplug message for California pricing logic
  4272. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  4273. {
  4274. uint8_t ts[20];
  4275. getNowDatetime(ts);
  4276. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4277. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4278. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4279. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4280. }
  4281. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4282. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4283. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4284. 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
  4285. {
  4286. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4287. if((access(filenmae,F_OK))!=-1)
  4288. {
  4289. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4290. sprintf(str,"rm -f %s",filenmae);
  4291. system(str);
  4292. }
  4293. }
  4294. }
  4295. 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);
  4296. #if 1 // for TempStopTransaction
  4297. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4298. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4299. {
  4300. checkTempStopTransaction(gun_index);
  4301. }
  4302. #endif
  4303. }
  4304. }
  4305. }
  4306. else
  4307. {
  4308. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4309. {
  4310. tempIndex = 2;
  4311. }
  4312. else
  4313. {
  4314. tempIndex = gun_index;
  4315. }
  4316. for (int index = 0; index < AC_QUANTITY; index++)
  4317. {
  4318. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4319. {
  4320. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4321. {
  4322. // Sent unplug message for California pricing logic
  4323. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  4324. {
  4325. uint8_t ts[20];
  4326. getNowDatetime(ts);
  4327. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4328. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4329. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4330. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4331. }
  4332. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4333. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4334. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4335. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4336. {
  4337. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4338. if((access(filenmae,F_OK))!=-1)
  4339. {
  4340. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4341. sprintf(str,"rm -f %s",filenmae);
  4342. system(str);
  4343. }
  4344. }
  4345. }
  4346. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4347. #if 1 // for TempStopTransaction
  4348. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4349. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4350. {
  4351. checkTempStopTransaction(gun_index);
  4352. }
  4353. #endif
  4354. }
  4355. }// END
  4356. }
  4357. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  4358. (
  4359. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  4360. )
  4361. )
  4362. {
  4363. if(SystemInitial > 0)
  4364. SystemInitial -= 1;
  4365. sendStatusNotificationRequest(gun_index);
  4366. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4367. }
  4368. //==============================================
  4369. // CSU Trigger Smart Charging Profile
  4370. //==============================================
  4371. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4372. {
  4373. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4374. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4375. }
  4376. //==============================================
  4377. // Meter report
  4378. //==============================================
  4379. // Trigger MeterValue
  4380. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4381. {
  4382. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4383. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4384. }
  4385. // Clock-aligned Meter value
  4386. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4387. {
  4388. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4389. reqClockAlignMeter[gun_index] = 0;
  4390. }
  4391. // Sample period MeterValue
  4392. 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))))
  4393. {
  4394. //check Transaction active
  4395. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4396. {
  4397. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4398. {
  4399. tempIndex = ((gun_index==2) ? 1: 0);
  4400. }
  4401. else
  4402. {
  4403. tempIndex = gun_index;
  4404. }
  4405. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4406. {
  4407. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4408. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4409. {
  4410. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4411. {
  4412. reqSampleMeter[gun_index] = 1;
  4413. }
  4414. }
  4415. }// End for CHAdeMO
  4416. }
  4417. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4418. {
  4419. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4420. {
  4421. tempIndex = ((gun_index==2) ? 1: 0);
  4422. }
  4423. else
  4424. {
  4425. tempIndex = gun_index;
  4426. }
  4427. for (int index = 0; index < CCS_QUANTITY; index++)
  4428. {
  4429. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4430. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4431. {
  4432. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4433. {
  4434. reqSampleMeter[gun_index] = 1;
  4435. }
  4436. }
  4437. } // End for CCS
  4438. }
  4439. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4440. {
  4441. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4442. {
  4443. tempIndex = ((gun_index==2) ? 1: 0);
  4444. }
  4445. else
  4446. {
  4447. tempIndex = gun_index;
  4448. }
  4449. for (int index = 0; index < GB_QUANTITY; index++)
  4450. {
  4451. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4452. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4453. {
  4454. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4455. {
  4456. reqSampleMeter[gun_index] = 1;
  4457. }
  4458. }
  4459. }// End for GB
  4460. }
  4461. else if(gunType[gun_index] == GUN_TYPE_DO)
  4462. {
  4463. tempIndex = gun_index;
  4464. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4465. {
  4466. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4467. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4468. {
  4469. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4470. {
  4471. reqSampleMeter[gun_index] = 1;
  4472. }
  4473. }
  4474. }
  4475. }
  4476. else
  4477. {
  4478. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4479. {
  4480. tempIndex = 2;
  4481. }
  4482. else
  4483. {
  4484. tempIndex = gun_index;
  4485. }
  4486. for (int index = 0; index < AC_QUANTITY; index++)
  4487. {
  4488. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4489. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4490. {
  4491. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4492. {
  4493. reqSampleMeter[gun_index] = 1;
  4494. }
  4495. }
  4496. }//End for AC
  4497. }
  4498. if(reqSampleMeter[gun_index] == 1)
  4499. {
  4500. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4501. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4502. storeTempStopTransaction(gun_index);
  4503. reqSampleMeter[gun_index] = 0;
  4504. }
  4505. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4506. }
  4507. //==============================================
  4508. // Check Connector reserved
  4509. //==============================================
  4510. //===============================
  4511. // Check if Reserve is expired
  4512. //===============================
  4513. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4514. {
  4515. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4516. {
  4517. DEBUG_INFO("reserve expired.\n");
  4518. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4519. }
  4520. }//END OF Check if Reserve is expired
  4521. //==========================================
  4522. // csu trigger FirmwareStatusNotificationReq
  4523. //==========================================
  4524. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4525. {
  4526. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  4527. }
  4528. //==========================================
  4529. // csu trigger DiagnosticsStatusNotificationReq
  4530. //==========================================
  4531. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4532. {
  4533. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  4534. }
  4535. //==========================================
  4536. // csu trigger CancelReservationConf
  4537. //==========================================
  4538. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4539. {
  4540. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  4541. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4542. }
  4543. //==========================================
  4544. // csu trigger ChangeAvailabilityConf
  4545. //==========================================
  4546. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4547. {
  4548. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  4549. }
  4550. //==========================================
  4551. // csu trigger UnlockConnectorConf
  4552. //==========================================
  4553. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4554. {
  4555. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  4556. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4557. }
  4558. //==========================================
  4559. // csu trigger ReserveNowConf
  4560. //==========================================
  4561. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4562. {
  4563. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  4564. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4565. }
  4566. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  4567. {
  4568. sendSignCertificateRequest();
  4569. }
  4570. }
  4571. }
  4572. //==========================================
  4573. // send request routine
  4574. //==========================================
  4575. int sendAuthorizeRequest(int gun_index)
  4576. {
  4577. mtrace();
  4578. int result = FAIL;
  4579. char message[100]={0};
  4580. char guid[37];
  4581. char tempdata[65]={0};
  4582. DEBUG_INFO("sendAuthorizeRequest...\n");
  4583. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4584. //Local Authorize
  4585. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  4586. {
  4587. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4588. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4589. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4590. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4591. result = PASS;
  4592. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4593. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4594. authorizeRetryTimes = 0;
  4595. return result;
  4596. }
  4597. 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))||
  4598. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4599. {
  4600. // Query from cache
  4601. DEBUG_INFO("Authorize from cache.\n");
  4602. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4603. // Query from list
  4604. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4605. {
  4606. DEBUG_INFO("Authorize from list.\n");
  4607. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4608. }
  4609. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4610. {
  4611. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4612. {
  4613. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4614. }
  4615. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4616. {
  4617. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4618. }
  4619. if(!GetOcppConnStatus())
  4620. {
  4621. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4622. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4623. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4624. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4625. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4626. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4627. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4628. authorizeRetryTimes = 0;
  4629. return result;
  4630. }
  4631. }
  4632. else
  4633. {
  4634. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4635. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4636. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4637. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4638. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  4639. else
  4640. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4641. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4642. result = PASS;
  4643. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4644. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4645. authorizeRetryTimes = 0;
  4646. return result;
  4647. }
  4648. }
  4649. //initialize struct Authorize
  4650. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  4651. //get data from shared memory
  4652. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4653. random_uuid(guid);
  4654. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  4655. LWS_Send(message);
  4656. sprintf(tempdata, "Authorize,%d", gun_index);
  4657. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4658. {
  4659. result = PASS;
  4660. DEBUG_INFO("Authorize mapItem pass\n");
  4661. }
  4662. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4663. return result;
  4664. }
  4665. int sendBootNotificationRequest(void)
  4666. {
  4667. mtrace();
  4668. int result = FAIL;
  4669. char message[500]={0}, payload[700]={0};
  4670. char guid[37]={0};
  4671. char tempdata[65]={0};
  4672. // Fill BootNotification fields
  4673. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  4674. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4675. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4676. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4677. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4678. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4679. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4680. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4681. ShmOCPP16Data->ChargeBoxId
  4682. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4683. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4684. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4685. ,ShmOCPP16Data->BootNotification.CpFwVersion
  4686. ,ShmOCPP16Data->BootNotification.CpIccid
  4687. ,ShmOCPP16Data->BootNotification.CpImsi);
  4688. random_uuid(guid);
  4689. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4690. LWS_Send(message);
  4691. sprintf(tempdata, "BootNotification,0");
  4692. 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*/)
  4693. {
  4694. result = PASS;
  4695. }
  4696. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4697. strcpy(queuedata,message);
  4698. return result;
  4699. }
  4700. int sendDataTransferRequest(int gun_index)
  4701. {
  4702. mtrace();
  4703. char message[1000]={0};
  4704. char guid[37]={0};
  4705. char tempdata[65]={0};
  4706. int result = FAIL;
  4707. random_uuid(guid);
  4708. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4709. MESSAGE_TYPE_CALL,
  4710. guid,
  4711. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4712. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4713. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4714. LWS_Send(message);
  4715. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4716. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4717. {
  4718. result = PASS;
  4719. DEBUG_INFO("DataTransfer mapItem pass\n");
  4720. }
  4721. return result;
  4722. }
  4723. int sendDiagnosticsStatusNotificationRequest(char *status)
  4724. {
  4725. mtrace();
  4726. int result = FAIL;
  4727. char message[110]={0};
  4728. char guid[37]={0};
  4729. char tempdata[65]={0};
  4730. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4731. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4732. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4733. random_uuid(guid);
  4734. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4735. LWS_SendNow(message);
  4736. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4737. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4738. {
  4739. result = PASS;
  4740. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4741. }
  4742. //#ifdef SystemLogMessage
  4743. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4744. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4745. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4746. //#endif
  4747. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4748. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4749. //record status
  4750. if(strcmp(status,"Idle")==0)
  4751. {
  4752. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4753. }
  4754. else if(strcmp(status,"Uploaded")==0)
  4755. {
  4756. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4757. }
  4758. else if(strcmp(status,"UploadFailed")==0)
  4759. {
  4760. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4761. }
  4762. else if(strcmp(status,"Uploading")==0)
  4763. {
  4764. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4765. }
  4766. return result;
  4767. }
  4768. int sendFirmwareStatusNotificationRequest(char *status)
  4769. {
  4770. mtrace();
  4771. int result = FAIL;
  4772. char message[110]={0};
  4773. char guid[37]={0};
  4774. char tempdata[65]={0};
  4775. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4776. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4777. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4778. random_uuid(guid);
  4779. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4780. LWS_SendNow(message);
  4781. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4782. 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*/)
  4783. {
  4784. result = PASS;
  4785. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4786. }
  4787. //#ifdef SystemLogMessage
  4788. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4789. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4790. //#endif
  4791. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4792. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4793. //record status
  4794. if(strcmp(status,"Downloaded")==0)
  4795. {
  4796. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4797. }
  4798. else if(strcmp(status,"DownloadFailed")==0)
  4799. {
  4800. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4801. }
  4802. else if(strcmp(status,"Downloading")==0)
  4803. {
  4804. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4805. }
  4806. else if(strcmp(status,"Idle")==0)
  4807. {
  4808. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4809. }
  4810. else if(strcmp(status,"InstallationFailed")==0)
  4811. {
  4812. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4813. }
  4814. else if(strcmp(status,"Installing")==0)
  4815. {
  4816. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4817. }
  4818. else if(strcmp(status,"Installed")==0)
  4819. {
  4820. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4821. }
  4822. return result;
  4823. }
  4824. int sendHeartbeatRequest(int gun_index)
  4825. {
  4826. mtrace();
  4827. int result = FAIL;
  4828. char message[80]={0};
  4829. char guid[37]={0};
  4830. char tempdata[65]={0};
  4831. random_uuid(guid);
  4832. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4833. , MESSAGE_TYPE_CALL
  4834. , guid );
  4835. LWS_Send(message);
  4836. sprintf(tempdata, "Heartbeat,%d", 0);
  4837. 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*/)
  4838. {
  4839. result = PASS;
  4840. }
  4841. return result;
  4842. }
  4843. int sendStartTransactionRequest(int gun_index)
  4844. {
  4845. mtrace();
  4846. int result = FAIL;
  4847. char message[250]={0};
  4848. char guid[37]={0};
  4849. struct timeval tmnow;
  4850. struct tm *tm;
  4851. char buf[28];//, usec_buf[6];
  4852. char tempdata[65]={0};
  4853. int tempIndex = 0;
  4854. DEBUG_INFO("sendStartTransactionRequest...\n");
  4855. gettimeofday(&tmnow, NULL);
  4856. time_t t;
  4857. t = time(NULL);
  4858. /*UTC time and date*/
  4859. tm = gmtime(&t);
  4860. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4861. #if 0 // remove temporally
  4862. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4863. strcat(buf,".");
  4864. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4865. strcat(buf,usec_buf);
  4866. #endif
  4867. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4868. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4869. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4870. // clear StartTransaction Response
  4871. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4872. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4873. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4874. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4875. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4876. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4877. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4878. {
  4879. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4880. {
  4881. tempIndex = ((gun_index==2) ? 1: 0);
  4882. }
  4883. else
  4884. {
  4885. tempIndex = gun_index;
  4886. }
  4887. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4888. {
  4889. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4890. {
  4891. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4892. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4893. }
  4894. }
  4895. }
  4896. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4897. {
  4898. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4899. {
  4900. tempIndex = ((gun_index==2) ? 1: 0);
  4901. }
  4902. else
  4903. {
  4904. tempIndex = gun_index;
  4905. }
  4906. for (int index = 0; index < CCS_QUANTITY; index++)
  4907. {
  4908. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4909. {
  4910. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4911. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4912. }
  4913. }
  4914. }
  4915. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4916. {
  4917. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4918. {
  4919. tempIndex = ((gun_index==2) ? 1: 0);
  4920. }
  4921. else
  4922. {
  4923. tempIndex = gun_index;
  4924. }
  4925. for (int index = 0; index < GB_QUANTITY; index++)
  4926. {
  4927. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4928. {
  4929. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4930. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4931. }
  4932. }
  4933. }
  4934. else if(gunType[gun_index] == GUN_TYPE_DO)
  4935. {
  4936. tempIndex = gun_index;
  4937. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4938. {
  4939. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4940. {
  4941. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4942. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4943. }
  4944. }
  4945. }
  4946. else
  4947. {
  4948. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4949. {
  4950. tempIndex = 2;
  4951. }
  4952. else
  4953. {
  4954. tempIndex = gun_index;
  4955. }
  4956. for (int index = 0; index < AC_QUANTITY; index++)
  4957. {
  4958. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4959. {
  4960. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4961. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4962. }
  4963. }
  4964. }
  4965. random_uuid(guid);
  4966. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4967. {
  4968. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4969. , gun_index +1
  4970. , MESSAGE_TYPE_CALL
  4971. , guid
  4972. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4973. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4974. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4975. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4976. }
  4977. else
  4978. {
  4979. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4980. , gun_index +1
  4981. , MESSAGE_TYPE_CALL
  4982. , guid
  4983. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4984. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4985. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4986. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  4987. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4988. }
  4989. #if 1
  4990. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4991. 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*/)
  4992. {
  4993. result = PASS;
  4994. }
  4995. #endif
  4996. strcpy(queuedata, message);
  4997. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4998. OCPP_insert_transaction_msg(YES, queuedata);
  4999. return result;
  5000. }
  5001. int sendStatusNotificationRequest(int gun_index)
  5002. {
  5003. mtrace();
  5004. int result = FAIL;
  5005. char message[600]={0};
  5006. char guid[37];
  5007. int currentStatus = 0;
  5008. struct timeval tmnow;
  5009. struct tm *tm;
  5010. char buf[28];//, usec_buf[6];
  5011. char tempdata[65]={0};
  5012. int tempIndex = 0;
  5013. uint8_t isStateChanged = TRUE;
  5014. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5015. gettimeofday(&tmnow, NULL);
  5016. time_t t;
  5017. t = time(NULL);
  5018. /*UTC time and date*/
  5019. tm = gmtime(&t);
  5020. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5021. #if 0 // remove temporally
  5022. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5023. strcat(buf,".");
  5024. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5025. strcat(buf,usec_buf);
  5026. #endif
  5027. //printf("%s",buf);
  5028. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5029. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5030. // it's option
  5031. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5032. /*
  5033. enum _SYSTEM_STATUS
  5034. {
  5035. S_BOOTING = 0,
  5036. S_IDLE, = 1
  5037. S_AUTHORIZING, =2
  5038. S_REASSIGN_CHECK, =3
  5039. S_REASSIGN, =4
  5040. S_PRECHARGE, =5
  5041. S_PREPARING_FOR_EV, =6
  5042. S_PREPARING_FOR_EVSE, =7
  5043. S_CHARGING, =8
  5044. S_TERMINATING, =9
  5045. S_COMPLETE, =10
  5046. S_ALARM, =11
  5047. S_FAULT =12
  5048. }
  5049. */
  5050. //check Transaction active
  5051. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5052. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5053. {
  5054. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5055. {
  5056. tempIndex = ((gun_index==2) ? 1: 0);
  5057. }
  5058. else
  5059. {
  5060. tempIndex = gun_index;
  5061. }
  5062. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5063. {
  5064. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5065. {
  5066. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5067. {
  5068. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5069. {
  5070. currentStatus = Preparing; //OCPP Status: Preparing
  5071. }
  5072. else
  5073. {
  5074. currentStatus = Available; //OCPP Status: Available
  5075. }
  5076. }
  5077. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5078. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5079. ) //S_PRECHARGE
  5080. {
  5081. currentStatus = Preparing; //OCPP Status: Preparing
  5082. }
  5083. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5084. {
  5085. currentStatus = Charging; //OCPP Status: Charging
  5086. }
  5087. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5088. {
  5089. currentStatus = Finishing; //OCPP Status: Finishing
  5090. }
  5091. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5092. {
  5093. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5094. }
  5095. 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
  5096. {
  5097. currentStatus = Unavailable; //OCPP Status: Unavailable
  5098. }
  5099. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5100. {
  5101. currentStatus = Faulted; //OCPP Status: Faulted
  5102. }
  5103. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5104. {
  5105. currentStatus = Reserved; //OCPP Status: Reserved
  5106. }
  5107. } //end of the same index
  5108. }//end of for CHAdeMO_QUANTITY
  5109. }
  5110. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5111. {
  5112. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5113. {
  5114. tempIndex = ((gun_index==2) ? 1: 0);
  5115. }
  5116. else
  5117. {
  5118. tempIndex = gun_index;
  5119. }
  5120. for (int index = 0; index < CCS_QUANTITY; index++)
  5121. {
  5122. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5123. {
  5124. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5125. {
  5126. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5127. {
  5128. currentStatus = Preparing; //OCPP Status: Preparing
  5129. }
  5130. else
  5131. {
  5132. currentStatus = Available; //OCPP Status: Available
  5133. }
  5134. }
  5135. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5136. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5137. ) //S_PRECHARGE
  5138. {
  5139. currentStatus = Preparing; //OCPP Status: Preparing
  5140. }
  5141. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5142. {
  5143. currentStatus = Charging; //OCPP Status: Charging
  5144. }
  5145. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5146. {
  5147. currentStatus = Finishing; //OCPP Status: Finishing
  5148. }
  5149. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5150. {
  5151. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5152. }
  5153. 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
  5154. {
  5155. currentStatus = Unavailable; //OCPP Status : Unavailable
  5156. }
  5157. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5158. {
  5159. currentStatus = Faulted; //OCPP Status: Faulted
  5160. }
  5161. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5162. {
  5163. currentStatus = Reserved; //OCPP Status: Reserved
  5164. }
  5165. } //end of the same index
  5166. } // end of for CCS_QUANTITY
  5167. }
  5168. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5169. {
  5170. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5171. {
  5172. tempIndex = ((gun_index==2) ? 1: 0);
  5173. }
  5174. else
  5175. {
  5176. tempIndex = gun_index;
  5177. }
  5178. for (int index = 0; index < GB_QUANTITY; index++)
  5179. {
  5180. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5181. {
  5182. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5183. {
  5184. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5185. {
  5186. currentStatus = Preparing; //OCPP Status: Preparing
  5187. }
  5188. else
  5189. {
  5190. currentStatus = Available; //OCPP Status: Available
  5191. }
  5192. }
  5193. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5194. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5195. ) //S_PRECHARGE
  5196. {
  5197. currentStatus = Preparing; //OCPP Status: Preparing
  5198. }
  5199. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5200. {
  5201. currentStatus = Charging; //OCPP Status: Charging
  5202. }
  5203. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5204. {
  5205. currentStatus = Finishing; //OCPP Status: Finishing
  5206. }
  5207. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5208. {
  5209. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5210. }
  5211. 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
  5212. {
  5213. currentStatus = Unavailable; //OCPP Status: Unavailable
  5214. }
  5215. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5216. {
  5217. currentStatus = Faulted; //OCPP Status: Faulted
  5218. }
  5219. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5220. {
  5221. currentStatus = Reserved; //OCPP Status: Reserved
  5222. }
  5223. } //end of the same index
  5224. } // end of for GB_QUANTITY
  5225. }
  5226. else if(gunType[gun_index] == GUN_TYPE_DO)
  5227. {
  5228. tempIndex = gun_index;
  5229. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5230. {
  5231. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5232. {
  5233. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5234. {
  5235. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5236. {
  5237. currentStatus = Preparing; //OCPP Status: Preparing
  5238. }
  5239. else
  5240. {
  5241. currentStatus = Available; //OCPP Status: Available
  5242. }
  5243. }
  5244. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5245. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5246. ) //S_PRECHARGE
  5247. {
  5248. currentStatus = Preparing; //OCPP Status: Preparing
  5249. }
  5250. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5251. {
  5252. currentStatus = Charging; //OCPP Status: Charging
  5253. }
  5254. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5255. {
  5256. currentStatus = Finishing; //OCPP Status: Finishing
  5257. }
  5258. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5259. {
  5260. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5261. }
  5262. 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
  5263. {
  5264. currentStatus = Unavailable; //OCPP Status: Unavailable
  5265. }
  5266. 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
  5267. {
  5268. currentStatus = Faulted; //OCPP Status: Faulted
  5269. }
  5270. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5271. {
  5272. currentStatus = Reserved; //OCPP Status: Reserved
  5273. }
  5274. } //end of the same index
  5275. }
  5276. }
  5277. else
  5278. {
  5279. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5280. {
  5281. tempIndex = 2;
  5282. }
  5283. else
  5284. {
  5285. tempIndex = gun_index;
  5286. }
  5287. for (int index = 0; index < AC_QUANTITY; index++)
  5288. {
  5289. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5290. {
  5291. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5292. {
  5293. 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))
  5294. {
  5295. currentStatus = Preparing; //OCPP Status: Preparing
  5296. }
  5297. else
  5298. {
  5299. currentStatus = Available; //OCPP Status: Available
  5300. }
  5301. }
  5302. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5303. {
  5304. currentStatus = Preparing; //OCPP Status: Preparing
  5305. }
  5306. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5307. {
  5308. currentStatus = Charging; //OCPP Status: Charging
  5309. }
  5310. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5311. {
  5312. currentStatus = Finishing; //OCPP Status: Finishing
  5313. }
  5314. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5315. {
  5316. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5317. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5318. else
  5319. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5320. }
  5321. 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
  5322. {
  5323. currentStatus = Unavailable; //OCPP Status: Unavailable
  5324. }
  5325. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5326. {
  5327. currentStatus = Faulted; //OCPP Status: Faulted
  5328. }
  5329. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5330. {
  5331. currentStatus = Reserved; //OCPP Status: Reserved
  5332. }
  5333. }//end of the same index
  5334. }//end of for AC_QUANTITY
  5335. }
  5336. //it's option
  5337. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5338. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  5339. {
  5340. isStateChanged = FALSE;
  5341. }
  5342. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5343. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5344. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5345. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5346. random_uuid(guid);
  5347. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5348. , MESSAGE_TYPE_CALL
  5349. , guid
  5350. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5351. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5352. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5353. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5354. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5355. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5356. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5357. if((server_sign == TRUE) && isStateChanged)
  5358. {
  5359. LWS_Send(message);
  5360. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5361. 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*/)
  5362. {
  5363. //DEBUG_ERROR("statusNotification mapitem pass");
  5364. result = PASS;
  5365. }
  5366. }
  5367. else
  5368. {
  5369. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5370. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5371. result = PASS;
  5372. }
  5373. return result;
  5374. }
  5375. int sendStopTransactionRequest(int gun_index)
  5376. {
  5377. mtrace();
  5378. int result = FAIL;
  5379. //char message[1500]={0};
  5380. char guid[37]={0};
  5381. char tempdata[65]={0};
  5382. int tempIndex = 0;
  5383. char TempStopTransaction[256];
  5384. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5385. //int idx_sample=0;
  5386. DEBUG_INFO("sendStopTransactionRequest \n");
  5387. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5388. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5389. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5390. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5391. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5392. {
  5393. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5394. {
  5395. tempIndex = ((gun_index==2) ? 1: 0);
  5396. }
  5397. else
  5398. {
  5399. tempIndex = gun_index;
  5400. }
  5401. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5402. {
  5403. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5404. {
  5405. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5406. }
  5407. }// END OF CHAdeMO_QUANTITY
  5408. }
  5409. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5410. {
  5411. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5412. {
  5413. tempIndex = ((gun_index==2) ? 1: 0);
  5414. }
  5415. else
  5416. {
  5417. tempIndex = gun_index;
  5418. }
  5419. for (int index = 0; index < CCS_QUANTITY; index++)
  5420. {
  5421. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5422. {
  5423. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5424. }
  5425. }// END OF CCS_QUANTITY
  5426. }
  5427. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5428. {
  5429. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5430. {
  5431. tempIndex = ((gun_index==2) ? 1: 0);
  5432. }
  5433. else
  5434. {
  5435. tempIndex = gun_index;
  5436. }
  5437. for (int index = 0; index < GB_QUANTITY; index++)
  5438. {
  5439. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5440. {
  5441. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5442. }
  5443. }// END OF GB_QUANTITY
  5444. }
  5445. else if(gunType[gun_index] == GUN_TYPE_DO)
  5446. {
  5447. tempIndex = gun_index;
  5448. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5449. {
  5450. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5451. {
  5452. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5453. }
  5454. }// END OF GB_QUANTITY
  5455. }
  5456. else
  5457. {
  5458. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5459. {
  5460. tempIndex = 2;
  5461. }
  5462. else
  5463. {
  5464. tempIndex = gun_index;
  5465. }
  5466. for (int index = 0; index < AC_QUANTITY; index++)
  5467. {
  5468. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5469. {
  5470. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5471. }
  5472. }// END OF AC_QUANTITY
  5473. }
  5474. //====================================== Stop Transaction Time =====================================================
  5475. struct timeval tmnow;
  5476. struct tm *tm;
  5477. char buf[28];//, usec_buf[6];
  5478. gettimeofday(&tmnow, NULL);
  5479. time_t t;
  5480. t = time(NULL);
  5481. /*UTC time and date*/
  5482. tm = gmtime(&t);
  5483. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  5485. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  5486. random_uuid(guid);
  5487. /***********************************transactionData******************************************************/
  5488. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5489. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5490. //=================================
  5491. // Transaction_Begin
  5492. //=================================
  5493. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5494. {
  5495. //============================================ Energy.Active.Import.Interval ================================
  5496. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5497. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5498. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5499. 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*/]);
  5500. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5501. 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))
  5502. {
  5503. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5504. }
  5505. else
  5506. {
  5507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5508. }
  5509. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5511. }
  5512. //=================================
  5513. // Transaction_End
  5514. //=================================
  5515. // ================================= Current.Import L1 ===============================================
  5516. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5517. {
  5518. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5519. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5520. {
  5521. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5522. {
  5523. tempIndex = ((gun_index==2) ? 1: 0);
  5524. }
  5525. else
  5526. {
  5527. tempIndex = gun_index;
  5528. }
  5529. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5530. {
  5531. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5532. {
  5533. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5534. }
  5535. }// End of for CHAdeMO_QUANTITY
  5536. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5537. }
  5538. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5539. {
  5540. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5541. {
  5542. tempIndex = ((gun_index==2) ? 1: 0);
  5543. }
  5544. else
  5545. {
  5546. tempIndex = gun_index;
  5547. }
  5548. for (int index = 0; index < CCS_QUANTITY; index++)
  5549. {
  5550. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5551. {
  5552. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5553. }
  5554. }// End of for CCS_QUANTITY
  5555. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5556. }
  5557. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5558. {
  5559. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5560. {
  5561. tempIndex = ((gun_index==2) ? 1: 0);
  5562. }
  5563. else
  5564. {
  5565. tempIndex = gun_index;
  5566. }
  5567. for (int index = 0; index < GB_QUANTITY; index++)
  5568. {
  5569. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5570. {
  5571. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5572. }
  5573. }// End of for GB_QUANTITY
  5574. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5575. }
  5576. else if(gunType[gun_index] == GUN_TYPE_DO)
  5577. {
  5578. tempIndex = gun_index;
  5579. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5580. {
  5581. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5582. {
  5583. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5584. }
  5585. }
  5586. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5587. }
  5588. else
  5589. {
  5590. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5591. {
  5592. tempIndex = 2;
  5593. }
  5594. else
  5595. {
  5596. tempIndex = gun_index;
  5597. }
  5598. for (int index = 0; index < AC_QUANTITY; index++)
  5599. {
  5600. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5601. {
  5602. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5603. }
  5604. }// End of for AC_QUANTITY
  5605. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5606. }
  5607. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5608. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5609. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5610. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5611. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5612. }
  5613. // ================================= Energy.Active.Import.Interval ==============================================
  5614. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5615. {
  5616. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5617. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5618. {
  5619. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5620. {
  5621. tempIndex = ((gun_index==2) ? 1: 0);
  5622. }
  5623. else
  5624. {
  5625. tempIndex = gun_index;
  5626. }
  5627. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5628. {
  5629. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5630. {
  5631. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5632. }
  5633. }// END OF CHAdeMO_QUANTITY
  5634. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5635. }
  5636. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5637. {
  5638. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5639. {
  5640. tempIndex = ((gun_index==2) ? 1: 0);
  5641. }
  5642. else
  5643. {
  5644. tempIndex = gun_index;
  5645. }
  5646. for (int index = 0; index < CCS_QUANTITY; index++)
  5647. {
  5648. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5649. {
  5650. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5651. }
  5652. }// END OF CCS_QUANTITY
  5653. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5654. }
  5655. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5656. {
  5657. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5658. {
  5659. tempIndex = ((gun_index==2) ? 1: 0);
  5660. }
  5661. else
  5662. {
  5663. tempIndex = gun_index;
  5664. }
  5665. for (int index = 0; index < GB_QUANTITY; index++)
  5666. {
  5667. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5668. {
  5669. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5670. }
  5671. }// END OF GB_QUANTITY
  5672. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5673. }
  5674. else if(gunType[gun_index] == GUN_TYPE_DO)
  5675. {
  5676. tempIndex = gun_index;
  5677. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5678. {
  5679. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5680. {
  5681. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5682. }
  5683. }
  5684. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5685. }
  5686. else
  5687. {
  5688. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5689. {
  5690. tempIndex = 2;
  5691. }
  5692. else
  5693. {
  5694. tempIndex = gun_index;
  5695. }
  5696. for (int index = 0; index < AC_QUANTITY; index++)
  5697. {
  5698. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5699. {
  5700. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5701. }
  5702. }// END OF AC_QUANTITY
  5703. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5704. }
  5705. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5706. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5707. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5708. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5709. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5710. }
  5711. //=================================== Power.Active.Import ==================================================
  5712. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5713. {
  5714. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5715. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5716. {
  5717. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5718. {
  5719. tempIndex = ((gun_index==2) ? 1: 0);
  5720. }
  5721. else
  5722. {
  5723. tempIndex = gun_index;
  5724. }
  5725. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5726. {
  5727. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5728. {
  5729. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5730. }
  5731. } // End for CHAdeMO_QUANTITY
  5732. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5733. }
  5734. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5735. {
  5736. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5737. {
  5738. tempIndex = ((gun_index==2) ? 1: 0);
  5739. }
  5740. else
  5741. {
  5742. tempIndex = gun_index;
  5743. }
  5744. for (int index = 0; index < CCS_QUANTITY; index++)
  5745. {
  5746. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5747. {
  5748. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5749. }
  5750. } // END for CCS_QUANTITY
  5751. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5752. }
  5753. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5754. {
  5755. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5756. {
  5757. tempIndex = ((gun_index==2) ? 1: 0);
  5758. }
  5759. else
  5760. {
  5761. tempIndex = gun_index;
  5762. }
  5763. for (int index = 0; index < GB_QUANTITY; index++)
  5764. {
  5765. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5766. {
  5767. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5768. }
  5769. }// END for GB_QUANTITY
  5770. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5771. }
  5772. else if(gunType[gun_index] == GUN_TYPE_DO)
  5773. {
  5774. tempIndex = gun_index;
  5775. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5776. {
  5777. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5778. {
  5779. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5780. }
  5781. }
  5782. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5783. }
  5784. else
  5785. {
  5786. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5787. {
  5788. tempIndex = 2;
  5789. }
  5790. else
  5791. {
  5792. tempIndex = gun_index;
  5793. }
  5794. for (int index = 0; index < AC_QUANTITY; index++)
  5795. {
  5796. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5797. {
  5798. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5799. }
  5800. } // END for AC_QUANTITY
  5801. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5802. }
  5803. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5804. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5805. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5806. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5807. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5808. }
  5809. //============================ Voltage L1 ====================================
  5810. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5811. {
  5812. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5813. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5814. {
  5815. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5816. {
  5817. tempIndex = ((gun_index==2) ? 1: 0);
  5818. }
  5819. else
  5820. {
  5821. tempIndex = gun_index;
  5822. }
  5823. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5824. {
  5825. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5826. {
  5827. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5828. }
  5829. } // END OF FOR CHAdeMO_QUANTITY
  5830. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5831. }
  5832. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5833. {
  5834. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5835. {
  5836. tempIndex = ((gun_index==2) ? 1: 0);
  5837. }
  5838. else
  5839. {
  5840. tempIndex = gun_index;
  5841. }
  5842. for (int index = 0; index < CCS_QUANTITY; index++)
  5843. {
  5844. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5845. {
  5846. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5847. }
  5848. } // END OF FOR CCS_QUANTITY
  5849. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5850. }
  5851. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5852. {
  5853. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5854. {
  5855. tempIndex = ((gun_index==2) ? 1: 0);
  5856. }
  5857. else
  5858. {
  5859. tempIndex = gun_index;
  5860. }
  5861. for (int index = 0; index < GB_QUANTITY; index++)
  5862. {
  5863. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5864. {
  5865. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5866. }
  5867. } // END OF FOR GB_QUANTITY
  5868. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5869. }
  5870. else if(gunType[gun_index] == GUN_TYPE_DO)
  5871. {
  5872. tempIndex = gun_index;
  5873. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5874. {
  5875. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5876. {
  5877. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5878. }
  5879. }
  5880. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5881. }
  5882. else
  5883. {
  5884. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5885. {
  5886. tempIndex = 2;
  5887. }
  5888. else
  5889. {
  5890. tempIndex = gun_index;
  5891. }
  5892. for (int index = 0; index < AC_QUANTITY; index++)
  5893. {
  5894. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5895. {
  5896. 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
  5897. }
  5898. } // END OF FOR AC_QUANTITY
  5899. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5900. }
  5901. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5902. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5903. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5904. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5905. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5906. }
  5907. //====================== End SoC ================================
  5908. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5909. {
  5910. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5911. 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))
  5912. {
  5913. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5914. {
  5915. tempIndex = ((gun_index==2) ? 1: 0);
  5916. }
  5917. else
  5918. {
  5919. tempIndex = gun_index;
  5920. }
  5921. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5922. {
  5923. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5924. {
  5925. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5926. {
  5927. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5928. }
  5929. }
  5930. }
  5931. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5932. {
  5933. for (int index = 0; index < CCS_QUANTITY; index++)
  5934. {
  5935. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5936. {
  5937. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5938. }
  5939. }
  5940. }
  5941. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5942. {
  5943. for (int index = 0; index < GB_QUANTITY; index++)
  5944. {
  5945. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5946. {
  5947. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5948. }
  5949. }
  5950. }
  5951. else if(gunType[gun_index] == GUN_TYPE_DO)
  5952. {
  5953. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5954. {
  5955. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5956. {
  5957. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5958. }
  5959. }
  5960. }
  5961. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5962. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5963. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5964. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5965. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5966. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5967. } // END FOR DC CASE
  5968. }
  5969. // ================================= Current.Import L2 ===============================================
  5970. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5971. {
  5972. // AC 3 phse L2 current
  5973. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5974. {
  5975. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5976. {
  5977. tempIndex = 2;
  5978. }
  5979. else
  5980. {
  5981. tempIndex = gun_index;
  5982. }
  5983. for (int index = 0; index < AC_QUANTITY; index++)
  5984. {
  5985. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5986. {
  5987. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5988. }
  5989. }// End of for AC_QUANTITY
  5990. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5991. }
  5992. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5993. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5994. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5995. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5996. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5997. }
  5998. // ================================= Current.Import L3 ===============================================
  5999. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6000. {
  6001. // AC 3 phse L3 current
  6002. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6003. {
  6004. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6005. {
  6006. tempIndex = 2;
  6007. }
  6008. else
  6009. {
  6010. tempIndex = gun_index;
  6011. }
  6012. for (int index = 0; index < AC_QUANTITY; index++)
  6013. {
  6014. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6015. {
  6016. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6017. }
  6018. }// End of for AC_QUANTITY
  6019. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6020. }
  6021. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6022. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6023. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6024. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6025. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6026. }
  6027. //============================ Voltage L2 ====================================
  6028. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6029. {
  6030. // AC 3 phse L2 voltage
  6031. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6032. {
  6033. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6034. {
  6035. tempIndex = 2;
  6036. }
  6037. else
  6038. {
  6039. tempIndex = gun_index;
  6040. }
  6041. for (int index = 0; index < AC_QUANTITY; index++)
  6042. {
  6043. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6044. {
  6045. 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
  6046. }
  6047. } // END OF FOR AC_QUANTITY
  6048. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6049. }
  6050. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6051. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6052. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6053. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6054. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6055. }
  6056. //============================ Voltage L3 ====================================
  6057. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6058. {
  6059. // AC 3 phse L3 voltage
  6060. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6061. {
  6062. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6063. {
  6064. tempIndex = 2;
  6065. }
  6066. else
  6067. {
  6068. tempIndex = gun_index;
  6069. }
  6070. for (int index = 0; index < AC_QUANTITY; index++)
  6071. {
  6072. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6073. {
  6074. 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
  6075. }
  6076. } // END OF FOR AC_QUANTITY
  6077. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6078. }
  6079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6081. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6082. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6084. }
  6085. //====================== Start SoC ================================
  6086. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6087. {
  6088. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6089. 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))
  6090. {
  6091. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6092. {
  6093. tempIndex = ((gun_index==2) ? 1: 0);
  6094. }
  6095. else
  6096. {
  6097. tempIndex = gun_index;
  6098. }
  6099. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6100. {
  6101. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6102. {
  6103. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6104. {
  6105. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6106. }
  6107. }
  6108. }
  6109. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6110. {
  6111. for (int index = 0; index < CCS_QUANTITY; index++)
  6112. {
  6113. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6114. {
  6115. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6116. }
  6117. }
  6118. }
  6119. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6120. {
  6121. for (int index = 0; index < GB_QUANTITY; index++)
  6122. {
  6123. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6124. {
  6125. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6126. }
  6127. }
  6128. }
  6129. else if(gunType[gun_index] == GUN_TYPE_DO)
  6130. {
  6131. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6132. {
  6133. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6134. {
  6135. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6136. }
  6137. }
  6138. }
  6139. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6140. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6141. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6142. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6143. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6144. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6145. } // END FOR DC CASE
  6146. }
  6147. //================================================ Message create ====================================================
  6148. json_object *StopTransaction = json_object_new_object();
  6149. json_object *transactionDatas = json_object_new_array();
  6150. json_object *sampledValues = json_object_new_array();
  6151. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6152. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6153. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6154. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6155. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6156. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6157. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6158. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6159. {
  6160. json_object *transactionData = json_object_new_object();
  6161. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6162. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6163. {
  6164. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6165. {
  6166. json_object *sampledValue = json_object_new_object();
  6167. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6168. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6169. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6170. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6171. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6172. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6173. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6174. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6175. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6176. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6177. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6178. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6179. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6180. json_object_array_add(sampledValues, sampledValue);
  6181. }
  6182. }
  6183. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6184. json_object_array_add(transactionDatas, transactionData);
  6185. }
  6186. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6187. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6188. ,MESSAGE_TYPE_CALL
  6189. ,guid
  6190. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6191. json_object_put(StopTransaction);
  6192. #if 1 // for TempStopTransaction
  6193. //Delete TempStopTransaction
  6194. if((access(TempStopTransaction,F_OK))!=-1)
  6195. {
  6196. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6197. }
  6198. #endif
  6199. #if 1
  6200. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6201. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6202. {
  6203. result = PASS;
  6204. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6205. }
  6206. #endif
  6207. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6208. OCPP_insert_transaction_msg(NO, queuedata);
  6209. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6210. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6211. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6212. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6213. {
  6214. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6215. }
  6216. //for test
  6217. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6218. return result;
  6219. }
  6220. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6221. {
  6222. mtrace();
  6223. int result = FAIL;
  6224. char guid[37]={0};
  6225. char tempdata[65]={0};
  6226. int tempIndex = 0;
  6227. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6228. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6229. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6230. //set value
  6231. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6232. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6233. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6234. -1);
  6235. random_uuid(guid);
  6236. //UTC Date time
  6237. struct timeval tmnow;
  6238. struct tm *tm;
  6239. char buf[28];//, usec_buf[6];
  6240. gettimeofday(&tmnow, NULL);
  6241. time_t t;
  6242. t = time(NULL);
  6243. /*UTC time and date*/
  6244. tm = gmtime(&t);
  6245. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6246. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6247. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6248. //********************************(1)Current.Import L1************************************************/
  6249. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6250. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6251. (dataType == ReadingContext_Trigger))
  6252. {
  6253. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6254. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6255. {
  6256. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6257. {
  6258. tempIndex = ((gun_index==2) ? 1: 0);
  6259. }
  6260. else
  6261. {
  6262. tempIndex = gun_index;
  6263. }
  6264. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6265. {
  6266. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6267. {
  6268. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6269. }
  6270. }
  6271. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6272. }
  6273. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6274. {
  6275. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6276. {
  6277. tempIndex = ((gun_index==2) ? 1: 0);
  6278. }
  6279. else
  6280. {
  6281. tempIndex = gun_index;
  6282. }
  6283. for (int index = 0; index < CCS_QUANTITY; index++)
  6284. {
  6285. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6286. {
  6287. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6288. }
  6289. }
  6290. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6291. }
  6292. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6293. {
  6294. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6295. {
  6296. tempIndex = ((gun_index==2) ? 1: 0);
  6297. }
  6298. else
  6299. {
  6300. tempIndex = gun_index;
  6301. }
  6302. for (int index = 0; index < GB_QUANTITY; index++)
  6303. {
  6304. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6305. {
  6306. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6307. }
  6308. }
  6309. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6310. }
  6311. else if(gunType[gun_index] == GUN_TYPE_DO)
  6312. {
  6313. tempIndex = gun_index;
  6314. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6315. {
  6316. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6317. {
  6318. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6319. }
  6320. }
  6321. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6322. }
  6323. else
  6324. {
  6325. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6326. {
  6327. tempIndex = 2;
  6328. }
  6329. else
  6330. {
  6331. tempIndex = gun_index;
  6332. }
  6333. for (int index = 0; index < AC_QUANTITY; index++)
  6334. {
  6335. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6336. {
  6337. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6338. }
  6339. }
  6340. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6341. }
  6342. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6343. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6344. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6345. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6346. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6347. }
  6348. //********************************(2)Energy.Active.Import.Register ************************************************/
  6349. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6350. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6351. (dataType == ReadingContext_Trigger))
  6352. {
  6353. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6354. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  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 < CHAdeMO_QUANTITY; index++)
  6365. {
  6366. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6367. {
  6368. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6369. }
  6370. }
  6371. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6372. }
  6373. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6374. {
  6375. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6376. {
  6377. tempIndex = ((gun_index==2) ? 1: 0);
  6378. }
  6379. else
  6380. {
  6381. tempIndex = gun_index;
  6382. }
  6383. for (int index = 0; index < CCS_QUANTITY; index++)
  6384. {
  6385. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6386. {
  6387. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6388. }
  6389. }
  6390. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6391. }
  6392. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6393. {
  6394. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6395. {
  6396. tempIndex = ((gun_index==2) ? 1: 0);
  6397. }
  6398. else
  6399. {
  6400. tempIndex = gun_index;
  6401. }
  6402. for (int index = 0; index < GB_QUANTITY; index++)
  6403. {
  6404. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6405. {
  6406. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6407. }
  6408. }
  6409. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6410. }
  6411. else if(gunType[gun_index] == GUN_TYPE_DO)
  6412. {
  6413. tempIndex = gun_index;
  6414. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6415. {
  6416. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6417. {
  6418. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6419. }
  6420. }
  6421. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6422. }
  6423. else
  6424. {
  6425. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6426. {
  6427. tempIndex = 2;
  6428. }
  6429. else
  6430. {
  6431. tempIndex = gun_index;
  6432. }
  6433. for (int index = 0; index < AC_QUANTITY; index++)
  6434. {
  6435. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6436. {
  6437. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6438. }
  6439. }
  6440. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6441. }
  6442. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6443. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6444. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6445. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6446. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6447. }
  6448. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6449. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6450. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6451. (dataType == ReadingContext_Trigger))
  6452. {
  6453. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6454. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  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 < CHAdeMO_QUANTITY; index++)
  6465. {
  6466. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6467. {
  6468. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6469. }
  6470. } // END OF FOR CHAdeMO_QUANTITY
  6471. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6472. }
  6473. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6474. {
  6475. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6476. {
  6477. tempIndex = ((gun_index==2) ? 1: 0);
  6478. }
  6479. else
  6480. {
  6481. tempIndex = gun_index;
  6482. }
  6483. for (int index = 0; index < CCS_QUANTITY; index++)
  6484. {
  6485. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6486. {
  6487. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6488. }
  6489. } // END OF CCS_QUANTITY
  6490. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6491. }
  6492. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6493. {
  6494. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6495. {
  6496. tempIndex = ((gun_index==2) ? 1: 0);
  6497. }
  6498. else
  6499. {
  6500. tempIndex = gun_index;
  6501. }
  6502. for (int index = 0; index < GB_QUANTITY; index++)
  6503. {
  6504. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6505. {
  6506. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6507. }
  6508. } // END OF GB_QUANTITY
  6509. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6510. }
  6511. else if(gunType[gun_index] == GUN_TYPE_DO)
  6512. {
  6513. tempIndex = gun_index;
  6514. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6515. {
  6516. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6517. {
  6518. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6519. }
  6520. }
  6521. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6522. }
  6523. else
  6524. {
  6525. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6526. {
  6527. tempIndex = 2;
  6528. }
  6529. else
  6530. {
  6531. tempIndex = gun_index;
  6532. }
  6533. for (int index = 0; index < AC_QUANTITY; index++)
  6534. {
  6535. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6536. {
  6537. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6538. }
  6539. }
  6540. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6541. }
  6542. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6543. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6544. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6545. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6546. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6547. }
  6548. //********************************(4)Power.Active.Import************************************************/
  6549. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6550. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6551. (dataType == ReadingContext_Trigger))
  6552. {
  6553. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6554. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  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 < CHAdeMO_QUANTITY; index++)
  6565. {
  6566. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6567. {
  6568. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6569. }
  6570. } // END OF FOR
  6571. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6572. }
  6573. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6574. {
  6575. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6576. {
  6577. tempIndex = ((gun_index==2) ? 1: 0);
  6578. }
  6579. else
  6580. {
  6581. tempIndex = gun_index;
  6582. }
  6583. for (int index = 0; index < CCS_QUANTITY; index++)
  6584. {
  6585. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6586. {
  6587. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6588. }
  6589. }
  6590. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6591. }
  6592. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6593. {
  6594. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6595. {
  6596. tempIndex = ((gun_index==2) ? 1: 0);
  6597. }
  6598. else
  6599. {
  6600. tempIndex = gun_index;
  6601. }
  6602. for (int index = 0; index < GB_QUANTITY; index++)
  6603. {
  6604. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6605. {
  6606. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6607. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6608. }
  6609. }
  6610. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6611. }
  6612. else if(gunType[gun_index] == GUN_TYPE_DO)
  6613. {
  6614. tempIndex = gun_index;
  6615. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6616. {
  6617. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6618. {
  6619. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6620. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6621. }
  6622. }
  6623. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6624. }
  6625. else
  6626. {
  6627. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6628. {
  6629. tempIndex = 2;
  6630. }
  6631. else
  6632. {
  6633. tempIndex = gun_index;
  6634. }
  6635. for (int index = 0; index < AC_QUANTITY; index++)
  6636. {
  6637. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6638. {
  6639. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6640. }
  6641. }
  6642. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6643. }
  6644. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6645. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6646. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6647. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6648. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6649. }
  6650. //***********************************************(5)VOLTAGE L1******************************************************/
  6651. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6652. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6653. (dataType == ReadingContext_Trigger))
  6654. {
  6655. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6656. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6657. {
  6658. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6659. {
  6660. tempIndex = ((gun_index==2) ? 1: 0);
  6661. }
  6662. else
  6663. {
  6664. tempIndex = gun_index;
  6665. }
  6666. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6667. {
  6668. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6669. {
  6670. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6671. }
  6672. }
  6673. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6674. }
  6675. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6676. {
  6677. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6678. {
  6679. tempIndex = ((gun_index==2) ? 1: 0);
  6680. }
  6681. else
  6682. {
  6683. tempIndex = gun_index;
  6684. }
  6685. for (int index = 0; index < CCS_QUANTITY; index++)
  6686. {
  6687. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6688. {
  6689. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6690. }
  6691. }
  6692. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6693. }
  6694. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6695. {
  6696. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6697. {
  6698. tempIndex = ((gun_index==2) ? 1: 0);
  6699. }
  6700. else
  6701. {
  6702. tempIndex = gun_index;
  6703. }
  6704. for (int index = 0; index < GB_QUANTITY; index++)
  6705. {
  6706. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6707. {
  6708. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6709. }
  6710. }
  6711. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6712. }
  6713. else if(gunType[gun_index] == GUN_TYPE_DO)
  6714. {
  6715. tempIndex = gun_index;
  6716. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6717. {
  6718. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6719. {
  6720. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6721. }
  6722. }
  6723. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6724. }
  6725. else
  6726. {
  6727. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6728. {
  6729. tempIndex = 2;
  6730. }
  6731. else
  6732. {
  6733. tempIndex = gun_index;
  6734. }
  6735. for (int index = 0; index < AC_QUANTITY; index++)
  6736. {
  6737. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6738. {
  6739. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6740. }
  6741. }
  6742. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6743. }
  6744. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6745. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6746. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6747. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6748. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6749. }
  6750. //***********************************************(6)SOC******************************************************/
  6751. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6752. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6753. (dataType == ReadingContext_Trigger))
  6754. {
  6755. 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))
  6756. {
  6757. //idx_sample=5;
  6758. //sampledValue = NULL;
  6759. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6760. {
  6761. tempIndex = ((gun_index==2) ? 1: 0);
  6762. }
  6763. else
  6764. {
  6765. tempIndex = gun_index;
  6766. }
  6767. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6768. {
  6769. //tempIndex = ((gun_index==2) ? 1: 0);
  6770. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6771. {
  6772. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6773. {
  6774. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6775. }
  6776. }
  6777. }
  6778. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6779. {
  6780. //tempIndex = ((gun_index==2) ? 1: 0);
  6781. for (int index = 0; index < CCS_QUANTITY; index++)
  6782. {
  6783. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6784. {
  6785. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6786. }
  6787. }
  6788. }
  6789. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6790. {
  6791. //tempIndex = ((gun_index==2) ? 1: 0);
  6792. for (int index = 0; index < GB_QUANTITY; index++)
  6793. {
  6794. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6795. {
  6796. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6797. }
  6798. }
  6799. }
  6800. else if(gunType[gun_index] == GUN_TYPE_DO)
  6801. {
  6802. //tempIndex = ((gun_index==2) ? 1: 0);
  6803. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6804. {
  6805. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6806. {
  6807. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6808. }
  6809. }
  6810. }
  6811. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6812. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6813. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6814. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6815. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6816. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6817. }
  6818. }
  6819. //********************************(7)Current.Import L2************************************************/
  6820. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6821. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6822. (dataType == ReadingContext_Trigger))
  6823. {
  6824. // Only for AC 3 phase
  6825. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6826. {
  6827. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6828. {
  6829. tempIndex = 2;
  6830. }
  6831. else
  6832. {
  6833. tempIndex = gun_index;
  6834. }
  6835. for (int index = 0; index < AC_QUANTITY; index++)
  6836. {
  6837. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6838. {
  6839. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6840. }
  6841. }
  6842. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6843. }
  6844. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6845. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6846. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6847. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6848. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6849. }
  6850. //********************************(8)Current.Import L3************************************************/
  6851. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6852. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6853. (dataType == ReadingContext_Trigger))
  6854. {
  6855. // Only for AC 3 phase
  6856. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6857. {
  6858. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6859. {
  6860. tempIndex = 2;
  6861. }
  6862. else
  6863. {
  6864. tempIndex = gun_index;
  6865. }
  6866. for (int index = 0; index < AC_QUANTITY; index++)
  6867. {
  6868. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6869. {
  6870. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6871. }
  6872. }
  6873. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6874. }
  6875. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6876. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6877. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6878. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6879. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6880. }
  6881. //***********************************************(9)VOLTAGE L2******************************************************/
  6882. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6883. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6884. (dataType == ReadingContext_Trigger))
  6885. {
  6886. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6887. {
  6888. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6889. {
  6890. tempIndex = 2;
  6891. }
  6892. else
  6893. {
  6894. tempIndex = gun_index;
  6895. }
  6896. for (int index = 0; index < AC_QUANTITY; index++)
  6897. {
  6898. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6899. {
  6900. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6901. }
  6902. }
  6903. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6904. }
  6905. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6906. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6907. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6908. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6909. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6910. }
  6911. //***********************************************(10)VOLTAGE L3******************************************************/
  6912. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6913. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6914. (dataType == ReadingContext_Trigger))
  6915. {
  6916. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6917. {
  6918. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6919. {
  6920. tempIndex = 2;
  6921. }
  6922. else
  6923. {
  6924. tempIndex = gun_index;
  6925. }
  6926. for (int index = 0; index < AC_QUANTITY; index++)
  6927. {
  6928. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6929. {
  6930. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6931. }
  6932. }
  6933. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6934. }
  6935. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6936. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6937. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6938. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6939. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6940. }
  6941. //***********************************************(11)Current.Offered******************************************************/
  6942. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6943. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6944. (dataType == ReadingContext_Trigger))
  6945. {
  6946. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6947. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6948. {
  6949. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6950. {
  6951. tempIndex = ((gun_index==2) ? 1: 0);
  6952. }
  6953. else
  6954. {
  6955. tempIndex = gun_index;
  6956. }
  6957. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6958. {
  6959. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6960. {
  6961. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  6962. }
  6963. } // END OF FOR CHAdeMO_QUANTITY
  6964. }
  6965. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6966. {
  6967. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6968. {
  6969. tempIndex = ((gun_index==2) ? 1: 0);
  6970. }
  6971. else
  6972. {
  6973. tempIndex = gun_index;
  6974. }
  6975. for (int index = 0; index < CCS_QUANTITY; index++)
  6976. {
  6977. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6978. {
  6979. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  6980. }
  6981. } // END OF CCS_QUANTITY
  6982. }
  6983. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6984. {
  6985. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6986. {
  6987. tempIndex = ((gun_index==2) ? 1: 0);
  6988. }
  6989. else
  6990. {
  6991. tempIndex = gun_index;
  6992. }
  6993. for (int index = 0; index < GB_QUANTITY; index++)
  6994. {
  6995. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6996. {
  6997. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  6998. }
  6999. } // END OF GB_QUANTITY
  7000. }
  7001. else if(gunType[gun_index] == GUN_TYPE_DO)
  7002. {
  7003. tempIndex = gun_index;
  7004. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7005. {
  7006. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7007. {
  7008. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7009. }
  7010. }
  7011. }
  7012. else
  7013. {
  7014. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7015. {
  7016. tempIndex = 2;
  7017. }
  7018. else
  7019. {
  7020. tempIndex = gun_index;
  7021. }
  7022. for (int index = 0; index < AC_QUANTITY; index++)
  7023. {
  7024. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7025. {
  7026. uint16_t currentOffer;
  7027. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7028. {
  7029. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7030. }
  7031. else
  7032. {
  7033. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7034. }
  7035. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7036. }
  7037. }
  7038. }
  7039. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7040. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7041. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7042. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7043. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7044. }
  7045. //***********************************************(12)Power.Offered******************************************************/
  7046. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7047. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7048. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7049. {
  7050. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7051. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7052. {
  7053. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7054. {
  7055. tempIndex = ((gun_index==2) ? 1: 0);
  7056. }
  7057. else
  7058. {
  7059. tempIndex = gun_index;
  7060. }
  7061. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7062. {
  7063. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7064. {
  7065. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7066. }
  7067. } // END OF FOR CHAdeMO_QUANTITY
  7068. }
  7069. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7070. {
  7071. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7072. {
  7073. tempIndex = ((gun_index==2) ? 1: 0);
  7074. }
  7075. else
  7076. {
  7077. tempIndex = gun_index;
  7078. }
  7079. for (int index = 0; index < CCS_QUANTITY; index++)
  7080. {
  7081. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7082. {
  7083. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7084. }
  7085. } // END OF CCS_QUANTITY
  7086. }
  7087. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7088. {
  7089. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7090. {
  7091. tempIndex = ((gun_index==2) ? 1: 0);
  7092. }
  7093. else
  7094. {
  7095. tempIndex = gun_index;
  7096. }
  7097. for (int index = 0; index < GB_QUANTITY; index++)
  7098. {
  7099. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7100. {
  7101. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7102. }
  7103. } // END OF GB_QUANTITY
  7104. }
  7105. else if(gunType[gun_index] == GUN_TYPE_DO)
  7106. {
  7107. tempIndex = gun_index;
  7108. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7109. {
  7110. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7111. {
  7112. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7113. }
  7114. }
  7115. }
  7116. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7117. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7118. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7119. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7120. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7121. }
  7122. // Message create ====================================================================================================
  7123. if(TRUE)
  7124. {
  7125. json_object *MeterValueReq = json_object_new_object();
  7126. json_object *MeterValues = json_object_new_array();
  7127. json_object *sampledValues = json_object_new_array();
  7128. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7129. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7130. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7131. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7132. {
  7133. json_object *MeterValue = json_object_new_object();
  7134. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7135. {
  7136. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7137. {
  7138. json_object *sampledValue = json_object_new_object();
  7139. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7140. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7141. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7142. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7143. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7144. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7145. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7146. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7147. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7148. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7149. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7150. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7151. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7152. json_object_array_add(sampledValues, sampledValue);
  7153. }
  7154. }
  7155. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7156. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7157. json_object_array_add(MeterValues, MeterValue);
  7158. }
  7159. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7160. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7161. ,gun_index + 1
  7162. ,MESSAGE_TYPE_CALL
  7163. ,guid
  7164. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7165. json_object_put(MeterValueReq);
  7166. }
  7167. // Put request guid to hash map
  7168. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7169. 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*/)
  7170. {
  7171. result = PASS;
  7172. //DEBUG_INFO("MeterValues mapitem pass\n");
  7173. }
  7174. if((dataType != ReadingContext_Trigger) &&
  7175. (dataType != ReadingContext_Sample_Clock) &&
  7176. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7177. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7178. else
  7179. {
  7180. if(FirstHeartBeat)
  7181. LWS_Send(queuedata +2);
  7182. }
  7183. return result;
  7184. }
  7185. int sendLogStatusNotificationRequest(char *status)
  7186. {
  7187. mtrace();
  7188. int result = PASS;
  7189. char message[4096]={0};
  7190. char guid[37]={0};
  7191. char tempdata[128]={0};
  7192. json_object *LogStatusNotification = json_object_new_object();
  7193. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7194. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7195. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7196. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7197. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7198. random_uuid(guid);
  7199. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7200. json_object_put(LogStatusNotification);
  7201. LWS_Send(message);
  7202. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7203. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7204. {
  7205. result = PASS;
  7206. }
  7207. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7208. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7209. return result;
  7210. }
  7211. int sendSecurityEventNotificationRequest()
  7212. {
  7213. mtrace();
  7214. int result = PASS;
  7215. char message[4096]={0};
  7216. char guid[37]={0};
  7217. char tempdata[128]={0};
  7218. json_object *SecurityEventNotification = json_object_new_object();
  7219. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7220. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7221. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7222. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7223. random_uuid(guid);
  7224. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7225. json_object_put(SecurityEventNotification);
  7226. LWS_Send(message);
  7227. sprintf(tempdata, "SecurityEventNotification,0");
  7228. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7229. {
  7230. result = PASS;
  7231. }
  7232. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7233. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7234. return result;
  7235. }
  7236. int sendSignCertificateRequest()
  7237. {
  7238. mtrace();
  7239. int result = PASS;
  7240. char message[4096]={0};
  7241. char guid[37]={0};
  7242. char tempdata[128]={0};
  7243. json_object *SignCertificate = json_object_new_object();
  7244. DEBUG_INFO("sendSignCertificateRequest...\n");
  7245. // Read csr file content
  7246. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7247. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7248. char *line = NULL;
  7249. size_t len = 0;
  7250. while(getline(&line, &len, fp) != -1)
  7251. {
  7252. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7253. {
  7254. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7255. }
  7256. }
  7257. fclose(fp);
  7258. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7259. random_uuid(guid);
  7260. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7261. json_object_put(SignCertificate);
  7262. LWS_Send(message);
  7263. sprintf(tempdata, "SignCertificate,0");
  7264. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7265. {
  7266. result = PASS;
  7267. }
  7268. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7269. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7270. return result;
  7271. }
  7272. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7273. {
  7274. mtrace();
  7275. int result = PASS;
  7276. char message[110]={0};
  7277. char guid[37]={0};
  7278. char tempdata[65]={0};
  7279. json_object *FirmwareStatusNotification = json_object_new_object();
  7280. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7281. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7282. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7283. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7284. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7285. random_uuid(guid);
  7286. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7287. json_object_put(FirmwareStatusNotification);
  7288. LWS_Send(message);
  7289. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7290. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7291. {
  7292. result = PASS;
  7293. }
  7294. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7295. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7296. return result;
  7297. }
  7298. //==========================================
  7299. // send confirm routine
  7300. //==========================================
  7301. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7302. {
  7303. mtrace();
  7304. int result = FAIL;
  7305. char message[100]={0};
  7306. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7307. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7308. LWS_Send(message);
  7309. result = TRUE;
  7310. return result;
  7311. }
  7312. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7313. {
  7314. mtrace();
  7315. int result = FAIL;
  7316. char message[100]={0};
  7317. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7318. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7319. LWS_Send(message);
  7320. result = TRUE;
  7321. return result;
  7322. }
  7323. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7324. {
  7325. mtrace();
  7326. int result = FAIL;
  7327. char message[100]={0};
  7328. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7329. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7330. LWS_Send(message);
  7331. result = TRUE;
  7332. return result;
  7333. }
  7334. int sendClearCacheConfirmation(char *uuid,char *payload)
  7335. {
  7336. mtrace();
  7337. int result = FAIL;
  7338. char message[500]={0};
  7339. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7340. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7341. LWS_Send(message);
  7342. return result;
  7343. }
  7344. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7345. {
  7346. mtrace();
  7347. int result = FAIL;
  7348. char message[500]={0};
  7349. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7350. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7351. LWS_Send(message);
  7352. return result;
  7353. }
  7354. int sendDataTransferConfirmation(char *uuid,char *payload)
  7355. {
  7356. mtrace();
  7357. char statusStr[20]={0};
  7358. char dataStr[10]={0};
  7359. char sstr[20]={0};
  7360. int c = 0;
  7361. char *loc;
  7362. int result = FAIL;
  7363. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7364. /**********************status**************************/
  7365. loc = strstr(payload, "status");
  7366. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7367. c = 0;
  7368. while (loc[3+strlen("status")+c] != '\"')
  7369. {
  7370. sstr[c] = loc[3+strlen("status")+c];
  7371. c++;
  7372. }
  7373. sstr[c] = '\0';
  7374. strcpy(statusStr, sstr);
  7375. /**********************data**************************/
  7376. loc = strstr(payload, "data");
  7377. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7378. c = 0;
  7379. while (loc[3+strlen("data")+c] != '\"')
  7380. {
  7381. sstr[c] = loc[3+strlen("data")+c];
  7382. c++;
  7383. }
  7384. sstr[c] = '\0';
  7385. strcpy(dataStr, sstr);
  7386. return result;
  7387. }
  7388. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7389. {
  7390. mtrace();
  7391. int result = FAIL;
  7392. char message[1000]={0};
  7393. int CompositeScheduleIndex = 0;
  7394. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7395. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7396. if(nPeriod == 0)
  7397. {
  7398. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7399. {
  7400. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7401. ,MESSAGE_TYPE_CALLRESULT
  7402. ,uuid
  7403. ,payload
  7404. ,connectorIdInt);
  7405. }
  7406. else
  7407. {
  7408. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7409. ,MESSAGE_TYPE_CALLRESULT
  7410. ,uuid
  7411. ,payload
  7412. ,connectorIdInt
  7413. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7414. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7415. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7416. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7417. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7418. }
  7419. }
  7420. else
  7421. {
  7422. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7423. ,MESSAGE_TYPE_CALLRESULT
  7424. ,uuid
  7425. ,payload
  7426. ,connectorIdInt
  7427. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7428. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7429. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7430. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7431. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7432. {
  7433. if (idx_sample == 0)
  7434. {
  7435. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7436. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7437. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7438. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7439. }
  7440. else
  7441. {
  7442. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7443. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7444. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7445. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7446. }
  7447. }
  7448. sprintf(message + strlen(message), "]}}]");
  7449. }
  7450. LWS_Send(message);
  7451. result = TRUE;
  7452. return result;
  7453. }
  7454. int sendGetConfigurationConfirmation(char *uuid)
  7455. {
  7456. mtrace();
  7457. int result = FAIL;
  7458. int MaxKeySupported = 0;
  7459. int sentConfigurationNumber= 0;
  7460. int sentunConfigurationNumber= 0;
  7461. char message[1024*10]={0};
  7462. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7463. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7464. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7465. ,MESSAGE_TYPE_CALLRESULT
  7466. ,uuid );
  7467. //configuration key
  7468. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7469. {
  7470. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7471. {
  7472. if (sentConfigurationNumber == 0)
  7473. {
  7474. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7475. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7476. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7477. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7478. }
  7479. else
  7480. {
  7481. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7482. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7483. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7484. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7485. }
  7486. sentConfigurationNumber = sentConfigurationNumber + 1;
  7487. }
  7488. }
  7489. sprintf(message + strlen(message), "]");
  7490. if(UnknownKeynum != 0)
  7491. {
  7492. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7493. //unkown key
  7494. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7495. {
  7496. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7497. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7498. if(sentunConfigurationNumber == 0)
  7499. {
  7500. sprintf(message + strlen(message), "\"%s\""
  7501. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7502. }
  7503. else
  7504. {
  7505. sprintf(message + strlen(message), ",\"%s\""
  7506. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7507. }
  7508. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7509. }
  7510. sprintf(message + strlen(message), "]");
  7511. }
  7512. sprintf(message + strlen(message), "}]");
  7513. LWS_Send(message);
  7514. return result;
  7515. }
  7516. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7517. {
  7518. mtrace();
  7519. int result = FAIL;
  7520. char message[400]={0};
  7521. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7522. if(strcmp(payload,"")==0)
  7523. {
  7524. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7525. }
  7526. else
  7527. {
  7528. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7529. }
  7530. LWS_Send(message);
  7531. result = TRUE;
  7532. return result;
  7533. }
  7534. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7535. {
  7536. mtrace();
  7537. int result = FAIL;
  7538. char message[80]={0};
  7539. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7540. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  7541. LWS_Send(message);
  7542. result = TRUE;
  7543. return result;
  7544. }
  7545. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7546. {
  7547. mtrace();
  7548. int result = FAIL;
  7549. char message[80]={0};
  7550. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7551. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7552. LWS_Send(message);
  7553. result = TRUE;
  7554. return result;
  7555. }
  7556. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7557. {
  7558. mtrace();
  7559. int result = FAIL;
  7560. char message[80]={0};
  7561. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7562. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7563. LWS_Send(message);
  7564. result = TRUE;
  7565. return result;
  7566. }
  7567. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7568. {
  7569. mtrace();
  7570. int result = FAIL;
  7571. char message[80]={0};
  7572. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7573. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7574. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7575. LWS_Send(message);
  7576. result = TRUE;
  7577. return result;
  7578. }
  7579. int sendResetConfirmation(char *uuid,char *payload)
  7580. {
  7581. mtrace();
  7582. int result = FAIL;
  7583. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7584. char message[80]={0};
  7585. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  7586. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7587. LWS_Send(message);
  7588. result = TRUE;
  7589. return result;
  7590. }
  7591. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7592. {
  7593. mtrace();
  7594. int result = FAIL;
  7595. char message[500]={0};
  7596. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7597. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7598. LWS_Send(message);
  7599. result = TRUE;
  7600. return result;
  7601. }
  7602. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7603. {
  7604. mtrace();
  7605. int result = FAIL;
  7606. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7607. char message[80]={0};
  7608. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7609. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7610. LWS_Send(message);
  7611. result = TRUE;
  7612. return result;
  7613. }
  7614. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7615. {
  7616. mtrace();
  7617. int result = FAIL;
  7618. char message[80]={0};
  7619. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7620. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7621. LWS_Send(message);
  7622. result = TRUE;
  7623. return result;
  7624. }
  7625. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7626. {
  7627. mtrace();
  7628. int result = FAIL;
  7629. char message[80]={0};
  7630. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7631. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7632. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7633. LWS_Send(message);
  7634. result = TRUE;
  7635. return result;
  7636. }
  7637. int sendUpdateFirmwareConfirmation(char *uuid)
  7638. {
  7639. mtrace();
  7640. int result = FAIL;
  7641. char message[60]={0};
  7642. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7643. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7644. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7645. LWS_Send(message);
  7646. result = TRUE;
  7647. return result;
  7648. }
  7649. int sendCertificateSignedConfirmation(char *uuid)
  7650. {
  7651. mtrace();
  7652. int result = PASS;
  7653. char message[4096]={0};
  7654. json_object *CertificateSigned = json_object_new_object();
  7655. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7656. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  7657. sprintf(message,"[%d,\"%s\",%s]"
  7658. ,MESSAGE_TYPE_CALLRESULT
  7659. ,uuid
  7660. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7661. json_object_put(CertificateSigned);
  7662. LWS_Send(message);
  7663. return result;
  7664. }
  7665. int sendDeleteCertificateConfirmation(char *uuid)
  7666. {
  7667. mtrace();
  7668. int result = PASS;
  7669. char message[4096]={0};
  7670. json_object *DeleteCertificate = json_object_new_object();
  7671. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7672. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  7673. sprintf(message,"[%d,\"%s\",%s]"
  7674. ,MESSAGE_TYPE_CALLRESULT
  7675. ,uuid
  7676. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7677. json_object_put(DeleteCertificate);
  7678. LWS_Send(message);
  7679. return result;
  7680. }
  7681. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7682. {
  7683. mtrace();
  7684. int result = PASS;
  7685. char message[4096]={0};
  7686. json_object *ExtendedTriggerMessage = json_object_new_object();
  7687. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7688. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  7689. sprintf(message,"[%d,\"%s\",%s]"
  7690. ,MESSAGE_TYPE_CALLRESULT
  7691. ,uuid
  7692. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7693. json_object_put(ExtendedTriggerMessage);
  7694. LWS_Send(message);
  7695. return result;
  7696. }
  7697. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7698. {
  7699. mtrace();
  7700. int result = PASS;
  7701. char message[4096]={0};
  7702. json_object *GetInstalledCertificateIds = json_object_new_object();
  7703. json_object *certificateHashDataDatas = json_object_new_array();
  7704. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7705. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  7706. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7707. {
  7708. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7709. {
  7710. json_object *certificateHashData = json_object_new_object();
  7711. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7712. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7713. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7714. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7715. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7716. }
  7717. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7718. }
  7719. else
  7720. {
  7721. json_object_put(certificateHashDataDatas);
  7722. }
  7723. sprintf(message,"[%d,\"%s\",%s]"
  7724. ,MESSAGE_TYPE_CALLRESULT
  7725. ,uuid
  7726. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7727. json_object_put(GetInstalledCertificateIds);
  7728. LWS_Send(message);
  7729. return result;
  7730. }
  7731. int sendGetLogConfirmation(char *uuid)
  7732. {
  7733. mtrace();
  7734. int result = PASS;
  7735. char message[4096]={0};
  7736. json_object *GetLog = json_object_new_object();
  7737. DEBUG_INFO("sendGetLogConfirmation...\n");
  7738. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  7739. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  7740. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  7741. sprintf(message,"[%d,\"%s\",%s]"
  7742. ,MESSAGE_TYPE_CALLRESULT
  7743. ,uuid
  7744. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7745. json_object_put(GetLog);
  7746. LWS_Send(message);
  7747. return result;
  7748. }
  7749. int sendInstallCertificateConfirmation(char *uuid)
  7750. {
  7751. mtrace();
  7752. int result = PASS;
  7753. char message[4096]={0};
  7754. json_object *InstallCertificate = json_object_new_object();
  7755. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7756. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  7757. sprintf(message,"[%d,\"%s\",%s]"
  7758. ,MESSAGE_TYPE_CALLRESULT
  7759. ,uuid
  7760. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7761. json_object_put(InstallCertificate);
  7762. LWS_Send(message);
  7763. return result;
  7764. }
  7765. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7766. {
  7767. mtrace();
  7768. int result = PASS;
  7769. char message[4096]={0};
  7770. json_object *SignedUpdateFirmware = json_object_new_object();
  7771. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7772. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  7773. sprintf(message,"[%d,\"%s\",%s]"
  7774. ,MESSAGE_TYPE_CALLRESULT
  7775. ,uuid
  7776. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7777. json_object_put(SignedUpdateFirmware);
  7778. LWS_Send(message);
  7779. return result;
  7780. }
  7781. int sendUnknownConfirmation(char *uuid)
  7782. {
  7783. mtrace();
  7784. int result = PASS;
  7785. char message[256]={0};
  7786. DEBUG_INFO("sendUnknownConfirmation...\n");
  7787. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7788. LWS_Send(message);
  7789. return result;
  7790. }
  7791. //==========================================
  7792. // Handle server request routine Start
  7793. //==========================================
  7794. int handleCancelReservationRequest(char *uuid, char *payload)
  7795. {
  7796. mtrace();
  7797. int result = FAIL;
  7798. int gunNO = 0;
  7799. int reservationIdInt = -1;
  7800. char comfirmstr[20];
  7801. DEBUG_INFO("handleCancelReservationRequest...\n");
  7802. json_object *CancelReservation;
  7803. CancelReservation = json_tokener_parse(payload);
  7804. if(!is_error(CancelReservation))
  7805. {
  7806. // Required data
  7807. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7808. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7809. }
  7810. json_object_put(CancelReservation);
  7811. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7812. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7813. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7814. if(reservationIdInt != -1)
  7815. {
  7816. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7817. //check Transaction active
  7818. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7819. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7820. {
  7821. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7822. {
  7823. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7824. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7825. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7826. {
  7827. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7828. }
  7829. else
  7830. {
  7831. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7832. }
  7833. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7834. goto end;
  7835. }
  7836. }
  7837. for (int index = 0; index < CCS_QUANTITY; index++)
  7838. {
  7839. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7840. {
  7841. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7842. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7843. if(gunType[2] == GUN_TYPE_CCS)
  7844. {
  7845. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7846. }
  7847. else
  7848. {
  7849. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7850. }
  7851. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7852. goto end;
  7853. }
  7854. }
  7855. for (int index = 0; index < GB_QUANTITY; index++)
  7856. {
  7857. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7858. {
  7859. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7860. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7861. if(gunType[2] == GUN_TYPE_GBT)
  7862. {
  7863. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7864. }
  7865. else
  7866. {
  7867. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7868. }
  7869. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7870. goto end;
  7871. }
  7872. }
  7873. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7874. {
  7875. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7876. {
  7877. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7878. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7879. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7880. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7881. goto end;
  7882. }
  7883. }
  7884. for (int index = 0; index < AC_QUANTITY; index++)
  7885. {
  7886. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7887. {
  7888. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7889. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7890. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7891. {
  7892. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7893. }
  7894. else
  7895. {
  7896. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7897. }
  7898. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7899. goto end;
  7900. }
  7901. }
  7902. }
  7903. //The reservationId does NOT match the reservationId
  7904. sendCancelReservationConfirmation(uuid, comfirmstr);
  7905. end:
  7906. // Fill in ocpp packet uuid
  7907. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  7908. return result;
  7909. }
  7910. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7911. {
  7912. mtrace();
  7913. int result = FAIL;
  7914. int gunIndex = -1;
  7915. char typeStr[16]={0};
  7916. char comfirmstr[20];
  7917. int specificId = FALSE;
  7918. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7919. json_object *ChangeAvailability;
  7920. ChangeAvailability = json_tokener_parse(payload);
  7921. if(!is_error(ChangeAvailability))
  7922. {
  7923. // Required data
  7924. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7925. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7926. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7927. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7928. }
  7929. json_object_put(ChangeAvailability);
  7930. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7931. {
  7932. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7933. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7934. }
  7935. else if(gunIndex == 0)
  7936. {
  7937. for(int i=0; i < gunTotalNumber; i++)
  7938. {
  7939. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  7940. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  7941. }
  7942. }
  7943. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7944. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7945. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7946. {
  7947. specificId = TRUE;
  7948. }
  7949. if(specificId == FALSE)
  7950. goto end;
  7951. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7952. {
  7953. //----------------------gunIndex is 0 ------------------------------------------------//
  7954. if(gunIndex == 0)
  7955. {
  7956. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7957. {
  7958. for(int i=0; i < gunTotalNumber; i++)
  7959. {
  7960. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7961. {
  7962. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7963. {
  7964. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7965. {
  7966. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7967. goto end;
  7968. }
  7969. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7970. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7971. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7972. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7973. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7974. {
  7975. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7976. goto end;
  7977. }
  7978. }
  7979. }//END FOR CHAdeMO_QUANTITY
  7980. for (int index = 0; index < CCS_QUANTITY; index++)
  7981. {
  7982. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7983. {
  7984. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7985. {
  7986. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7987. goto end;
  7988. }
  7989. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7990. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7991. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7992. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7993. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7994. {
  7995. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7996. goto end;
  7997. }
  7998. }
  7999. }//END FOR CCS_QUANTITY
  8000. for (int index = 0; index < GB_QUANTITY; index++)
  8001. {
  8002. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8003. {
  8004. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8005. {
  8006. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8007. goto end;
  8008. }
  8009. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8010. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8011. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8012. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8013. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8014. {
  8015. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8016. goto end;
  8017. }
  8018. }
  8019. }// END FOR GB_QUANTITY
  8020. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8021. {
  8022. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8023. {
  8024. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8025. {
  8026. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8027. goto end;
  8028. }
  8029. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8030. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8031. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8032. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8033. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8034. {
  8035. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8036. goto end;
  8037. }
  8038. }
  8039. }// END FOR GENERAL_GUN_QUANTITY
  8040. for (int index = 0; index < AC_QUANTITY; index++)
  8041. {
  8042. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8043. {
  8044. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8045. {
  8046. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8047. goto end;
  8048. }
  8049. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8050. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8051. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8052. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8053. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8054. {
  8055. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8056. goto end;
  8057. }
  8058. }
  8059. }//END FOR AC_QUANTITY
  8060. }// END FOR gunTotalNumber
  8061. }
  8062. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8063. {
  8064. for(int i=0; i < gunTotalNumber; i++)
  8065. {
  8066. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8067. {
  8068. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8069. goto end;
  8070. }
  8071. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8072. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8073. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8074. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8075. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8076. {
  8077. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8078. goto end;
  8079. }
  8080. }
  8081. }
  8082. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8083. goto end;
  8084. }
  8085. //----------------------gunIndex is not 0 ------------------------------------------------//
  8086. //check Transaction active
  8087. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8088. {
  8089. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8090. {
  8091. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8092. {
  8093. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8094. goto end;
  8095. }
  8096. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8097. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8098. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8099. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8100. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8101. {
  8102. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8103. goto end;
  8104. }
  8105. else
  8106. {
  8107. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8108. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8109. goto end;
  8110. }
  8111. }
  8112. }//END FOR CHAdeMO_QUANTITY
  8113. for (int index = 0; index < CCS_QUANTITY; index++)
  8114. {
  8115. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8116. {
  8117. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8118. {
  8119. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8120. goto end;
  8121. }
  8122. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8123. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8124. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8125. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8126. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8127. {
  8128. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8129. goto end;
  8130. }
  8131. else
  8132. {
  8133. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8134. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8135. goto end;
  8136. }
  8137. }
  8138. }//END FOR CCS_QUANTITY
  8139. for (int index = 0; index < GB_QUANTITY; index++)
  8140. {
  8141. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8142. {
  8143. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8144. {
  8145. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8146. goto end;
  8147. }
  8148. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8149. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8150. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8151. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8152. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8153. {
  8154. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8155. goto end;
  8156. }
  8157. else
  8158. {
  8159. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8160. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8161. goto end;
  8162. }
  8163. }
  8164. }// END FOR GB_QUANTITY
  8165. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8166. {
  8167. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8168. {
  8169. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8170. {
  8171. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8172. goto end;
  8173. }
  8174. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8175. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8176. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8177. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8178. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8179. {
  8180. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8181. goto end;
  8182. }
  8183. else
  8184. {
  8185. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8186. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8187. goto end;
  8188. }
  8189. }
  8190. }// END FOR GENERAL_GUN_QUANTITY
  8191. for (int index = 0; index < AC_QUANTITY; index++)
  8192. {
  8193. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8194. {
  8195. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8196. {
  8197. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8198. goto end;
  8199. }
  8200. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8201. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8202. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8203. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8204. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8205. {
  8206. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8207. goto end;
  8208. }
  8209. else
  8210. {
  8211. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8212. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8213. goto end;
  8214. }
  8215. }
  8216. }//END FOR AC_QUANTITY
  8217. }//END FOR AvailabilityTypeStr[Inoperative]
  8218. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8219. {
  8220. //----------------------gunIndex is 0 ------------------------------------------------//
  8221. if(gunIndex == 0)
  8222. {
  8223. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8224. {
  8225. for(int i=0; i < gunTotalNumber; i++)
  8226. {
  8227. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8228. {
  8229. 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
  8230. {
  8231. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8232. goto end;
  8233. }
  8234. }//END FOR CHAdeMO_QUANTITY
  8235. for (int index = 0; index < CCS_QUANTITY; index++)
  8236. {
  8237. 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
  8238. {
  8239. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8240. goto end;
  8241. }
  8242. }//END FOR CCS_QUANTITY
  8243. for (int index = 0; index < GB_QUANTITY; index++)
  8244. {
  8245. 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
  8246. {
  8247. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8248. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8249. goto end;
  8250. }
  8251. }// END FOR GB_QUANTITY
  8252. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8253. {
  8254. 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
  8255. {
  8256. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8257. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8258. goto end;
  8259. }
  8260. }// END FOR GENERAL_GUN_QUANTITY
  8261. for (int index = 0; index < AC_QUANTITY; index++)
  8262. {
  8263. 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
  8264. {
  8265. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8266. goto end;
  8267. }
  8268. }//END FOR CHAdeMO_QUANTITY
  8269. }// END FOR gunTotalNumber
  8270. }
  8271. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8272. {
  8273. for(int i=0; i < gunTotalNumber; i++)
  8274. {
  8275. for (int index = 0; index < AC_QUANTITY; index++)
  8276. {
  8277. 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
  8278. {
  8279. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8280. goto end;
  8281. }
  8282. }//END FOR CHAdeMO_QUANTITY
  8283. } // END FOR gunTotalNumber
  8284. }
  8285. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8286. goto end;
  8287. }
  8288. //----------------------gunIndex is not 0 ------------------------------------------------//
  8289. //check Transaction active
  8290. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8291. {
  8292. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8293. {
  8294. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8295. goto end;
  8296. }
  8297. }//END FOR CHAdeMO_QUANTITY
  8298. for (int index = 0; index < CCS_QUANTITY; index++)
  8299. {
  8300. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8301. {
  8302. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8303. goto end;
  8304. }
  8305. }//END FOR CCS_QUANTITY
  8306. for (int index = 0; index < GB_QUANTITY; index++)
  8307. {
  8308. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8309. {
  8310. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8311. goto end;
  8312. }
  8313. }// END FOR GB_QUANTITY
  8314. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8315. {
  8316. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8317. {
  8318. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8319. goto end;
  8320. }
  8321. }// END FOR GENERAL_GUN_QUANTITY
  8322. for (int index = 0; index < AC_QUANTITY; index++)
  8323. {
  8324. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8325. {
  8326. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8327. goto end;
  8328. }
  8329. }//END FOR AC_QUANTITY
  8330. }//END FOR AvailabilityTypeStr[Operative]
  8331. end:
  8332. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8333. {
  8334. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8335. }
  8336. else
  8337. {
  8338. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8339. }
  8340. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8341. {
  8342. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8343. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8344. }
  8345. else if(gunIndex == 0)
  8346. {
  8347. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8348. {
  8349. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8350. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8351. }
  8352. }
  8353. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8354. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8355. return result;
  8356. }
  8357. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8358. {
  8359. mtrace();
  8360. int valueInvalid = NO;
  8361. int result = FAIL;
  8362. char keystr[40]={0};
  8363. char valuestr[501]={0}; //value should be limited in 500 bytes
  8364. char comfirmstr[20]={0};
  8365. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8366. json_object *ChangeConfiguration;
  8367. ChangeConfiguration = json_tokener_parse(payload);
  8368. if(!is_error(ChangeConfiguration))
  8369. {
  8370. // Required data
  8371. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8372. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8373. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8374. {
  8375. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8376. }
  8377. else
  8378. {
  8379. valueInvalid = YES;
  8380. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8381. }
  8382. }
  8383. json_object_put(ChangeConfiguration);
  8384. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  8385. {
  8386. DEBUG_ERROR("Payload is null or value is invalid.\n");
  8387. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8388. }
  8389. else
  8390. {
  8391. int status = setKeyValue(keystr, valuestr);
  8392. switch(status)
  8393. {
  8394. case ConfigurationStatus_Accepted:
  8395. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8396. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8397. StoreConfigurationTable();
  8398. break;
  8399. case RebootRequired:
  8400. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8401. StoreConfigurationTable();
  8402. break;
  8403. case NotSupported:
  8404. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8405. break;
  8406. case ConfigurationStatus_Rejected:
  8407. default:
  8408. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8409. break;
  8410. }
  8411. }
  8412. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8413. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8414. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8415. {
  8416. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8417. SetOcppConnStatus(FALSE);
  8418. }
  8419. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8420. {
  8421. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8422. }
  8423. return result;
  8424. }
  8425. int handleClearCacheRequest(char *uuid, char *payload)
  8426. {
  8427. mtrace();
  8428. int result = FAIL;
  8429. char comfirmstr[20];
  8430. char rmFileCmd[100]={0};
  8431. struct stat stats;
  8432. DEBUG_INFO("handleClearCacheRequest...\n");
  8433. stat("/Storage/OCPP", &stats);
  8434. // Check for directory existence
  8435. if (S_ISDIR(stats.st_mode) == 1)
  8436. {}
  8437. else
  8438. {
  8439. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8440. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  8441. system(rmFileCmd);
  8442. }
  8443. if(OCPP_cleanLocalCache())
  8444. {
  8445. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8446. }
  8447. else
  8448. {
  8449. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8450. }
  8451. sendClearCacheConfirmation(uuid, comfirmstr);
  8452. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8453. return result;
  8454. }
  8455. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8456. {
  8457. mtrace();
  8458. int result = FAIL;
  8459. int resultRename;
  8460. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8461. char chargingProfilePurposeStr[26]={0};
  8462. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8463. char tempchargingProfilePurposeStr[26]={0};
  8464. char str[100]={0};
  8465. char fname[200]={0};
  8466. char comfirmstr[20]={0};
  8467. char word[1600]={0};
  8468. int clearflag = FALSE;
  8469. int chargingProfileIdIsNULL = FALSE;
  8470. int connectorIsNULL = FALSE;
  8471. int chargingProfilePurposeIsNULL = FALSE;
  8472. int stackLevelIsNULL = FALSE;
  8473. //int GotoEnd = FALSE;
  8474. FILE *fptr1, *fptr2;
  8475. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  8476. int n_chargingProfile=0;
  8477. int isEmptyFile = FALSE;
  8478. char sLineWord[1600]={0};
  8479. char chargingProfiles[10][100]={0};
  8480. int ChargeProfileCount = 0;
  8481. int ch;
  8482. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8483. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8484. json_object *ClearChargingProfile;
  8485. ClearChargingProfile = json_tokener_parse(payload);
  8486. if(!is_error(ClearChargingProfile))
  8487. {
  8488. // Optional data
  8489. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8490. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8491. else
  8492. chargingProfileIdIsNULL = TRUE;
  8493. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8494. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8495. else
  8496. connectorIsNULL = TRUE;
  8497. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8498. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8499. else
  8500. chargingProfilePurposeIsNULL = TRUE;
  8501. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8502. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8503. else
  8504. stackLevelIsNULL = TRUE;
  8505. }
  8506. json_object_put(ClearChargingProfile);
  8507. if(connectorIsNULL == FALSE)
  8508. {
  8509. switch(connectorIdInt)
  8510. {
  8511. case 0:
  8512. if(chargingProfilePurposeIsNULL == TRUE)
  8513. {
  8514. int l = 0;
  8515. strcpy(fname, ChargePointMaxProfile_JSON);
  8516. if((access(fname,F_OK))!=-1)
  8517. {
  8518. strcpy(chargingProfiles[l], fname);
  8519. l = l + 1;
  8520. }
  8521. strcpy(fname, TxDefaultProfile_0_JSON);
  8522. if((access(fname,F_OK))!=-1)
  8523. {
  8524. strcpy(chargingProfiles[l], fname);
  8525. l = l + 1;
  8526. }
  8527. ChargeProfileCount = l;
  8528. }
  8529. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8530. {
  8531. strcpy(fname, ChargePointMaxProfile_JSON);
  8532. if((access(fname,F_OK))!=-1)
  8533. {
  8534. strcpy(chargingProfiles[0], fname);
  8535. ChargeProfileCount = 1;
  8536. }
  8537. }
  8538. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8539. {
  8540. strcpy(fname, TxDefaultProfile_0_JSON);
  8541. if((access(fname,F_OK))!=-1)
  8542. {
  8543. strcpy(chargingProfiles[0], fname);
  8544. ChargeProfileCount = 1;
  8545. }
  8546. }
  8547. break;
  8548. default:
  8549. if(chargingProfilePurposeIsNULL == TRUE)
  8550. {
  8551. int m = 0;
  8552. memset(fname, 0, ARRAY_SIZE(fname));
  8553. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8554. if((access(fname,F_OK))!=-1)
  8555. {
  8556. strcpy(chargingProfiles[m], fname);
  8557. m = m + 1;
  8558. }
  8559. memset(fname, 0, ARRAY_SIZE(fname));
  8560. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8561. if((access(fname,F_OK))!=-1)
  8562. {
  8563. strcpy(chargingProfiles[m], fname);
  8564. m = m + 1;
  8565. }
  8566. ChargeProfileCount = m;
  8567. }
  8568. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8569. {
  8570. //strcpy(fname, TxDefaultProfile_1_JSON);
  8571. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8572. if((access(fname,F_OK))!=-1)
  8573. {
  8574. strcpy(chargingProfiles[0], fname);
  8575. ChargeProfileCount = 1;
  8576. }
  8577. }
  8578. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8579. {
  8580. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8581. if((access(fname,F_OK))!=-1)
  8582. {
  8583. strcpy(chargingProfiles[0], fname);
  8584. ChargeProfileCount = 1;
  8585. }
  8586. //strcpy(fname, TxProfile_1_JSON);
  8587. }
  8588. //strcpy(fname, ChargePointMaxProfile_JSON );
  8589. break;
  8590. }
  8591. }
  8592. else // Check all Charging Profiles
  8593. {
  8594. int i = 0;
  8595. char fnametemp[200]={0};
  8596. ChargeProfileCount = 0;
  8597. //Check ChargePointMaxProfile.json exit
  8598. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8599. {
  8600. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  8601. i = i + 1;
  8602. }
  8603. //Check TxDefaultProfile_0.json exit
  8604. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8605. {
  8606. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  8607. i = i + 1;
  8608. }
  8609. //Check TxDefaultProfile_%d.json
  8610. for(int j=1; j <= gunTotalNumber; j++)
  8611. {
  8612. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8613. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8614. if((access(fnametemp,F_OK))!=-1)
  8615. {
  8616. strcpy(chargingProfiles[i], fnametemp);
  8617. i = i + 1;
  8618. }
  8619. }
  8620. //Check TxProfile_%d.json
  8621. for(int j=1; j <= gunTotalNumber; j++)
  8622. {
  8623. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8624. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8625. if((access(fnametemp,F_OK))!=-1)
  8626. {
  8627. strcpy(chargingProfiles[i], fnametemp);
  8628. i = i + 1;
  8629. }
  8630. }
  8631. ChargeProfileCount = i;
  8632. }// End connectorIsNULL is TRUE
  8633. if(ChargeProfileCount == 0)
  8634. {
  8635. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8636. goto end;
  8637. }
  8638. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8639. {
  8640. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8641. goto end;
  8642. }
  8643. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8644. {
  8645. memset(str, 0, ARRAY_SIZE(str));
  8646. // clear temp file
  8647. sprintf(str,"rm -f %s",temp);
  8648. system(str);
  8649. for(int k=0; k < ChargeProfileCount; k++)
  8650. {
  8651. memset(str, 0, ARRAY_SIZE(str));
  8652. //clear file in C
  8653. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8654. system(str);
  8655. }
  8656. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8657. goto end;
  8658. }
  8659. else if(connectorIsNULL == TRUE)
  8660. {
  8661. for(int k=0; k < ChargeProfileCount; k++)
  8662. {
  8663. fptr1 = fopen(chargingProfiles[k], "r");
  8664. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  8665. //Check Charging Profile Count
  8666. while(fscanf(fptr1, "%s", word) != EOF)
  8667. {
  8668. //DEBUG_INFO("word=%s\n",word);
  8669. if(strstr(word, "chargingProfileId")!= NULL)
  8670. {
  8671. //DEBUG_INFO("test chargingProfileId \n");
  8672. n_chargingProfile = n_chargingProfile + 1;
  8673. //DEBUG_INFO("chargingProfileId Found\n");
  8674. }
  8675. }
  8676. rewind(fptr1);
  8677. //search Charging Profile Element
  8678. //int i= 0;
  8679. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8680. {
  8681. json_object *tmpProfilee;
  8682. tmpProfilee = json_tokener_parse(sLineWord);
  8683. if(!is_error(tmpProfilee))
  8684. {
  8685. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8686. {
  8687. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8688. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8689. }
  8690. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8691. {
  8692. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8693. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8694. }
  8695. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8696. {
  8697. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8698. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8699. }
  8700. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8701. {
  8702. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8703. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8704. }
  8705. }
  8706. json_object_put(tmpProfilee);
  8707. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8708. {
  8709. //------- not write to fptr2-------//
  8710. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8711. //clearflag = TRUE;
  8712. }
  8713. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8714. {
  8715. //------- not write to fptr2-------//
  8716. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8717. }
  8718. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8719. {
  8720. //------- not write to fptr2-------//
  8721. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8722. }
  8723. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8724. {
  8725. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8726. }
  8727. else
  8728. {
  8729. fprintf(fptr2, sLineWord);//writing data into file
  8730. }
  8731. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8732. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8733. if(clearflag == TRUE)
  8734. {
  8735. fclose(fptr1);
  8736. fclose(fptr2);
  8737. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8738. system(str);
  8739. // clear temp file
  8740. sprintf(str,"rm -f %s",temp);
  8741. system(str);
  8742. }
  8743. else
  8744. {
  8745. fclose(fptr1);
  8746. fclose(fptr2);
  8747. memset(str, 0, ARRAY_SIZE(str));
  8748. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8749. system(str);
  8750. resultRename = rename(temp, chargingProfiles[k]);
  8751. if(resultRename == 0)
  8752. {
  8753. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8754. }
  8755. else
  8756. {
  8757. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8758. }
  8759. if(comfirmstr[0]== 0)
  8760. {
  8761. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8762. }
  8763. //Check chargingProfile is empty file
  8764. /*------ Read the file ----------------*/
  8765. fptr1=fopen(chargingProfiles[k],"r");
  8766. ch=fgetc(fptr1);
  8767. rewind(fptr1);
  8768. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8769. if(ch!=EOF)
  8770. {
  8771. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8772. {
  8773. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8774. if(sLineWord[0]=='\0')
  8775. {
  8776. isEmptyFile = TRUE;
  8777. break;
  8778. }
  8779. else
  8780. {
  8781. isEmptyFile = FALSE;
  8782. break;
  8783. }
  8784. }
  8785. }
  8786. else
  8787. isEmptyFile = TRUE;
  8788. fclose(fptr1);
  8789. if(isEmptyFile == TRUE)
  8790. {
  8791. memset(str, 0, ARRAY_SIZE(str));
  8792. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8793. system(str);
  8794. }
  8795. }
  8796. }// End of while(int k=0; k < ChargePointCount; k++)
  8797. }
  8798. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8799. {
  8800. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8801. for(int k=0; k < ChargeProfileCount; k++)
  8802. {
  8803. fptr1 = fopen(chargingProfiles[k], "r");
  8804. fptr2 = fopen(temp, "w+");
  8805. //Check Charging Profile Count
  8806. while(fscanf(fptr1, "%s", word) != EOF)
  8807. {
  8808. //DEBUG_INFO("word=%s\n",word);
  8809. if(strstr(word, "chargingProfileId")!= NULL)
  8810. {
  8811. n_chargingProfile = n_chargingProfile + 1;
  8812. }
  8813. }
  8814. rewind(fptr1);
  8815. //search Charging Profile Element
  8816. //int i= 0;
  8817. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8818. {
  8819. json_object *tmpProfilee;
  8820. tmpProfilee = json_tokener_parse(sLineWord);
  8821. if(!is_error(tmpProfilee))
  8822. {
  8823. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8824. {
  8825. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8826. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8827. }
  8828. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8829. {
  8830. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8831. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8832. }
  8833. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8834. {
  8835. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8836. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8837. }
  8838. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8839. {
  8840. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8841. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8842. }
  8843. }
  8844. json_object_put(tmpProfilee);
  8845. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8846. {
  8847. //------- not write to fptr2-------//
  8848. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8849. //clearflag = TRUE;
  8850. }
  8851. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8852. {
  8853. //------- not write to fptr2-------//
  8854. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8855. }
  8856. else if(stackLevelIsNULL == TRUE)
  8857. {
  8858. //Clear Whole File
  8859. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8860. clearflag = TRUE;
  8861. break;
  8862. }
  8863. else
  8864. {
  8865. fprintf(fptr2, sLineWord);//writing data into file
  8866. }
  8867. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8868. }
  8869. if(clearflag == TRUE)
  8870. {
  8871. fclose(fptr1);
  8872. fclose(fptr2);
  8873. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8874. system(str);
  8875. // clear temp file
  8876. sprintf(str,"rm -f %s",temp);
  8877. system(str);
  8878. }
  8879. else
  8880. {
  8881. fclose(fptr1);
  8882. fclose(fptr2);
  8883. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8884. system(str);
  8885. resultRename = rename(temp, chargingProfiles[k]);
  8886. if(resultRename == 0)
  8887. {
  8888. DEBUG_INFO("File ChargingProfile renamed successfully");
  8889. }
  8890. else
  8891. {
  8892. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8893. }
  8894. if(comfirmstr[0]== 0)
  8895. {
  8896. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8897. }
  8898. //Check chargingProfile is empty file
  8899. /*------ Read the file ----------------*/
  8900. fptr1=fopen(chargingProfiles[k],"r");
  8901. ch=fgetc(fptr1);
  8902. rewind(fptr1);
  8903. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8904. if(ch!=EOF)
  8905. {
  8906. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8907. {
  8908. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8909. if(sLineWord[0]=='\0')
  8910. {
  8911. isEmptyFile = TRUE;
  8912. break;
  8913. }
  8914. else
  8915. {
  8916. isEmptyFile = FALSE;
  8917. break;
  8918. }
  8919. }
  8920. }
  8921. else
  8922. isEmptyFile = TRUE;
  8923. fclose(fptr1);
  8924. if(isEmptyFile == TRUE)
  8925. {
  8926. memset(str, 0, ARRAY_SIZE(str));
  8927. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8928. system(str);
  8929. }
  8930. /*------- End of reading ---------------*/
  8931. }
  8932. } // while(int k=0; k < ChargeProfileCount; k++)
  8933. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8934. end:
  8935. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8936. {
  8937. if(connectorIdInt == 0)
  8938. {
  8939. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8940. {
  8941. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  8942. }
  8943. }
  8944. else
  8945. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  8946. }
  8947. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8948. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8949. return result;
  8950. }
  8951. void createFirmwareVersionByDataTransfer(void)
  8952. {
  8953. json_object *FirmwareDataTransfer = json_object_new_object();
  8954. // AC & DC model
  8955. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8956. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8957. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8958. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8959. // DC model
  8960. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8961. {
  8962. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8963. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8964. (gunType[3] != GUN_TYPE_UNKNOWN))
  8965. {
  8966. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8967. }
  8968. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8969. {
  8970. // DS DM DW
  8971. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8972. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8973. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8974. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8975. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8976. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8977. }
  8978. else
  8979. {
  8980. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8981. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8982. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8983. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8984. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8985. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8986. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8987. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8988. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8989. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8990. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8991. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8992. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8993. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8994. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8995. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8996. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8997. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8998. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8999. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9000. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9001. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9002. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9003. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9004. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9005. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9006. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9007. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9008. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9009. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9010. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9011. }
  9012. }
  9013. // 4G model
  9014. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9015. {
  9016. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9017. }
  9018. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9019. json_object_put(FirmwareDataTransfer);
  9020. }
  9021. int handleDataTransferRequest(char *uuid, char *payload)
  9022. {
  9023. mtrace();
  9024. json_object *response = json_object_new_object();
  9025. int result = FAIL;
  9026. char tempvendorId[255]={0};
  9027. char tempmessageId[50]={0};
  9028. char tempdata[512]={0};
  9029. char message[2048]={0};
  9030. DEBUG_INFO("handleDataTransferRequest...\n");
  9031. if((uuid != NULL) && (payload != NULL))
  9032. {
  9033. json_object *DataTransfer;
  9034. DataTransfer = json_tokener_parse(payload);
  9035. if(!is_error(DataTransfer))
  9036. {
  9037. // Required data
  9038. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9039. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9040. // Optional data
  9041. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9042. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9043. if(json_object_object_get(DataTransfer, "data") != NULL)
  9044. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9045. result = PASS;
  9046. }
  9047. json_object_put(DataTransfer);
  9048. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9049. {
  9050. // Send all moudle firmware version on EVSE
  9051. createFirmwareVersionByDataTransfer();
  9052. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9053. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9054. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9055. json_object_put(response);
  9056. }
  9057. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9058. {
  9059. system("/usr/bin/run_tmate_restart.sh &");
  9060. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9061. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9062. json_object_put(response);
  9063. }
  9064. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9065. {
  9066. json_object *data;
  9067. data = json_tokener_parse(tempdata);
  9068. if(!is_error(data))
  9069. {
  9070. 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))
  9071. {
  9072. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9073. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9074. if(json_object_object_get(data, "SOC") != NULL)
  9075. {
  9076. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9077. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9078. }
  9079. if(json_object_object_get(data, "Energy") != NULL)
  9080. {
  9081. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9082. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9083. }
  9084. if(json_object_object_get(data, "Duration") != NULL)
  9085. {
  9086. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9087. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9088. }
  9089. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9090. }
  9091. else
  9092. {
  9093. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9094. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9095. }
  9096. }
  9097. else
  9098. {
  9099. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9100. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9101. }
  9102. json_object_put(data);
  9103. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9104. json_object_put(response);
  9105. }
  9106. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9107. {
  9108. json_object *data;
  9109. data = json_tokener_parse(tempdata);
  9110. if(!is_error(data))
  9111. {
  9112. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9113. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9114. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9115. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9116. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9117. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9118. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9119. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9120. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9121. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9122. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9123. }
  9124. else
  9125. {
  9126. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9127. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9128. }
  9129. json_object_put(data);
  9130. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9131. json_object_put(response);
  9132. }
  9133. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9134. {
  9135. json_object *data;
  9136. data = json_tokener_parse(tempdata);
  9137. if(!is_error(data))
  9138. {
  9139. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9140. if(json_object_object_get(data, "idToken") != NULL)
  9141. {
  9142. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9143. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9144. }
  9145. if(json_object_object_get(data, "price") != NULL)
  9146. {
  9147. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9148. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9149. }
  9150. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9151. }
  9152. else
  9153. {
  9154. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9155. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9156. }
  9157. json_object_put(data);
  9158. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9159. json_object_put(response);
  9160. }
  9161. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9162. {
  9163. json_object *data;
  9164. data = json_tokener_parse(tempdata);
  9165. if(!is_error(data))
  9166. {
  9167. if(json_object_object_get(data, "txId") != NULL)
  9168. {
  9169. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9170. for(int idx = 0;idx<gunTotalNumber;idx++)
  9171. {
  9172. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9173. {
  9174. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9175. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9176. if(json_object_object_get(data, "description") != NULL)
  9177. {
  9178. // California pricing V1.0
  9179. DEBUG_INFO("California pricing V1.0\n");
  9180. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9181. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9182. }
  9183. else
  9184. {
  9185. // California pricing V1.1
  9186. DEBUG_INFO("California pricing V1.1\n");
  9187. if(json_object_object_get(data, "timestamp") != NULL)
  9188. {
  9189. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9190. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9191. }
  9192. if(json_object_object_get(data, "meterValue") != NULL)
  9193. {
  9194. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9195. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9196. }
  9197. if(json_object_object_get(data, "cost") != NULL)
  9198. {
  9199. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9200. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9201. }
  9202. if(json_object_object_get(data, "state") != NULL)
  9203. {
  9204. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9205. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9206. }
  9207. if(json_object_object_get(data, "chargingPrice") != NULL)
  9208. {
  9209. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9210. {
  9211. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9212. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9213. }
  9214. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9215. {
  9216. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9217. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9218. }
  9219. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9220. {
  9221. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9222. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9223. }
  9224. }
  9225. if(json_object_object_get(data, "idlePrice") != NULL)
  9226. {
  9227. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9228. {
  9229. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9230. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9231. }
  9232. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9233. {
  9234. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9235. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9236. }
  9237. }
  9238. if(json_object_object_get(data, "nextPeriod") != NULL)
  9239. {
  9240. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9241. {
  9242. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9243. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9244. }
  9245. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9246. {
  9247. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9248. {
  9249. 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")));
  9250. 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"));
  9251. }
  9252. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9253. {
  9254. 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")));
  9255. 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"));
  9256. }
  9257. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9258. {
  9259. 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")));
  9260. 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"));
  9261. }
  9262. }
  9263. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9264. {
  9265. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9266. {
  9267. 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")));
  9268. 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"));
  9269. }
  9270. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9271. {
  9272. 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")));
  9273. 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"));
  9274. }
  9275. }
  9276. }
  9277. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9278. {
  9279. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9280. {
  9281. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9282. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9283. }
  9284. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9285. {
  9286. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9287. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9288. }
  9289. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9290. {
  9291. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9292. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9293. }
  9294. }
  9295. }
  9296. }
  9297. }
  9298. }
  9299. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9300. }
  9301. else
  9302. {
  9303. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9304. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9305. }
  9306. json_object_put(data);
  9307. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9308. json_object_put(response);
  9309. }
  9310. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9311. {
  9312. json_object *data;
  9313. data = json_tokener_parse(tempdata);
  9314. if(!is_error(data))
  9315. {
  9316. if(json_object_object_get(data, "txId") != NULL)
  9317. {
  9318. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9319. for(int idx = 0;idx<gunTotalNumber;idx++)
  9320. {
  9321. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9322. {
  9323. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9324. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9325. if(json_object_object_get(data, "description") != NULL)
  9326. {
  9327. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9328. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9329. }
  9330. }
  9331. }
  9332. }
  9333. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9334. }
  9335. else
  9336. {
  9337. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9338. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9339. }
  9340. json_object_put(data);
  9341. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9342. json_object_put(response);
  9343. }
  9344. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9345. {
  9346. json_object *data;
  9347. data = json_tokener_parse(tempdata);
  9348. if(!is_error(data))
  9349. {
  9350. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9351. if(json_object_object_get(data, "Content_Type") != NULL)
  9352. {
  9353. 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))
  9354. {
  9355. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9356. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9357. {
  9358. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9359. }
  9360. }
  9361. else
  9362. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9363. }
  9364. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9365. }
  9366. else
  9367. {
  9368. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9369. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9370. }
  9371. json_object_put(data);
  9372. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9373. json_object_put(response);
  9374. }
  9375. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  9376. {
  9377. json_object *data;
  9378. data = json_tokener_parse(tempdata);
  9379. if(!is_error(data))
  9380. {
  9381. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9382. if(json_object_object_get(data, "Page_Index") != NULL)
  9383. {
  9384. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9385. }
  9386. if(json_object_object_get(data, "Duration") != NULL)
  9387. {
  9388. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9389. }
  9390. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  9391. }
  9392. else
  9393. {
  9394. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9395. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9396. }
  9397. json_object_put(data);
  9398. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9399. json_object_put(response);
  9400. }
  9401. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9402. {
  9403. json_object *data;
  9404. data = json_tokener_parse(tempdata);
  9405. if(!is_error(data))
  9406. {
  9407. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9408. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9409. {
  9410. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9411. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9412. else
  9413. {
  9414. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9415. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9416. }
  9417. }
  9418. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9419. {
  9420. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9421. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9422. else
  9423. {
  9424. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9425. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9426. }
  9427. }
  9428. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9429. {
  9430. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9431. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9432. else
  9433. {
  9434. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9435. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9436. }
  9437. }
  9438. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9439. {
  9440. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9441. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9442. else
  9443. {
  9444. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9445. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9446. }
  9447. }
  9448. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9449. {
  9450. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9451. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9452. else
  9453. {
  9454. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9455. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9456. }
  9457. }
  9458. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9459. {
  9460. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9461. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9462. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9463. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9464. else
  9465. {
  9466. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9467. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9468. }
  9469. }
  9470. if(json_object_object_get(data, "isAuthentication") != NULL)
  9471. {
  9472. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9473. {
  9474. case 0:
  9475. case 1:
  9476. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9477. break;
  9478. default:
  9479. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9480. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9481. break;
  9482. }
  9483. }
  9484. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9485. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9486. }
  9487. else
  9488. {
  9489. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9490. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9491. }
  9492. json_object_put(data);
  9493. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9494. json_object_put(response);
  9495. }
  9496. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  9497. {
  9498. json_object *data;
  9499. data = json_tokener_parse(tempdata);
  9500. if(!is_error(data))
  9501. {
  9502. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9503. {
  9504. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  9505. {
  9506. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9507. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9508. }
  9509. else
  9510. {
  9511. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9512. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  9513. }
  9514. }
  9515. else
  9516. {
  9517. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9518. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9519. }
  9520. }
  9521. else
  9522. {
  9523. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9524. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9525. }
  9526. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9527. json_object_put(response);
  9528. }
  9529. else if(strstr(tempmessageId, "refund_status") != NULL)
  9530. {
  9531. json_object *data;
  9532. data = json_tokener_parse(tempdata);
  9533. if(!is_error(data))
  9534. {
  9535. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9536. if(json_object_object_get(data, "status") != NULL)
  9537. {
  9538. //DEBUG_INFO("status: %s\n", json_object_get_string(json_object_object_get(data, "status")));
  9539. if(strcmp(json_object_get_string(json_object_object_get(data, "status")), "T") || strcmp(json_object_get_string(json_object_object_get(data, "status")), "F"))
  9540. {
  9541. sprintf((char *)ShmOCPP16Data->YesCustomData.RefundStatus.status, "%s", json_object_get_string(json_object_object_get(data, "status")));
  9542. }
  9543. else
  9544. {
  9545. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9546. json_object_object_add(response, "data", json_object_new_string("status value is invalid."));
  9547. }
  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("status data can not get."));
  9553. }
  9554. if(json_object_object_get(data, "chargeDate") != NULL)
  9555. {
  9556. sprintf((char *)ShmOCPP16Data->YesCustomData.RefundStatus.chargeDate, "%s", json_object_get_string(json_object_object_get(data,"chargeDate")));
  9557. }
  9558. else
  9559. {
  9560. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9561. json_object_object_add(response, "data", json_object_new_string("chargeDate data can not get."));
  9562. }
  9563. if(json_object_object_get(data, "holdAmt") != NULL)
  9564. {
  9565. if(json_object_get_int(json_object_object_get(data, "holdAmt")) >= 0)
  9566. ShmOCPP16Data->YesCustomData.RefundStatus.holdAmt = json_object_get_int(json_object_object_get(data, "holdAmt"));
  9567. else
  9568. {
  9569. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9570. json_object_object_add(response, "data", json_object_new_string("holdAmt data is invalid."));
  9571. }
  9572. }
  9573. else
  9574. {
  9575. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9576. json_object_object_add(response, "data", json_object_new_string("holdAmt data can not get."));
  9577. }
  9578. if(json_object_object_get(data, "chargeAmt") != NULL)
  9579. {
  9580. if(json_object_get_int(json_object_object_get(data, "chargeAmt")) >= 0)
  9581. ShmOCPP16Data->YesCustomData.RefundStatus.chargeAmt = json_object_get_int(json_object_object_get(data, "chargeAmt"));
  9582. else
  9583. {
  9584. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9585. json_object_object_add(response, "data", json_object_new_string("chargeAmt data is invalid."));
  9586. }
  9587. }
  9588. else
  9589. {
  9590. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9591. json_object_object_add(response, "data", json_object_new_string("chargeAmt data can not get."));
  9592. }
  9593. if(json_object_object_get(data, "refundAmt") != NULL)
  9594. {
  9595. if(json_object_get_int(json_object_object_get(data, "refundAmt")) >= 0)
  9596. ShmOCPP16Data->YesCustomData.RefundStatus.refundAmt = json_object_get_int(json_object_object_get(data, "refundAmt"));
  9597. else
  9598. {
  9599. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9600. json_object_object_add(response, "data", json_object_new_string("refundAmt data is invalid."));
  9601. }
  9602. }
  9603. else
  9604. {
  9605. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9606. json_object_object_add(response, "data", json_object_new_string("refundAmt data can not get."));
  9607. }
  9608. if(json_object_object_get(data, "page") != NULL)
  9609. {
  9610. if(json_object_get_int(json_object_object_get(data, "page")) >= 0 && json_object_get_int(json_object_object_get(data, "page")) <= 3)
  9611. ShmOCPP16Data->YesCustomData.RefundStatus.page = json_object_get_int(json_object_object_get(data, "page"));
  9612. else
  9613. {
  9614. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9615. json_object_object_add(response, "data", json_object_new_string("page data is invalid."));
  9616. }
  9617. }
  9618. else
  9619. {
  9620. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9621. json_object_object_add(response, "data", json_object_new_string("page data can not get."));
  9622. }
  9623. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9624. {
  9625. ShmOCPP16Data->YesCustomData.RefundStatusReq = 1;
  9626. DEBUG_INFO("<<< RefundStatus:{status:%s, chargeDate:%s, holdAmt:%d, chargeAmt:%d, refundAmt:%d, page:%d}\n",
  9627. ShmOCPP16Data->YesCustomData.RefundStatus.status,
  9628. ShmOCPP16Data->YesCustomData.RefundStatus.chargeDate,
  9629. ShmOCPP16Data->YesCustomData.RefundStatus.holdAmt,
  9630. ShmOCPP16Data->YesCustomData.RefundStatus.chargeAmt,
  9631. ShmOCPP16Data->YesCustomData.RefundStatus.refundAmt,
  9632. ShmOCPP16Data->YesCustomData.RefundStatus.page);
  9633. }
  9634. }
  9635. else
  9636. {
  9637. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9638. json_object_object_add(response, "data", json_object_new_string("refund_status content got something wrong."));
  9639. }
  9640. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9641. json_object_put(response);
  9642. }
  9643. else if(strstr(tempmessageId, "deduct_status") != NULL)
  9644. {
  9645. json_object *data;
  9646. data = json_tokener_parse(tempdata);
  9647. if(!is_error(data))
  9648. {
  9649. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9650. if(json_object_object_get(data, "status") != NULL)
  9651. {
  9652. //DEBUG_INFO("status: %s\n", json_object_get_string(json_object_object_get(data, "status")));
  9653. if((strcmp(json_object_get_string(json_object_object_get(data, "status")), "T")==0) || (strcmp(json_object_get_string(json_object_object_get(data, "status")), "F")==0))
  9654. {
  9655. sprintf((char*)ShmOCPP16Data->YesCustomData.DeductStatus.status, "%s", json_object_get_string(json_object_object_get(data, "status")));
  9656. }
  9657. else
  9658. {
  9659. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9660. json_object_object_add(response, "data", json_object_new_string("status value is invalid."));
  9661. }
  9662. }
  9663. else
  9664. {
  9665. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9666. json_object_object_add(response, "data", json_object_new_string("status data can not get."));
  9667. }
  9668. if(json_object_object_get(data, "autoLoadAmt") != NULL)
  9669. {
  9670. if(json_object_get_int(json_object_object_get(data, "autoLoadAmt")) >= 0)
  9671. ShmOCPP16Data->YesCustomData.DeductStatus.autoLoadAmt = json_object_get_int(json_object_object_get(data, "autoLoadAmt"));
  9672. else
  9673. {
  9674. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9675. json_object_object_add(response, "data", json_object_new_string("autoLoadAmt is invalid."));
  9676. }
  9677. }
  9678. else
  9679. {
  9680. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9681. json_object_object_add(response, "data", json_object_new_string("autoLoadAmt data can not get."));
  9682. }
  9683. if(json_object_object_get(data, "beforeAmt") != NULL)
  9684. {
  9685. if(json_object_get_int(json_object_object_get(data, "beforeAmt")) >= 0)
  9686. ShmOCPP16Data->YesCustomData.DeductStatus.beforeAmt = json_object_get_int(json_object_object_get(data, "beforeAmt"));
  9687. else
  9688. {
  9689. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9690. json_object_object_add(response, "data", json_object_new_string("beforeAmt data is invalid."));
  9691. }
  9692. }
  9693. else
  9694. {
  9695. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9696. json_object_object_add(response, "data", json_object_new_string("beforeAmt data can not get."));
  9697. }
  9698. if(json_object_object_get(data, "chargeAmt") != NULL)
  9699. {
  9700. if(json_object_get_int(json_object_object_get(data, "chargeAmt")) >= 0)
  9701. ShmOCPP16Data->YesCustomData.DeductStatus.chargeAmt = json_object_get_int(json_object_object_get(data, "chargeAmt"));
  9702. else
  9703. {
  9704. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9705. json_object_object_add(response, "data", json_object_new_string("chargeAmt data is invalid."));
  9706. }
  9707. }
  9708. else
  9709. {
  9710. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9711. json_object_object_add(response, "data", json_object_new_string("chargeAmt data can not get."));
  9712. }
  9713. if(json_object_object_get(data, "afterAmt") != NULL)
  9714. {
  9715. if(json_object_get_int(json_object_object_get(data, "afterAmt")) >= 0)
  9716. ShmOCPP16Data->YesCustomData.DeductStatus.afterAmt = json_object_get_int(json_object_object_get(data, "afterAmt"));
  9717. else
  9718. {
  9719. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9720. json_object_object_add(response, "data", json_object_new_string("afterAmt data is invalid."));
  9721. }
  9722. }
  9723. else
  9724. {
  9725. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9726. json_object_object_add(response, "data", json_object_new_string("afterAmt data can not get."));
  9727. }
  9728. if(json_object_object_get(data, "page") != NULL)
  9729. {
  9730. if(json_object_get_int(json_object_object_get(data, "page")) >= 0)
  9731. ShmOCPP16Data->YesCustomData.DeductStatus.page = json_object_get_int(json_object_object_get(data, "page"));
  9732. else
  9733. {
  9734. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9735. json_object_object_add(response, "data", json_object_new_string("page data is invalid."));
  9736. }
  9737. }
  9738. else
  9739. {
  9740. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9741. json_object_object_add(response, "data", json_object_new_string("page data can not get."));
  9742. }
  9743. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9744. {
  9745. ShmOCPP16Data->YesCustomData.DeductStatusReq = 1;
  9746. DEBUG_INFO("<<< deduct_status:{status:%s, autoLoadAmt:%d, beforeAmt:%d, chargeAmt:%d, afterAmt:%d, page:%d}\n",
  9747. ShmOCPP16Data->YesCustomData.DeductStatus.status,
  9748. ShmOCPP16Data->YesCustomData.DeductStatus.autoLoadAmt,
  9749. ShmOCPP16Data->YesCustomData.DeductStatus.beforeAmt,
  9750. ShmOCPP16Data->YesCustomData.DeductStatus.chargeAmt,
  9751. ShmOCPP16Data->YesCustomData.DeductStatus.afterAmt,
  9752. ShmOCPP16Data->YesCustomData.DeductStatus.page);
  9753. }
  9754. }
  9755. else
  9756. {
  9757. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9758. json_object_object_add(response, "data", json_object_new_string("deduct_status content got something wrong."));
  9759. }
  9760. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9761. json_object_put(response);
  9762. }
  9763. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9764. {
  9765. json_object *data;
  9766. data = json_tokener_parse(tempdata);
  9767. if(!is_error(data))
  9768. {
  9769. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9770. if(json_object_object_get(data, "stationName") != NULL)
  9771. {
  9772. sprintf((char *)ShmOCPP16Data->YesCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9773. }
  9774. else
  9775. {
  9776. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9777. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9778. }
  9779. /*if(json_object_object_get(data, "station_id") != NULL)
  9780. {
  9781. sprintf((char *)ShmOCPP16Data->YesCustomData.ChargerInfo.station_id, "%s", json_object_get_string(json_object_object_get(data,"station_id")));
  9782. }
  9783. else
  9784. {
  9785. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9786. json_object_object_add(response, "data", json_object_new_string("station_id data can not get."));
  9787. }
  9788. if(json_object_object_get(data, "charge_id") != NULL)
  9789. {
  9790. for(int idx=0;idx<json_object_array_length(json_object_object_get(data, "charge_id"));idx++)
  9791. {
  9792. sprintf((char*)ShmOCPP16Data->YesCustomData.ChargerInfo.charge_id[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(data, "charge_id"), idx)));
  9793. }
  9794. }
  9795. else
  9796. {
  9797. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9798. json_object_object_add(response, "data", json_object_new_string("charge_id data can not get."));
  9799. }*/
  9800. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9801. {
  9802. ShmOCPP16Data->YesCustomData.ChargerInfoReq = 1;
  9803. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9804. ShmOCPP16Data->YesCustomData.ChargerInfo.station_name);
  9805. }
  9806. }
  9807. else
  9808. {
  9809. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9810. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9811. }
  9812. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9813. json_object_put(response);
  9814. }
  9815. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9816. {
  9817. json_object *data;
  9818. data = json_tokener_parse(tempdata);
  9819. if(!is_error(data))
  9820. {
  9821. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9822. if(json_object_object_get(data, "weatherId") != NULL)
  9823. {
  9824. ShmOCPP16Data->YesCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9825. }
  9826. else
  9827. {
  9828. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9829. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9830. }
  9831. if(json_object_object_get(data, "Temperature") != NULL)
  9832. {
  9833. ShmOCPP16Data->YesCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9834. }
  9835. else
  9836. {
  9837. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9838. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9839. }
  9840. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9841. {
  9842. ShmOCPP16Data->YesCustomData.WeatherInfoReq = 1;
  9843. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9844. ShmOCPP16Data->YesCustomData.WeatherInfo.weatherId,
  9845. ShmOCPP16Data->YesCustomData.WeatherInfo.temperature
  9846. );
  9847. }
  9848. }
  9849. else
  9850. {
  9851. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9852. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9853. }
  9854. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9855. json_object_put(response);
  9856. }
  9857. else if(strstr(tempmessageId, "set_qrcode") != NULL)
  9858. {
  9859. json_object *data;
  9860. data = json_tokener_parse(tempdata);
  9861. if(!is_error(data))
  9862. {
  9863. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9864. if(json_object_object_get(data, "connectorId") != NULL)
  9865. {
  9866. if((json_object_get_int(json_object_object_get(data, "connectorId")) > 0) && (json_object_get_int(json_object_object_get(data, "connectorId")) <= gunTotalNumber))
  9867. {
  9868. int idx = json_object_get_int(json_object_object_get(data, "connectorId"))-1;
  9869. if(json_object_object_get(data, "qrcode") != NULL)
  9870. {
  9871. sprintf((char *)ShmOCPP16Data->YesCustomData.QrCode[idx], "%s", json_object_get_string(json_object_object_get(data,"qrcode")));
  9872. ShmOCPP16Data->YesCustomData.SetQrCodeReq = 1;
  9873. DEBUG_INFO("<<< set_qrcode:{connectorId:%d, qrcode:%s}\n",
  9874. idx,
  9875. ShmOCPP16Data->YesCustomData.QrCode[idx]
  9876. );
  9877. }
  9878. else
  9879. {
  9880. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9881. json_object_object_add(response, "data", json_object_new_string("qrcode data can not get."));
  9882. }
  9883. }
  9884. else
  9885. {
  9886. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9887. json_object_object_add(response, "data", json_object_new_string("connectorId data is invalid."));
  9888. }
  9889. }
  9890. else
  9891. {
  9892. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9893. json_object_object_add(response, "data", json_object_new_string("connectorId data can not get."));
  9894. }
  9895. }
  9896. else
  9897. {
  9898. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9899. json_object_object_add(response, "data", json_object_new_string("set_qrcode content got something wrong."));
  9900. }
  9901. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9902. json_object_put(response);
  9903. }
  9904. else
  9905. {
  9906. // Can not find valid message id
  9907. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9908. }
  9909. }
  9910. else
  9911. {
  9912. // Payload is null
  9913. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9914. }
  9915. LWS_Send(message);
  9916. return result;
  9917. }
  9918. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9919. {
  9920. mtrace();
  9921. int result = FAIL;
  9922. int connectorIdInt, durationInt;
  9923. char chargingRateUnitStr[4]={0};
  9924. char comfirmstr[20];
  9925. int confirmPeriods = 0;
  9926. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9927. json_object *GetCompositeSchedule;
  9928. GetCompositeSchedule = json_tokener_parse(payload);
  9929. if(!is_error(GetCompositeSchedule))
  9930. {
  9931. // Required data
  9932. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9933. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9934. else
  9935. connectorIdInt = -1;
  9936. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9937. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9938. else
  9939. durationInt = 86400;
  9940. // Optional data
  9941. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9942. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9943. }
  9944. json_object_put(GetCompositeSchedule);
  9945. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9946. if((connectorIdInt == 0) ||
  9947. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9948. {
  9949. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9950. struct StructChargingProfile tmpProfile[1];
  9951. if(strstr(chargingRateUnitStr, "W") != NULL)
  9952. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9953. else
  9954. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9955. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9956. {
  9957. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9958. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9959. }
  9960. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9961. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9962. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9963. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9964. {
  9965. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9966. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9967. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9968. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9969. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9970. {
  9971. confirmPeriods = idx;
  9972. break;
  9973. }
  9974. }
  9975. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9976. {
  9977. confirmPeriods += 1;
  9978. }
  9979. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9980. }
  9981. else
  9982. {
  9983. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9984. }
  9985. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9986. return result;
  9987. }
  9988. int handleGetConfigurationRequest(char *uuid, char *payload)
  9989. {
  9990. mtrace();
  9991. int result = FAIL;
  9992. int MaxKeySupported = 0;
  9993. int n_keys = 0;
  9994. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9995. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9996. json_object *GetConfiguration;
  9997. GetConfiguration = json_tokener_parse(payload);
  9998. if(!is_error(GetConfiguration))
  9999. {
  10000. // Optional data
  10001. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10002. {
  10003. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10004. {
  10005. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10006. n_keys = idx + 1;
  10007. }
  10008. }
  10009. }
  10010. json_object_put(GetConfiguration);
  10011. UnknownKeynum = 0;
  10012. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10013. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10014. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10015. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10016. if(n_keys != 0)
  10017. {
  10018. for(int i=0;i<n_keys;i++)
  10019. {
  10020. getKeyValue(requestKey[i]);
  10021. }
  10022. }
  10023. else
  10024. {
  10025. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10026. getKeyValue("");
  10027. }
  10028. processUnkownKey();
  10029. sendGetConfigurationConfirmation(uuid);
  10030. return result;
  10031. }
  10032. static char fnamePlusPath[100]={0};
  10033. static char fnamePWithNoPath[60]={0};
  10034. void checkUploadLog(void)
  10035. {
  10036. FILE *fp;
  10037. /* Open the command for reading. */
  10038. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10039. if (fp == NULL) {
  10040. DEBUG_WARN("Failed to run command\n" );
  10041. exit(1);
  10042. }
  10043. int ftppathlen = 0;
  10044. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10045. int i = 0;
  10046. /* Read the output a line at a time - output it. */
  10047. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10048. if(i==0)
  10049. {
  10050. ftppathlen = strlen(fnamePlusPath);
  10051. DEBUG_INFO("%s\n", fnamePlusPath);
  10052. fnamePlusPath[ftppathlen]='\0';
  10053. break;
  10054. }
  10055. i= i+1;
  10056. }
  10057. /* close */
  10058. pclose(fp);
  10059. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10060. {
  10061. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10062. {
  10063. fnamePlusPath[k]='\0';
  10064. }
  10065. }
  10066. i=1;
  10067. //char fname[60]={0};
  10068. while(i < ftppathlen)
  10069. {
  10070. int len=ftppathlen-i;
  10071. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10072. {
  10073. DEBUG_INFO("compare '/' all right\n");
  10074. break;
  10075. }
  10076. i=i+1;
  10077. }
  10078. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10079. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10080. fnamePWithNoPath[i+1] = '\0';
  10081. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10082. {
  10083. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10084. {
  10085. fnamePWithNoPath[j]='\0';
  10086. }
  10087. }
  10088. FILE* fp1 = fopen(fnamePlusPath, "r");
  10089. if (fp1)
  10090. {
  10091. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10092. // file exists
  10093. fclose(fp1);
  10094. }
  10095. else
  10096. {
  10097. // file doesn't exist
  10098. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10099. }
  10100. }
  10101. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  10102. {
  10103. mtrace();
  10104. int result = FAIL;
  10105. time_t CurrentTime;
  10106. struct tm *tm;
  10107. pthread_t th_Status;
  10108. CurrentTime = time(NULL);
  10109. tm = localtime(&CurrentTime);
  10110. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  10111. 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);
  10112. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10113. if(!interLock.isGetDiagnosticGoing)
  10114. {
  10115. interLock.isGetDiagnosticGoing = 1;
  10116. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  10117. sleep(1);
  10118. }
  10119. else
  10120. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10121. return result;
  10122. }
  10123. void* GetDiagnosticsProcess(void* data)
  10124. {
  10125. pthread_detach(pthread_self());
  10126. mtrace();
  10127. int retriesInt=0, retryIntervalInt=0;
  10128. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10129. 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};
  10130. int port=0;
  10131. int isSuccess = FALSE;
  10132. char cmdBuf[2048];
  10133. struct tm *tmNow;
  10134. time_t CurrentTime;
  10135. struct tm tmStart;
  10136. struct tm tmStop;
  10137. CurrentTime = time(NULL);
  10138. tmNow=localtime(&CurrentTime);
  10139. uint16_t targetYear, targetMonth;
  10140. json_object *GetDiagnostics;
  10141. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10142. GetDiagnostics = json_tokener_parse(data);
  10143. if(!is_error(GetDiagnostics))
  10144. {
  10145. // Required data
  10146. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10147. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10148. // Optional data
  10149. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10150. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10151. else
  10152. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10153. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10154. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10155. else
  10156. retryIntervalInt = 30;
  10157. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10158. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10159. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10160. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10161. }
  10162. json_object_put(GetDiagnostics);
  10163. // Pack log to compress file
  10164. 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) &&
  10165. (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))
  10166. {
  10167. // Pack system log
  10168. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10169. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10170. targetYear = tmStart.tm_year;
  10171. targetMonth = tmStart.tm_mon;
  10172. do
  10173. {
  10174. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10175. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10176. if(targetMonth+1>=13)
  10177. {
  10178. targetYear += 1;
  10179. targetMonth = 1;
  10180. }
  10181. else
  10182. {
  10183. targetMonth += 1;
  10184. }
  10185. }while((targetYear < (tmNow->tm_year+1900)) ||
  10186. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10187. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10188. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10189. system(cmdBuf);
  10190. // Pack charging & event log
  10191. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10192. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10193. targetYear = tmStart.tm_year;
  10194. targetMonth = tmStart.tm_mon;
  10195. do
  10196. {
  10197. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10198. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10199. if(targetMonth+1>=13)
  10200. {
  10201. targetYear += 1;
  10202. targetMonth = 1;
  10203. }
  10204. else
  10205. {
  10206. targetMonth += 1;
  10207. }
  10208. }while((targetYear < (tmNow->tm_year+1900)) ||
  10209. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10210. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10211. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10212. system(cmdBuf);
  10213. // Combine log file
  10214. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10215. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10216. }
  10217. else
  10218. {
  10219. system("exec /root/logPackTools 'log' 6");
  10220. }
  10221. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10222. system(cmdBuf);
  10223. checkUploadLog();
  10224. //****************location*******************/
  10225. if(strcmp(locationstr,"")==0)
  10226. {
  10227. DEBUG_INFO("location is <Empty>!\n");
  10228. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10229. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10230. goto end;
  10231. }
  10232. memset(protocol, 0, ARRAY_SIZE(protocol));
  10233. memset(user, 0, ARRAY_SIZE(user) );
  10234. memset(password, 0, ARRAY_SIZE(password));
  10235. memset(host, 0, ARRAY_SIZE(host));
  10236. memset(path, 0, ARRAY_SIZE(path));
  10237. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10238. memset(host1, 0, ARRAY_SIZE(host1));
  10239. memset(path1, 0, ARRAY_SIZE(path1));
  10240. /*location: ftp://user:password@host:port/path*/
  10241. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10242. if((access(fnamePlusPath,F_OK))!=-1)
  10243. {
  10244. DEBUG_INFO("fnamePlusPath exist.\n");
  10245. }
  10246. else
  10247. {
  10248. DEBUG_INFO("fnamePlusPath not exist!\n");
  10249. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10250. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10251. goto end;
  10252. }
  10253. if(strchr(locationstr,'@')==NULL)
  10254. {
  10255. sscanf(locationstr,
  10256. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10257. protocol, host, &port, path);
  10258. strcpy(user,"anonymous");
  10259. strcpy(password,"");
  10260. }
  10261. else
  10262. {
  10263. //DEBUG_INFO("pch=%s\n", pch);
  10264. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10265. protocol, user, password, host, &port, path);
  10266. }
  10267. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10268. {
  10269. DEBUG_INFO("protocol is not ftp/http ! \n");
  10270. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10271. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10272. goto end;
  10273. }
  10274. if(strncmp(locationstr,"http", 4) == 0)
  10275. {
  10276. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10277. sprintf(ftppath,"/%s", path);
  10278. do
  10279. {
  10280. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10281. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10282. sleep(3);
  10283. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10284. if(!isSuccess)
  10285. {
  10286. DEBUG_INFO("Diagnostics fail.\n");
  10287. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10288. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10289. sleep(retryIntervalInt);
  10290. }
  10291. else
  10292. {
  10293. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10294. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10295. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10296. }
  10297. retriesInt--;
  10298. }while((isSuccess == 0)&&(retriesInt >= 0));
  10299. }
  10300. else
  10301. {
  10302. sscanf(host,"%[^/]%s",host1, path1);
  10303. if(strlen(path) > 0)
  10304. sprintf(ftppath,"/%s", path);
  10305. else
  10306. sprintf(ftppath,"/%s", path1);
  10307. int ftppathlen=strlen(ftppath);
  10308. int i=1;
  10309. char filenametemp[50];
  10310. while(i < ftppathlen)
  10311. {
  10312. int len=ftppathlen-i;
  10313. if(ftppath[len]== 47) // '/' ascll code: 47
  10314. {
  10315. DEBUG_INFO("find '/' all right\n");
  10316. break;
  10317. }
  10318. i=i+1;
  10319. }
  10320. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10321. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10322. filenametemp[i+1] = 0;
  10323. if(port == 0)
  10324. port = 21;
  10325. do
  10326. {
  10327. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10328. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10329. sleep(3);
  10330. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10331. if(!isSuccess)
  10332. {
  10333. DEBUG_INFO("Diagnostics fail.\n");
  10334. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10335. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10336. sleep(retryIntervalInt);
  10337. }
  10338. else
  10339. {
  10340. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10341. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10342. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10343. }
  10344. retriesInt--;
  10345. }while((!isSuccess)&&(retriesInt >= 0));
  10346. }
  10347. end:
  10348. system("rm -f /mnt/*");
  10349. sleep(5);
  10350. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10351. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10352. interLock.isGetDiagnosticGoing = 0;
  10353. pthread_exit(NULL);
  10354. }
  10355. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10356. {
  10357. mtrace();
  10358. int result = FAIL;
  10359. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10360. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10361. {
  10362. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10363. locallistVersion = -1;
  10364. }
  10365. else
  10366. {
  10367. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10368. OCPP_getListVerion();
  10369. }
  10370. //from db.OCPP_getListVerion
  10371. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10372. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  10373. sendGetLocalListVersionConfirmation(uuid,"");
  10374. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  10375. return result;
  10376. }
  10377. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10378. {
  10379. mtrace();
  10380. int result = FAIL;
  10381. int connectorIdInt=-1;
  10382. int tempIndex = 0;
  10383. int connectorIdIsNULL, chargingProfileIsNULL;
  10384. char comfirmstr[20]={0};
  10385. char cmdBuf[512];
  10386. json_object *RemoteStartTransaction;
  10387. FILE *fp;
  10388. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10389. if(server_pending == TRUE)
  10390. {
  10391. return 0;
  10392. }
  10393. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10394. RemoteStartTransaction = json_tokener_parse(payload);
  10395. if(!is_error(RemoteStartTransaction))
  10396. {
  10397. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10398. {
  10399. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10400. }
  10401. else
  10402. {
  10403. connectorIdIsNULL = TRUE;
  10404. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10405. {
  10406. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10407. {
  10408. connectorIdIsNULL = FALSE;
  10409. connectorIdInt = (gun_index+1);
  10410. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10411. break;
  10412. }
  10413. }
  10414. }
  10415. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10416. {
  10417. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10418. // Required data
  10419. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10420. // Optional data
  10421. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10422. {
  10423. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10424. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10425. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10426. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10427. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10428. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10429. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10430. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10431. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10432. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10433. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10434. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10435. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10436. {
  10437. 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")));
  10438. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10439. 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"));
  10440. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10441. 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"));
  10442. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10443. 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")));
  10444. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10445. {
  10446. 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++)
  10447. {
  10448. 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"));
  10449. 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"));
  10450. 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)
  10451. 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"));
  10452. }
  10453. }
  10454. }
  10455. }
  10456. else
  10457. {
  10458. chargingProfileIsNULL = TRUE;
  10459. }
  10460. }
  10461. }
  10462. else
  10463. {
  10464. connectorIdIsNULL = TRUE;
  10465. }
  10466. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10467. {
  10468. DEBUG_WARN("Connector id is NULL\n.");
  10469. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10470. goto end;
  10471. }
  10472. /*
  10473. enum _SYSTEM_STATUS
  10474. {
  10475. S_BOOTING = 0,
  10476. S_IDLE, = 1
  10477. S_AUTHORIZING, = 2
  10478. S_REASSIGN_CHECK, = 3
  10479. S_REASSIGN, = 4
  10480. S_PRECHARGE, = 5
  10481. S_PREPARING_FOR_EV, = 6
  10482. S_PREPARING_FOR_EVSE, = 7
  10483. S_CHARGING, = 8
  10484. S_TERMINATING, = 9
  10485. S_COMPLETE, = 10
  10486. S_ALARM, = 11
  10487. S_FAULT = 12
  10488. }
  10489. */
  10490. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10491. {
  10492. //check Transaction active
  10493. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10494. {
  10495. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10496. {
  10497. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10498. }
  10499. else
  10500. {
  10501. tempIndex = connectorIdInt -1;
  10502. }
  10503. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10504. {
  10505. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10506. {
  10507. 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))
  10508. {
  10509. //Reserved
  10510. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10511. }
  10512. 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))
  10513. {
  10514. //Reserved
  10515. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10516. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10517. goto end;
  10518. }
  10519. else
  10520. {
  10521. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10522. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10523. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10524. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10525. {
  10526. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10527. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10528. goto end;
  10529. }
  10530. }//END FOR ELSE
  10531. }
  10532. }// END FOR CHAdeMO_QUANTITY
  10533. }
  10534. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10535. {
  10536. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10537. {
  10538. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10539. }
  10540. else
  10541. {
  10542. tempIndex = connectorIdInt -1;
  10543. }
  10544. for (int index = 0; index < CCS_QUANTITY; index++)
  10545. {
  10546. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10547. {
  10548. 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))
  10549. {
  10550. //Reserved
  10551. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10552. }
  10553. 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))
  10554. {
  10555. //Reserved
  10556. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10557. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10558. goto end;
  10559. }
  10560. else
  10561. {
  10562. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10563. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10564. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10565. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10566. {
  10567. DEBUG_WARN("CCS connector not allow start\n.");
  10568. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10569. goto end;
  10570. }
  10571. }// END FOR ELSE
  10572. }
  10573. }// END FOR CCS_QUANTITY
  10574. }
  10575. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10576. {
  10577. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10578. {
  10579. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10580. }
  10581. else
  10582. {
  10583. tempIndex = connectorIdInt -1;
  10584. }
  10585. for (int index = 0; index < GB_QUANTITY; index++)
  10586. {
  10587. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10588. {
  10589. 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))
  10590. {
  10591. //Reserved
  10592. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10593. }
  10594. 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))
  10595. {
  10596. //Reserved
  10597. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10598. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10599. goto end;
  10600. }
  10601. else
  10602. {
  10603. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10604. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10605. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10606. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10607. {
  10608. DEBUG_WARN("GB connector not allow start\n.");
  10609. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10610. goto end;
  10611. }
  10612. }// END FOR ELSE
  10613. }
  10614. } // END FOR GB_QUANTITY
  10615. }
  10616. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10617. {
  10618. tempIndex = connectorIdInt -1;
  10619. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10620. {
  10621. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10622. {
  10623. 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))
  10624. {
  10625. //Reserved
  10626. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10627. }
  10628. 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))
  10629. {
  10630. //Reserved
  10631. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10632. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10633. goto end;
  10634. }
  10635. else
  10636. {
  10637. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10638. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10639. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10640. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10641. {
  10642. DEBUG_WARN("GB connector not allow start\n.");
  10643. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10644. goto end;
  10645. }
  10646. }// END FOR ELSE
  10647. }
  10648. } // END FOR GB_QUANTITY
  10649. }
  10650. else
  10651. {
  10652. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10653. {
  10654. tempIndex = 2;
  10655. }
  10656. else
  10657. {
  10658. tempIndex = connectorIdInt -1;
  10659. }
  10660. for (int index = 0; index < AC_QUANTITY; index++)
  10661. {
  10662. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10663. {
  10664. 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))
  10665. {
  10666. //Reserved
  10667. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10668. }
  10669. 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))
  10670. {
  10671. //Reserved
  10672. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10673. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10674. goto end;
  10675. }
  10676. else
  10677. {
  10678. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10679. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10680. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10681. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10682. {
  10683. DEBUG_WARN("AC connector not allow start\n.");
  10684. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10685. goto end;
  10686. }
  10687. }//END FOR ELSE
  10688. }
  10689. }// END FOR AC_QUANTITY
  10690. }
  10691. if(chargingProfileIsNULL == FALSE)
  10692. {
  10693. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10694. {
  10695. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10696. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10697. //memset idTag
  10698. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10699. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10700. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10701. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10702. // Save profile to file
  10703. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10704. system(cmdBuf);
  10705. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10706. fp = fopen(cmdBuf, "w");
  10707. 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));
  10708. fclose(fp);
  10709. }
  10710. else
  10711. {
  10712. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10713. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10714. }
  10715. }
  10716. else
  10717. {
  10718. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10719. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10720. //memset idTag
  10721. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10722. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10723. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10724. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10725. }
  10726. }
  10727. else
  10728. {
  10729. DEBUG_WARN("Connector id over\n.");
  10730. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10731. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10732. }
  10733. end:
  10734. json_object_put(RemoteStartTransaction);
  10735. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10736. {
  10737. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10738. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10739. }
  10740. //OCPP send RemoteStartConfirmation by first.
  10741. sendRemoteStartConfirmation(uuid, comfirmstr);
  10742. return result;
  10743. }
  10744. int handleRemoteStartRequest(char *uuid, char *payload)
  10745. {
  10746. mtrace();
  10747. int result = PASS;
  10748. int connectorIdInt=-1;
  10749. int tempIndex = 0;
  10750. char comfirmstr[20]={0};
  10751. char cmdBuf[512];
  10752. json_object *RemoteStartTransaction;
  10753. FILE *fp;
  10754. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10755. if(server_pending == TRUE)
  10756. {
  10757. result = FAIL;
  10758. }
  10759. RemoteStartTransaction = json_tokener_parse(payload);
  10760. if(!is_error(RemoteStartTransaction))
  10761. {
  10762. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10763. {
  10764. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10765. }
  10766. else
  10767. {
  10768. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10769. {
  10770. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10771. {
  10772. connectorIdInt = (gun_index+1);
  10773. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10774. break;
  10775. }
  10776. }
  10777. }
  10778. if(connectorIdInt == 0)
  10779. {
  10780. DEBUG_WARN("Connector id shall not equal 0.\n");
  10781. result = FAIL;
  10782. }
  10783. else if(connectorIdInt == -1)
  10784. {
  10785. DEBUG_INFO("Connector id does not specific.\n");
  10786. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10787. {
  10788. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10789. // Required data
  10790. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10791. // Optional data
  10792. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10793. {
  10794. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10795. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10796. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10797. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10798. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10799. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10800. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10801. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10802. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10803. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10804. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10805. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10806. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10807. {
  10808. 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")));
  10809. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10810. 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"));
  10811. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10812. 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"));
  10813. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10814. 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")));
  10815. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10816. {
  10817. 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++)
  10818. {
  10819. 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"));
  10820. 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"));
  10821. 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)
  10822. 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"));
  10823. }
  10824. }
  10825. }
  10826. }
  10827. else
  10828. {
  10829. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10830. }
  10831. }
  10832. }
  10833. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10834. {
  10835. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10836. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10837. // Required data
  10838. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10839. // Optional data
  10840. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10841. {
  10842. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10843. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10844. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10845. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10846. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10847. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10848. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10849. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10850. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10851. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10852. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10853. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10854. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10855. {
  10856. 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")));
  10857. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10858. 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"));
  10859. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10860. 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"));
  10861. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10862. 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")));
  10863. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10864. {
  10865. 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++)
  10866. {
  10867. 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"));
  10868. 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"));
  10869. 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)
  10870. 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"));
  10871. }
  10872. }
  10873. }
  10874. }
  10875. else
  10876. {
  10877. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10878. }
  10879. }
  10880. else
  10881. {
  10882. DEBUG_WARN("Connector id is over maximun value.\n");
  10883. result = FAIL;
  10884. }
  10885. }
  10886. if(result == PASS)
  10887. {
  10888. if(connectorIdInt > 0)
  10889. {
  10890. //check Transaction active
  10891. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10892. {
  10893. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10894. {
  10895. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10896. }
  10897. else
  10898. {
  10899. tempIndex = connectorIdInt -1;
  10900. }
  10901. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10902. {
  10903. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10904. {
  10905. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10906. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10907. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10908. {
  10909. //Reserved
  10910. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10911. }
  10912. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10913. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10914. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10915. {
  10916. //Reserved
  10917. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10918. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10919. goto end;
  10920. }
  10921. else
  10922. {
  10923. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10924. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10925. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10926. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10927. {
  10928. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10929. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10930. goto end;
  10931. }
  10932. }//END FOR ELSE
  10933. }
  10934. }// END FOR CHAdeMO_QUANTITY
  10935. }
  10936. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10937. {
  10938. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10939. {
  10940. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10941. }
  10942. else
  10943. {
  10944. tempIndex = connectorIdInt -1;
  10945. }
  10946. for (int index = 0; index < CCS_QUANTITY; index++)
  10947. {
  10948. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10949. {
  10950. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10951. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10952. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10953. {
  10954. //Reserved
  10955. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10956. }
  10957. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10958. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10959. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10960. {
  10961. //Reserved
  10962. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10963. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10964. goto end;
  10965. }
  10966. else
  10967. {
  10968. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10969. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10970. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10971. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10972. {
  10973. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10974. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10975. goto end;
  10976. }
  10977. }// END FOR ELSE
  10978. }
  10979. }// END FOR CCS_QUANTITY
  10980. }
  10981. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10982. {
  10983. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10984. {
  10985. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10986. }
  10987. else
  10988. {
  10989. tempIndex = connectorIdInt -1;
  10990. }
  10991. for (int index = 0; index < GB_QUANTITY; index++)
  10992. {
  10993. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10994. {
  10995. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10996. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10997. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10998. {
  10999. //Reserved
  11000. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11001. }
  11002. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11003. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11004. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11005. {
  11006. //Reserved
  11007. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11008. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11009. goto end;
  11010. }
  11011. else
  11012. {
  11013. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11014. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11015. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11016. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11017. {
  11018. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11019. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11020. goto end;
  11021. }
  11022. }// END FOR ELSE
  11023. }
  11024. } // END FOR GB_QUANTITY
  11025. }
  11026. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11027. {
  11028. tempIndex = connectorIdInt -1;
  11029. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11030. {
  11031. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11032. {
  11033. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11034. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11035. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11036. {
  11037. //Reserved
  11038. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11039. }
  11040. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11041. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11042. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11043. {
  11044. //Reserved
  11045. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11046. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11047. goto end;
  11048. }
  11049. else
  11050. {
  11051. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11052. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11053. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11054. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11055. {
  11056. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11057. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11058. goto end;
  11059. }
  11060. }// END FOR ELSE
  11061. }
  11062. } // END FOR GB_QUANTITY
  11063. }
  11064. else
  11065. {
  11066. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11067. {
  11068. tempIndex = 2;
  11069. }
  11070. else
  11071. {
  11072. tempIndex = connectorIdInt -1;
  11073. }
  11074. for (int index = 0; index < AC_QUANTITY; index++)
  11075. {
  11076. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11077. {
  11078. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11079. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11080. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11081. {
  11082. //Reserved
  11083. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11084. }
  11085. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11086. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11087. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11088. {
  11089. //Reserved
  11090. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11091. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11092. goto end;
  11093. }
  11094. else
  11095. {
  11096. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11097. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11098. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11099. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11100. {
  11101. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11102. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11103. goto end;
  11104. }
  11105. }//END FOR ELSE
  11106. }
  11107. }// END FOR AC_QUANTITY
  11108. }
  11109. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11110. {
  11111. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11112. {
  11113. // Save profile to file
  11114. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11115. system(cmdBuf);
  11116. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11117. fp = fopen(cmdBuf, "w");
  11118. 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));
  11119. fclose(fp);
  11120. }
  11121. else
  11122. {
  11123. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11124. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11125. goto end;
  11126. }
  11127. }
  11128. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11129. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11130. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11131. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11132. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11133. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11134. }
  11135. else
  11136. {
  11137. uint8_t isHasIdleConnector = FALSE;
  11138. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11139. {
  11140. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11141. {
  11142. isHasIdleConnector = TRUE;
  11143. break;
  11144. }
  11145. }
  11146. if(isHasIdleConnector == TRUE)
  11147. {
  11148. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11149. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11150. {
  11151. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11152. {
  11153. // Save profile to file
  11154. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11155. system(cmdBuf);
  11156. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11157. fp = fopen(cmdBuf, "w");
  11158. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11159. fclose(fp);
  11160. refreshStartTimer(&clientTime.RemoteStartWait);
  11161. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11162. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11163. }
  11164. else
  11165. {
  11166. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11167. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11168. }
  11169. }
  11170. else
  11171. {
  11172. refreshStartTimer(&clientTime.RemoteStartWait);
  11173. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11174. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11175. }
  11176. }
  11177. else
  11178. {
  11179. DEBUG_INFO("There is not any connector is idle.\n");
  11180. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11181. }
  11182. }
  11183. }
  11184. else
  11185. {
  11186. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11187. }
  11188. end:
  11189. json_object_put(RemoteStartTransaction);
  11190. sendRemoteStartConfirmation(uuid, comfirmstr);
  11191. return result;
  11192. }
  11193. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11194. {
  11195. mtrace();
  11196. int result = FAIL;
  11197. int match = FALSE;
  11198. int GunNO = 0;
  11199. int tempIndex = 0;
  11200. int transactionIdInt=0;
  11201. int transactionIdIsNULL= TRUE;
  11202. char comfirmstr[20];
  11203. json_object *RemoteStopTransaction;
  11204. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11205. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11206. if(server_pending == TRUE)
  11207. {
  11208. return 0;
  11209. }
  11210. RemoteStopTransaction = json_tokener_parse(payload);
  11211. if(!is_error(RemoteStopTransaction))
  11212. {
  11213. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11214. {
  11215. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11216. transactionIdIsNULL = FALSE;
  11217. }
  11218. }
  11219. json_object_put(RemoteStopTransaction);
  11220. if(transactionIdIsNULL == FALSE)
  11221. {
  11222. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11223. {
  11224. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11225. {
  11226. //check Transaction active
  11227. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11228. {
  11229. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11230. {
  11231. tempIndex = ((gun_index==2) ? 1: 0);
  11232. }
  11233. else
  11234. {
  11235. tempIndex = gun_index;
  11236. }
  11237. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11238. {
  11239. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11240. {
  11241. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11242. {
  11243. match = TRUE;
  11244. GunNO = gun_index;
  11245. }
  11246. }
  11247. }// END FOR CHAdeMO_QUANTITY
  11248. }
  11249. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11250. {
  11251. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11252. {
  11253. tempIndex = ((gun_index==2) ? 1: 0);
  11254. }
  11255. else
  11256. {
  11257. tempIndex = gun_index;
  11258. }
  11259. for (int index = 0; index < CCS_QUANTITY; index++)
  11260. {
  11261. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11262. {
  11263. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11264. {
  11265. match = TRUE;
  11266. GunNO = gun_index;
  11267. }
  11268. }
  11269. }// END FOR CCS_QUANTITY
  11270. }
  11271. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11272. {
  11273. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11274. {
  11275. tempIndex = ((gun_index==2) ? 1: 0);
  11276. }
  11277. else
  11278. {
  11279. tempIndex = gun_index;
  11280. }
  11281. for (int index = 0; index < GB_QUANTITY; index++)
  11282. {
  11283. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11284. {
  11285. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11286. {
  11287. match = TRUE;
  11288. GunNO = gun_index;
  11289. }
  11290. }
  11291. }// END FOR GB_QUANTITY
  11292. }
  11293. else if(gunType[gun_index] == GUN_TYPE_DO)
  11294. {
  11295. tempIndex = gun_index;
  11296. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11297. {
  11298. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11299. {
  11300. 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
  11301. {
  11302. match = TRUE;
  11303. GunNO = gun_index;
  11304. }
  11305. }
  11306. }// END FOR GB_QUANTITY
  11307. }
  11308. else
  11309. {
  11310. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11311. {
  11312. tempIndex = 2;
  11313. }
  11314. else
  11315. {
  11316. tempIndex = gun_index;
  11317. }
  11318. for (int index = 0; index < AC_QUANTITY; index++)
  11319. {
  11320. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11321. {
  11322. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11323. {
  11324. match = TRUE;
  11325. GunNO = gun_index;
  11326. }
  11327. }
  11328. }// END FOR CHAdeMO_QUANTITY
  11329. } // END FOR AC ELSE
  11330. }// CHECK IF ResponseTransactionId == transactionIdInt
  11331. }//END FOR
  11332. if( match == TRUE)
  11333. {
  11334. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11335. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11336. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11337. }
  11338. else
  11339. {
  11340. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11341. }
  11342. }
  11343. else
  11344. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11345. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11346. return result;
  11347. }
  11348. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11349. {
  11350. mtrace();
  11351. int result = FAIL;
  11352. int connectorIdInt=0, reservationIdInt=0;
  11353. int tempIndex = 0;
  11354. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  11355. char comfirmstr[20]={0};
  11356. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11357. int c = 0;
  11358. char *loc;
  11359. //char *ptr;
  11360. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11361. strcpy(sstrtemp, stringtrimspace(payload));
  11362. //***(1)connectorId ****/
  11363. c=0;
  11364. loc = strstr(sstrtemp, "connectorId");
  11365. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11366. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11367. {
  11368. sstr[c] = loc[strlen("connectorId")+2+c];
  11369. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11370. c++;
  11371. }
  11372. sstr[c] = '\0';
  11373. connectorIdInt = atoi(sstr);
  11374. //***(2)expiryDate ****/
  11375. loc = strstr(sstrtemp, "expiryDate");
  11376. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11377. c = 0;
  11378. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11379. {
  11380. sstr[c] = loc[3+strlen("expiryDate")+c];
  11381. c++;
  11382. }
  11383. sstr[c] = '\0';
  11384. strcpy(expiryDatestr, sstr);
  11385. //***(3)idTag ****/
  11386. loc = strstr(sstrtemp, "idTag");
  11387. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11388. c = 0;
  11389. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11390. {
  11391. sstr[c] = loc[3+strlen("idTag")+c];
  11392. c++;
  11393. }
  11394. sstr[c] = '\0';
  11395. strcpy(idTagstr, sstr);
  11396. //***(4)parentIdTag ****/
  11397. loc = strstr(sstrtemp, "parentIdTag");
  11398. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11399. c = 0;
  11400. if(loc == NULL)
  11401. {
  11402. strcpy(parentIdTagstr, "");
  11403. }
  11404. else
  11405. {
  11406. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11407. {
  11408. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11409. c++;
  11410. }
  11411. sstr[c] = '\0';
  11412. strcpy(parentIdTagstr, sstr);
  11413. }
  11414. //***(5)reservationId ****/
  11415. c=0;
  11416. loc = strstr(sstrtemp, "reservationId");
  11417. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11418. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11419. {
  11420. sstr[c] = loc[strlen("reservationId")+2+c];
  11421. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11422. c++;
  11423. }
  11424. sstr[c] = '\0';
  11425. reservationIdInt = atoi(sstr);
  11426. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11427. /*
  11428. enum SYSTEM_STATUS
  11429. {
  11430. SYS_MODE_BOOTING = 0,
  11431. SYS_MODE_IDLE = 1,
  11432. SYS_MODE_AUTHORIZING = 2,
  11433. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11434. SYS_MODE_REASSIGN = 4,
  11435. SYS_MODE_PREPARING = 5,
  11436. SYS_MODE_PREPARE_FOR_EV = 6,
  11437. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11438. SYS_MODE_CHARGING = 8,
  11439. SYS_MODE_TERMINATING = 9,
  11440. SYS_MODE_COMPLETE = 10,
  11441. SYS_MODE_ALARM = 11,
  11442. SYS_MODE_FAULT = 12,
  11443. SYS_MODE_RESERVATION = 13,
  11444. SYS_MODE_BOOKING = 14,
  11445. SYS_MODE_MAINTAIN = 15,
  11446. SYS_MODE_DEBUG = 16,
  11447. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11448. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11449. SYS_MODE_UPDATE = 19
  11450. };
  11451. */
  11452. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11453. {
  11454. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11455. goto end;
  11456. }
  11457. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11458. {
  11459. //check Transaction active
  11460. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11461. {
  11462. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11463. {
  11464. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11465. }
  11466. else
  11467. {
  11468. tempIndex = connectorIdInt -1;
  11469. }
  11470. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11471. {
  11472. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11473. {
  11474. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11475. {
  11476. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11477. {
  11478. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11479. {
  11480. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11481. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11482. }
  11483. 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'))
  11484. {
  11485. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11486. }
  11487. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11488. {
  11489. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11490. }
  11491. else
  11492. {
  11493. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11494. }
  11495. }
  11496. 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
  11497. {
  11498. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11499. }
  11500. }
  11501. else
  11502. {
  11503. //replace reservation
  11504. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11505. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11506. }
  11507. }
  11508. } // END FOR CHAdeMO_QUANTITY
  11509. }
  11510. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11511. {
  11512. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11513. {
  11514. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11515. }
  11516. else
  11517. {
  11518. tempIndex = connectorIdInt -1;
  11519. }
  11520. for (int index = 0; index < CCS_QUANTITY; index++)
  11521. {
  11522. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11523. {
  11524. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11525. {
  11526. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11527. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11528. {
  11529. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11530. {
  11531. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11532. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11533. }
  11534. 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'))
  11535. {
  11536. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11537. }
  11538. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11539. {
  11540. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11541. }
  11542. else
  11543. {
  11544. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11545. }
  11546. }
  11547. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_ALARM) ||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAUL, SYS_MODE_TERMINATING ---> SuspendedEV
  11548. {
  11549. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11550. }
  11551. }
  11552. else
  11553. {
  11554. //replace reservation
  11555. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11556. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11557. }
  11558. }
  11559. } // END FOR CCS_QUANTITY
  11560. }
  11561. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11562. {
  11563. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11564. {
  11565. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11566. }
  11567. else
  11568. {
  11569. tempIndex = connectorIdInt -1;
  11570. }
  11571. for (int index = 0; index < GB_QUANTITY; index++)
  11572. {
  11573. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11574. {
  11575. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11576. {
  11577. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11578. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11579. {
  11580. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11581. {
  11582. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11583. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11584. }
  11585. 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'))
  11586. {
  11587. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11588. }
  11589. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11590. {
  11591. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11592. }
  11593. else
  11594. {
  11595. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11596. }
  11597. }
  11598. 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
  11599. {
  11600. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11601. }
  11602. }
  11603. else
  11604. {
  11605. //replace reservation
  11606. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11607. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11608. }
  11609. }
  11610. }// END FOR GB_QUANTITY
  11611. }
  11612. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11613. {
  11614. tempIndex = connectorIdInt -1;
  11615. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11616. {
  11617. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11618. {
  11619. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11620. {
  11621. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11622. 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
  11623. {
  11624. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11625. {
  11626. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11627. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11628. }
  11629. 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'))
  11630. {
  11631. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11632. }
  11633. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11634. {
  11635. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11636. }
  11637. else
  11638. {
  11639. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11640. }
  11641. }
  11642. 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
  11643. {
  11644. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11645. }
  11646. }
  11647. else
  11648. {
  11649. //replace reservation
  11650. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11651. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11652. }
  11653. }
  11654. }// END FOR GB_QUANTITY
  11655. }
  11656. else
  11657. {
  11658. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11659. {
  11660. tempIndex = 2;
  11661. }
  11662. else
  11663. {
  11664. tempIndex = (connectorIdInt -1);
  11665. }
  11666. for (int index = 0; index < AC_QUANTITY; index++)
  11667. {
  11668. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11669. {
  11670. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11671. {
  11672. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11673. {
  11674. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11675. {
  11676. 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))
  11677. {
  11678. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11679. }
  11680. else
  11681. {
  11682. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11683. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11684. }
  11685. }
  11686. 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'))
  11687. {
  11688. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11689. }
  11690. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11691. {
  11692. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11693. }
  11694. else
  11695. {
  11696. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11697. }
  11698. }
  11699. 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
  11700. {
  11701. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11702. }
  11703. }
  11704. else
  11705. {
  11706. //replace reservation
  11707. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11708. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11709. }
  11710. }
  11711. } // END FOR AC_QUANTITY
  11712. }
  11713. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11714. }
  11715. else if(connectorIdInt == 0)
  11716. {
  11717. //check Transaction active
  11718. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11719. {
  11720. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11721. {
  11722. 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'))
  11723. {
  11724. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11725. goto end;
  11726. }
  11727. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11728. {
  11729. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11730. goto end;
  11731. }
  11732. 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
  11733. {
  11734. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11735. goto end;
  11736. }
  11737. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11738. {
  11739. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11740. goto end;
  11741. }
  11742. }
  11743. }// END FOR CHAdeMO_QUANTITY
  11744. for (int index = 0; index < CCS_QUANTITY; index++)
  11745. {
  11746. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11747. {
  11748. 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'))
  11749. {
  11750. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11751. goto end;
  11752. }
  11753. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11754. {
  11755. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11756. goto end;
  11757. }
  11758. 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
  11759. {
  11760. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11761. goto end;
  11762. }
  11763. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11764. {
  11765. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11766. goto end;
  11767. }
  11768. }
  11769. } // END FOR CCS_QUANTITY
  11770. for (int index = 0; index < GB_QUANTITY; index++)
  11771. {
  11772. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11773. {
  11774. 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'))
  11775. {
  11776. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11777. goto end;
  11778. }
  11779. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11780. {
  11781. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11782. goto end;
  11783. }
  11784. 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
  11785. {
  11786. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11787. goto end;
  11788. }
  11789. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11790. {
  11791. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11792. goto end;
  11793. }
  11794. }
  11795. } // END FOR GB_QUANTITY
  11796. for (int index = 0; index < AC_QUANTITY; index++)
  11797. {
  11798. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11799. {
  11800. 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'))
  11801. {
  11802. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11803. goto end;
  11804. }
  11805. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11806. {
  11807. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11808. goto end;
  11809. }
  11810. 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
  11811. {
  11812. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11813. goto end;
  11814. }
  11815. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11816. {
  11817. 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))
  11818. {
  11819. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11820. goto end;
  11821. }
  11822. }
  11823. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11824. {
  11825. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11826. goto end;
  11827. }
  11828. }
  11829. }// END FOR AC_QUANTITY
  11830. //The connectorId is 0
  11831. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  11832. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11833. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11834. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  11835. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11836. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  11837. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11838. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  11839. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  11840. result = TRUE;
  11841. return result;
  11842. }
  11843. else
  11844. {
  11845. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11846. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11847. }
  11848. if(strcmp(comfirmstr,"Accepted") == 0)
  11849. {
  11850. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11851. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11852. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11853. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11854. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11855. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  11856. result = TRUE;
  11857. return result;
  11858. }
  11859. end:
  11860. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11861. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11862. return result;
  11863. }
  11864. int handleResetRequest(char *uuid, char *payload)
  11865. {
  11866. mtrace();
  11867. int result = FAIL;
  11868. char sstr[10]={0},sstrtemp[30]={ 0 };
  11869. char typestr[10]={0};
  11870. char comfirmstr[20]={0};
  11871. int c = 0;
  11872. char *loc;
  11873. DEBUG_INFO("handleResetRequest...\n");
  11874. strcpy(sstrtemp, stringtrimspace(payload));
  11875. loc = strstr(sstrtemp, "type");
  11876. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11877. c = 0;
  11878. while (loc[3+strlen("type")+c] != '\"')
  11879. {
  11880. sstr[c] = loc[3+strlen("type")+c];
  11881. c++;
  11882. }
  11883. sstr[c] = '\0';
  11884. strcpy(typestr,sstr);
  11885. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11886. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11887. {
  11888. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11889. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  11890. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11891. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11892. }
  11893. else
  11894. {
  11895. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11896. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11897. result = PASS;
  11898. }
  11899. sendResetConfirmation(uuid, comfirmstr);
  11900. return result;
  11901. }
  11902. int handleSendLocalListRequest(char *uuid, char *payload)
  11903. {
  11904. mtrace();
  11905. int result = FAIL;
  11906. char comfirmstr[20];
  11907. int checkState_Faulted = FALSE;
  11908. json_object *SendLocalList;
  11909. DEBUG_INFO("handleSendLocalListRequest...\n");
  11910. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11911. {
  11912. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11913. goto end;
  11914. }
  11915. //check Charge Point state
  11916. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11917. {
  11918. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11919. {
  11920. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11921. }
  11922. }
  11923. for (int index = 0; index < CCS_QUANTITY; index++)
  11924. {
  11925. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11926. {
  11927. checkState_Faulted = TRUE; //OCPP Status
  11928. }
  11929. }
  11930. for (int index = 0; index < GB_QUANTITY; index++)
  11931. {
  11932. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11933. {
  11934. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11935. }
  11936. }
  11937. //check Charge Point state
  11938. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11939. {
  11940. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11941. {
  11942. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11943. }
  11944. }
  11945. //check Charge Point state
  11946. for (int index = 0; index < AC_QUANTITY; index++)
  11947. {
  11948. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11949. {
  11950. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11951. }
  11952. }
  11953. if(checkState_Faulted == TRUE)
  11954. {
  11955. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11956. goto end;
  11957. }
  11958. // Parsing payload
  11959. SendLocalList = json_tokener_parse(payload);
  11960. if(!is_error(SendLocalList))
  11961. {
  11962. // Required data
  11963. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11964. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11965. // Optional data
  11966. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11967. {
  11968. //Check UpdateType
  11969. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11970. {
  11971. //Local list full update
  11972. DEBUG_INFO("Local list full update.\n");
  11973. OCPP_getListVerion();
  11974. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11975. {
  11976. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11977. goto end;
  11978. }
  11979. OCPP_cleanLocalList();
  11980. }
  11981. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11982. {
  11983. //Local list different update
  11984. DEBUG_INFO("Local list different update.\n");
  11985. OCPP_getListVerion();
  11986. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11987. {
  11988. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11989. goto end;
  11990. }
  11991. }
  11992. else
  11993. {
  11994. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11995. goto end;
  11996. }
  11997. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11998. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11999. {
  12000. 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")));
  12001. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12002. {
  12003. 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")));
  12004. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12005. 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")));
  12006. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12007. 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")));
  12008. }
  12009. // Add to db
  12010. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12011. {
  12012. //Local list full update
  12013. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12014. idx,
  12015. ShmOCPP16Data->SendLocalList.ListVersion,
  12016. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12017. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12018. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12019. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12020. // update list
  12021. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12022. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12023. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12024. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12025. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12026. }
  12027. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12028. {
  12029. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12030. idx,
  12031. ShmOCPP16Data->SendLocalList.ListVersion,
  12032. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12033. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12034. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12035. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12036. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12037. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12038. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12039. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12040. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12041. }
  12042. }
  12043. }
  12044. else
  12045. {
  12046. //Check UpdateType
  12047. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12048. {
  12049. //Local list full update
  12050. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12051. OCPP_cleanLocalList();
  12052. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12053. goto end;
  12054. }
  12055. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12056. {
  12057. //Local list different update
  12058. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12059. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12060. goto end;
  12061. }
  12062. }
  12063. result = PASS;
  12064. }
  12065. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12066. end:
  12067. json_object_put(SendLocalList);
  12068. sendSendLocalListConfirmation(uuid, comfirmstr);
  12069. return result;
  12070. }
  12071. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12072. {
  12073. mtrace();
  12074. int result = FAIL;
  12075. struct StructSetChargingProfile SetProfileReq = {0};
  12076. int tempchargingProfileIdInt;
  12077. int chargingSchedulePeriodCount = 0;
  12078. char comfirmstr[20]={0};
  12079. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12080. char rmFileCmd[128]={0};
  12081. int profileQuantity = 0;
  12082. json_object *SetChargingProfile;
  12083. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12084. SetChargingProfile = json_tokener_parse(payload);
  12085. if(!is_error(SetChargingProfile))
  12086. {
  12087. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12088. {
  12089. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12090. }
  12091. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12092. {
  12093. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12094. {
  12095. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12096. }
  12097. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12098. {
  12099. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12100. }
  12101. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12102. {
  12103. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12104. }
  12105. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12106. {
  12107. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12108. }
  12109. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12110. {
  12111. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12112. }
  12113. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12114. {
  12115. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12116. }
  12117. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12118. {
  12119. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12120. }
  12121. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12122. {
  12123. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12124. }
  12125. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12126. {
  12127. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12128. {
  12129. 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")));
  12130. }
  12131. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12132. {
  12133. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12134. }
  12135. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12136. {
  12137. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12138. }
  12139. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12140. {
  12141. 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")));
  12142. }
  12143. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12144. {
  12145. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12146. if(chargingSchedulePeriodCount <= 10)
  12147. {
  12148. 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++)
  12149. {
  12150. 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)
  12151. {
  12152. 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"));
  12153. }
  12154. 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)
  12155. {
  12156. 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"));
  12157. }
  12158. 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)
  12159. {
  12160. 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"));
  12161. }
  12162. }
  12163. }
  12164. }
  12165. }
  12166. }
  12167. }
  12168. // Profile periods quantity check
  12169. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12170. {
  12171. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12172. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12173. goto end;
  12174. }
  12175. // Check invalid limit
  12176. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12177. {
  12178. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12179. {
  12180. 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)))) ||
  12181. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12182. {
  12183. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12184. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12185. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12186. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12187. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12188. goto end;
  12189. }
  12190. }
  12191. }
  12192. else
  12193. {
  12194. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12195. {
  12196. 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))
  12197. {
  12198. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12199. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12200. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12201. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12202. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12203. goto end;
  12204. }
  12205. }
  12206. }
  12207. // Profile purpose info check
  12208. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12209. {
  12210. FILE *fp;
  12211. char dataLine[4096]={0};
  12212. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12213. if(SetProfileReq.ConnectorId != 0)
  12214. {
  12215. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12216. DEBUG_WARN("Profile connector id is not 0.\n");
  12217. goto end;
  12218. }
  12219. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12220. if (!fp)
  12221. {
  12222. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12223. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12224. }
  12225. else
  12226. {
  12227. while(fscanf(fp, "%s", dataLine) != EOF)
  12228. {
  12229. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12230. {
  12231. profileQuantity += 1;
  12232. }
  12233. }
  12234. }
  12235. fclose(fp);
  12236. }
  12237. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12238. {
  12239. FILE *fp;
  12240. char dataLine[4096]={0};
  12241. char filename[128]={0};
  12242. int tmpProfileQuantity;
  12243. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12244. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12245. {
  12246. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12247. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12248. goto end;
  12249. }
  12250. if(SetProfileReq.ConnectorId == 0)
  12251. {
  12252. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12253. {
  12254. tmpProfileQuantity = 0;
  12255. memset(filename, 0, ARRAY_SIZE(filename));
  12256. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12257. fp = fopen(filename, "r");
  12258. if (!fp)
  12259. {
  12260. DEBUG_INFO("%s does not create.\n", filename);
  12261. fp = fopen(filename, "w+");
  12262. }
  12263. else
  12264. {
  12265. while(fscanf(fp, "%s", dataLine) != EOF)
  12266. {
  12267. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12268. {
  12269. tmpProfileQuantity += 1;
  12270. }
  12271. }
  12272. }
  12273. fclose(fp);
  12274. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12275. }
  12276. }
  12277. else
  12278. {
  12279. memset(filename, 0, ARRAY_SIZE(filename));
  12280. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12281. fp = fopen(filename, "r");
  12282. if (!fp)
  12283. {
  12284. DEBUG_INFO("%s does not create.\n", filename);
  12285. fp = fopen(filename, "w+");
  12286. }
  12287. else
  12288. {
  12289. while(fscanf(fp, "%s", dataLine) != EOF)
  12290. {
  12291. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12292. {
  12293. profileQuantity += 1;
  12294. }
  12295. }
  12296. }
  12297. fclose(fp);
  12298. }
  12299. }
  12300. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12301. {
  12302. int isMatchTransactiodId= FALSE;
  12303. FILE *fp;
  12304. char dataLine[4096]={0};
  12305. char filename[128]={0};
  12306. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12307. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12308. if(SetProfileReq.ConnectorId == 0)
  12309. {
  12310. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12311. DEBUG_WARN("Profile connector id is 0.\n");
  12312. goto end;
  12313. }
  12314. int tempIndex = 0;
  12315. //check Transaction active
  12316. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12317. {
  12318. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12319. {
  12320. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12321. }
  12322. else
  12323. {
  12324. tempIndex = SetProfileReq.ConnectorId -1;
  12325. }
  12326. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12327. {
  12328. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12329. {
  12330. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12331. {
  12332. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12333. {
  12334. isMatchTransactiodId = TRUE;
  12335. break;
  12336. }
  12337. }
  12338. }
  12339. }
  12340. }
  12341. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12342. {
  12343. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12344. {
  12345. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12346. }
  12347. else
  12348. {
  12349. tempIndex = SetProfileReq.ConnectorId -1;
  12350. }
  12351. for (int index = 0; index < CCS_QUANTITY; index++)
  12352. {
  12353. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12354. {
  12355. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12356. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12357. {
  12358. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12359. {
  12360. isMatchTransactiodId = TRUE;
  12361. break;
  12362. }
  12363. }
  12364. }
  12365. }
  12366. }
  12367. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12368. {
  12369. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12370. {
  12371. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12372. }
  12373. else
  12374. {
  12375. tempIndex = SetProfileReq.ConnectorId -1;
  12376. }
  12377. for (int index = 0; index < GB_QUANTITY; index++)
  12378. {
  12379. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12380. {
  12381. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12382. {
  12383. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12384. {
  12385. isMatchTransactiodId = TRUE;
  12386. break;
  12387. }
  12388. }
  12389. }
  12390. }
  12391. }
  12392. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12393. {
  12394. tempIndex = SetProfileReq.ConnectorId -1;
  12395. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12396. {
  12397. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12398. {
  12399. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12400. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12401. {
  12402. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12403. {
  12404. isMatchTransactiodId = TRUE;
  12405. break;
  12406. }
  12407. }
  12408. }
  12409. }
  12410. }
  12411. else
  12412. {
  12413. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12414. {
  12415. tempIndex = 2;
  12416. }
  12417. else
  12418. {
  12419. tempIndex = (SetProfileReq.ConnectorId -1);
  12420. }
  12421. for (int index = 0; index < AC_QUANTITY; index++)
  12422. {
  12423. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12424. {
  12425. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12426. {
  12427. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12428. {
  12429. isMatchTransactiodId = TRUE;
  12430. break;
  12431. }
  12432. }
  12433. }
  12434. }
  12435. }
  12436. //check Transaction active
  12437. if(isMatchTransactiodId == FALSE)
  12438. {
  12439. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12440. DEBUG_WARN("Tx profile transaction id is not match.\n");
  12441. goto end;
  12442. }
  12443. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12444. {
  12445. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12446. DEBUG_WARN("Connector id is over max gun number.\n");
  12447. goto end;
  12448. }
  12449. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12450. fp = fopen(filename, "r");
  12451. if (!fp)
  12452. {
  12453. DEBUG_INFO("%s does not create.\n", filename);
  12454. fp = fopen(filename, "w+");
  12455. }
  12456. else
  12457. {
  12458. //Check Charging Profile Count
  12459. while(fscanf(fp, "%s", dataLine) != EOF)
  12460. {
  12461. //DEBUG_INFO("word=%s\n",word);
  12462. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12463. {
  12464. profileQuantity += 1;
  12465. }
  12466. }
  12467. }
  12468. fclose(fp);
  12469. }
  12470. // Check ChargeProfileMaxStackLevel
  12471. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12472. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12473. {
  12474. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12475. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12476. goto end;
  12477. }
  12478. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12479. {
  12480. FILE *fp;
  12481. char dataLine[4096]={0};
  12482. char fnametemp[128]={0};
  12483. int tmpProfileQuantity;
  12484. //Check ChargePointMaxProfile.json exit
  12485. profileQuantity = 0;
  12486. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12487. {
  12488. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  12489. //Check Charging Profile Count
  12490. tmpProfileQuantity = 0;
  12491. while(fscanf(fp, "%s", dataLine) != EOF)
  12492. {
  12493. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12494. {
  12495. profileQuantity += 1;
  12496. tmpProfileQuantity += 1;
  12497. }
  12498. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12499. }
  12500. fclose(fp);
  12501. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12502. }
  12503. //Check TxDefaultProfile_%d.json
  12504. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12505. {
  12506. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12507. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12508. if((access(fnametemp,F_OK))!=-1)
  12509. {
  12510. fp = fopen(fnametemp, "r");
  12511. //Check Charging Profile Count
  12512. tmpProfileQuantity = 0;
  12513. while(fscanf(fp, "%s", dataLine) != EOF)
  12514. {
  12515. //DEBUG_INFO("word=%s\n",word);
  12516. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12517. {
  12518. profileQuantity += 1;
  12519. tmpProfileQuantity += 1;
  12520. }
  12521. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12522. }
  12523. fclose(fp);
  12524. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12525. }
  12526. }
  12527. //Check TxProfile_%d.json
  12528. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12529. {
  12530. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12531. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  12532. if((access(fnametemp,F_OK))!=-1)
  12533. {
  12534. fp = fopen(fnametemp, "r");
  12535. //Check Charging Profile Count
  12536. tmpProfileQuantity = 0;
  12537. while(fscanf(fp, "%s", dataLine) != EOF)
  12538. {
  12539. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12540. {
  12541. profileQuantity += 1;
  12542. tmpProfileQuantity += 1;
  12543. }
  12544. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12545. }
  12546. fclose(fp);
  12547. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12548. }
  12549. }
  12550. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12551. if(profileQuantity > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12552. {
  12553. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12554. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12555. goto end;
  12556. }
  12557. }
  12558. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12559. //**********************************Write to File********************************************************/
  12560. {
  12561. FILE *infile;
  12562. FILE *outfile;
  12563. char dataLine[4096]={0};
  12564. char filename[128]={0};
  12565. int chkChar=0;
  12566. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12567. {
  12568. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12569. {
  12570. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12571. }
  12572. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12573. {
  12574. if(SetProfileReq.ConnectorId==0)
  12575. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12576. else
  12577. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12578. }
  12579. else
  12580. {
  12581. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12582. }
  12583. infile = fopen (filename, "r");
  12584. outfile = fopen (tempfile, "w");
  12585. chkChar = fgetc(infile);
  12586. rewind(infile);
  12587. if(chkChar == EOF)
  12588. {
  12589. // Profile is empty
  12590. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12591. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12592. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12593. fclose(infile);
  12594. fclose(outfile);
  12595. sprintf(rmFileCmd,"rm -f %s",filename);
  12596. system(rmFileCmd);
  12597. rename(tempfile, filename);
  12598. }
  12599. else
  12600. {
  12601. // Profile is not empty
  12602. int ChargingProfileAdded = FALSE;
  12603. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12604. {
  12605. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12606. json_object *tmpChargingProfile;
  12607. tmpChargingProfile = json_tokener_parse(dataLine);
  12608. if(!is_error(SetChargingProfile))
  12609. {
  12610. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12611. {
  12612. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12613. {
  12614. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12615. }
  12616. }
  12617. }
  12618. json_object_put(tmpChargingProfile);
  12619. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12620. {
  12621. if(ChargingProfileAdded == FALSE)
  12622. {
  12623. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12624. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12625. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12626. ChargingProfileAdded = TRUE;
  12627. }
  12628. }
  12629. else
  12630. {
  12631. fprintf(outfile,"%s\n",dataLine);
  12632. if(ChargingProfileAdded == FALSE)
  12633. {
  12634. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12635. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12636. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12637. ChargingProfileAdded = TRUE;
  12638. }
  12639. }
  12640. } // end of while loop
  12641. fclose(infile);
  12642. fclose(outfile);
  12643. sprintf(rmFileCmd,"rm -f %s",filename);
  12644. system(rmFileCmd);
  12645. rename(tempfile, filename);
  12646. }
  12647. }
  12648. sleep(1);
  12649. result = TRUE;
  12650. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12651. }
  12652. end:
  12653. json_object_put(SetChargingProfile);
  12654. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12655. {
  12656. if(SetProfileReq.ConnectorId == 0)
  12657. {
  12658. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12659. {
  12660. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  12661. }
  12662. }
  12663. else
  12664. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12665. }
  12666. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12667. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12668. return result;
  12669. }
  12670. int handleTriggerMessageRequest(char *uuid, char *payload)
  12671. {
  12672. mtrace();
  12673. int result = FAIL;
  12674. int connectorIdIsNULL = FALSE;
  12675. int connectorIdInt =0;
  12676. char sstr[40]={0},sstrtemp[100]={ 0 };
  12677. char requestedMessagestr[40]={0};
  12678. char comfirmstr[20]={0};
  12679. int c = 0;
  12680. char *loc;
  12681. DEBUG_INFO("handleTriggerMessageRequest\n");
  12682. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12683. strcpy(sstrtemp, stringtrimspace(payload));
  12684. c = 0;
  12685. loc = strstr(sstrtemp, "requestedMessage");
  12686. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12687. {
  12688. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12689. c++;
  12690. }
  12691. sstr[c] = '\0';
  12692. strcpy(requestedMessagestr, sstr);
  12693. c = 0;
  12694. loc = strstr(sstrtemp, "connectorId");
  12695. if(loc == NULL)
  12696. {
  12697. connectorIdIsNULL = TRUE;
  12698. }
  12699. else
  12700. {
  12701. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12702. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12703. {
  12704. sstr[c] = loc[strlen("connectorId")+2+c];
  12705. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12706. c++;
  12707. }
  12708. sstr[c] = '\0';
  12709. connectorIdInt = atoi(sstr);
  12710. }
  12711. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12712. {
  12713. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12714. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12715. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12716. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12717. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12718. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12719. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12720. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12721. {
  12722. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12723. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12724. return TRUE;
  12725. }
  12726. else
  12727. {
  12728. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12729. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12730. }
  12731. }
  12732. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12733. {
  12734. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12735. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12736. return TRUE;
  12737. }
  12738. //==========================
  12739. // Trigger message
  12740. //==========================
  12741. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12742. {
  12743. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12744. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12745. {
  12746. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12747. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12748. }
  12749. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12750. }
  12751. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12752. {
  12753. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  12754. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12755. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12756. }
  12757. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12758. {
  12759. //sendBootNotificationRequest();
  12760. server_sign = FALSE;
  12761. }
  12762. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12763. {
  12764. refreshStartTimer(&clientTime.Heartbeat);
  12765. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  12766. }
  12767. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12768. {
  12769. if(connectorIdIsNULL == FALSE)
  12770. {
  12771. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12772. {
  12773. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12774. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12775. }
  12776. }
  12777. else
  12778. {
  12779. for(int idx=0;idx< gunTotalNumber;idx++)
  12780. {
  12781. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12782. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12783. }
  12784. }
  12785. }
  12786. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12787. {
  12788. if(connectorIdIsNULL == FALSE)
  12789. {
  12790. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  12791. {
  12792. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12793. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  12794. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12795. }
  12796. }
  12797. else
  12798. {
  12799. for(int idx=0;idx< gunTotalNumber;idx++)
  12800. {
  12801. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  12802. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12803. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12804. }
  12805. }
  12806. }
  12807. return result;
  12808. }
  12809. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12810. {
  12811. mtrace();
  12812. int result = FAIL;
  12813. int connectorIdInt =0;
  12814. char comfirmstr[20]={0};
  12815. int tempIndex = 0;
  12816. json_object *UnlockConnector;
  12817. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12818. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12819. UnlockConnector = json_tokener_parse(payload);
  12820. if(!is_error(UnlockConnector))
  12821. {
  12822. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12823. {
  12824. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12825. }
  12826. }
  12827. json_object_put(UnlockConnector);
  12828. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12829. if(gunTotalNumber == 0)
  12830. {
  12831. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12832. goto end;
  12833. }
  12834. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12835. {
  12836. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12837. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12838. goto end;
  12839. }
  12840. else
  12841. {
  12842. //check Transaction active
  12843. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12844. {
  12845. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12846. {
  12847. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12848. }
  12849. else
  12850. {
  12851. tempIndex = connectorIdInt -1;
  12852. }
  12853. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12854. {
  12855. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12856. {
  12857. //stop Transaction
  12858. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12859. }
  12860. }
  12861. }
  12862. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12863. {
  12864. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12865. {
  12866. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12867. }
  12868. else
  12869. {
  12870. tempIndex = connectorIdInt -1;
  12871. }
  12872. for (int index = 0; index < CCS_QUANTITY; index++)
  12873. {
  12874. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12875. {
  12876. //stop Transaction
  12877. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12878. }
  12879. }
  12880. }
  12881. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12882. {
  12883. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12884. {
  12885. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12886. }
  12887. else
  12888. {
  12889. tempIndex = connectorIdInt -1;
  12890. }
  12891. for (int index = 0; index < GB_QUANTITY; index++)
  12892. {
  12893. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12894. {
  12895. //stop Transaction
  12896. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12897. }
  12898. }
  12899. }
  12900. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12901. {
  12902. tempIndex = connectorIdInt -1;
  12903. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12904. {
  12905. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12906. {
  12907. //stop Transaction
  12908. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12909. }
  12910. }
  12911. }
  12912. else
  12913. {
  12914. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12915. {
  12916. tempIndex = 2;
  12917. }
  12918. else
  12919. {
  12920. tempIndex = connectorIdInt-1;
  12921. }
  12922. for (int index = 0; index < AC_QUANTITY; index++)
  12923. {
  12924. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12925. {
  12926. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12927. }
  12928. }
  12929. }
  12930. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12931. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  12932. result = TRUE;
  12933. return result;
  12934. }
  12935. end:
  12936. //json_object_put(obj); --- remove temporally
  12937. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12938. return result;
  12939. }
  12940. static char UpdateFirmwarepayloadData[300]={0};
  12941. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12942. {
  12943. mtrace();
  12944. int result = FAIL;
  12945. pthread_t t;
  12946. sendUpdateFirmwareConfirmation(uuid);
  12947. memset(UpdateFirmwarepayloadData, 0, 300);
  12948. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12949. if(!interLock.isUpdateFirmwareGoing)
  12950. {
  12951. interLock.isUpdateFirmwareGoing = 1;
  12952. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12953. sleep(1);
  12954. }
  12955. else
  12956. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12957. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  12958. return result;
  12959. }
  12960. void *UpdateFirmwareProcess(void *data)
  12961. {
  12962. pthread_detach(pthread_self());
  12963. mtrace();
  12964. int retriesInt =0, retryIntervalInt=0;
  12965. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  12966. int port=0;
  12967. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  12968. int isSuccess = 0;
  12969. char ftpbuf[1024];
  12970. char temp[1024];
  12971. char * pch;
  12972. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12973. json_object *UpdateFirmware;
  12974. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12975. if(!is_error(UpdateFirmware))
  12976. {
  12977. // Required data
  12978. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12979. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12980. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12981. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12982. // Optional data
  12983. if(json_object_object_get(UpdateFirmware, "retries"))
  12984. {
  12985. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12986. }
  12987. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12988. {
  12989. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12990. }
  12991. }
  12992. json_object_put(UpdateFirmware);
  12993. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12994. memset(path, 0, ARRAY_SIZE(path));
  12995. // Wait retrieveData
  12996. if(strlen(retrieveDatestr) > 10)
  12997. {
  12998. do
  12999. {
  13000. sleep(1);
  13001. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13002. }
  13003. // Ready to download
  13004. system("rm -f /mnt/*");
  13005. if(strncmp(locationstr,"http", 4) == 0)
  13006. {
  13007. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13008. sprintf(ftppath,"/%s", path);
  13009. DEBUG_INFO("locationstr: %s\n", locationstr);
  13010. DEBUG_INFO("protocol: %s\n",protocol);
  13011. DEBUG_INFO("host: %s\n",host);
  13012. DEBUG_INFO("path: %s\n",path);
  13013. DEBUG_INFO("ftppath: %s\n",ftppath);
  13014. int ftppathlen=strlen(ftppath);
  13015. int i=1;
  13016. char filenametemp[50];
  13017. while(i < ftppathlen)
  13018. {
  13019. int len=ftppathlen-i;
  13020. if(ftppath[len]== 47) // '/' ascll code: 47
  13021. {
  13022. DEBUG_INFO("compare '/' all right\n");
  13023. break;
  13024. }
  13025. i=i+1;
  13026. }
  13027. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13028. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13029. filenametemp[i+1] = 0;
  13030. do
  13031. {
  13032. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13033. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13034. sleep(1);
  13035. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13036. if(!isSuccess)
  13037. {
  13038. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13039. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13040. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13041. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13042. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13043. }
  13044. else
  13045. {
  13046. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13047. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13048. }
  13049. retriesInt--;
  13050. }while((isSuccess == 0)&&(retriesInt >= 0));
  13051. }
  13052. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13053. {
  13054. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13055. memset(temp, 0, ARRAY_SIZE(temp));
  13056. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13057. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13058. int ftppathlen=strlen(ftpbuf);
  13059. int i=1;
  13060. char filenametemp[50];
  13061. while(i < ftppathlen)
  13062. {
  13063. int len=ftppathlen-i;
  13064. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13065. {
  13066. DEBUG_INFO(" compare '/' all right\n");
  13067. break;
  13068. }
  13069. i=i+1;
  13070. }
  13071. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13072. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13073. filenametemp[i+1] = 0;
  13074. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13075. pch=strchr(temp,'@');
  13076. if(pch==NULL)
  13077. {
  13078. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13079. protocol, host, &port, path);
  13080. strcpy(user,"anonymous");
  13081. strcpy(password,"");
  13082. }
  13083. else
  13084. {
  13085. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13086. protocol, user, password, host, &port, path);
  13087. }
  13088. sscanf(host,"%[^/]%s",host1, path1);
  13089. sprintf(ftppath,"%s", path1);
  13090. //DEBUG_INFO("protocol =%s\n",protocol);
  13091. //DEBUG_INFO("user =%s\n",user);
  13092. //DEBUG_INFO("password =%s\n",password);
  13093. //DEBUG_INFO("host1 =%s\n",host1);
  13094. //DEBUG_INFO("port =%d\n",port);
  13095. //DEBUG_INFO("path1 =%s\n",path1);
  13096. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13097. //ftpFile(host, user, password, port, ftppath, fname);
  13098. //download firmware pthred
  13099. if(port == 0)
  13100. {
  13101. port = 21;
  13102. }
  13103. do
  13104. {
  13105. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13106. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13107. sleep(1);
  13108. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13109. if(!isSuccess)
  13110. {
  13111. //BulldogUtil.sleepMs(interval*1000);
  13112. DEBUG_INFO("Update firmware request and download file fail.\n");
  13113. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13114. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13115. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13116. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13117. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13118. }
  13119. else
  13120. {
  13121. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13122. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13123. }
  13124. retriesInt--;
  13125. }while((!isSuccess)&&(retriesInt >= 0));
  13126. }
  13127. else
  13128. {
  13129. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13130. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13131. sleep(1);
  13132. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13133. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13134. }
  13135. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13136. interLock.isUpdateFirmwareGoing = 0;
  13137. pthread_exit(NULL);
  13138. }
  13139. int handleCertificateSignedRequest(char *uuid, char *payload)
  13140. {
  13141. mtrace();
  13142. int result = PASS;
  13143. json_object *CertificateSigned;
  13144. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13145. CertificateSigned = json_tokener_parse(payload);
  13146. if(!is_error(CertificateSigned))
  13147. {
  13148. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13149. }
  13150. json_object_put(CertificateSigned);
  13151. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  13152. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13153. fclose(fp);
  13154. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13155. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13156. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13157. sendCertificateSignedConfirmation(uuid);
  13158. return result;
  13159. }
  13160. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13161. {
  13162. mtrace();
  13163. int result = PASS;
  13164. json_object *DeleteCertificate;
  13165. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13166. DeleteCertificate = json_tokener_parse(payload);
  13167. if(!is_error(DeleteCertificate))
  13168. {
  13169. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13170. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13171. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13172. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13173. }
  13174. json_object_put(DeleteCertificate);
  13175. /*
  13176. * TODO: Delete certificateSigned process
  13177. */
  13178. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  13179. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13180. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  13181. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  13182. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  13183. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  13184. sendDeleteCertificateConfirmation(uuid);
  13185. return result;
  13186. }
  13187. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13188. {
  13189. mtrace();
  13190. int result = PASS;
  13191. json_object *ExtendedTriggerMessage;
  13192. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13193. ExtendedTriggerMessage = json_tokener_parse(payload);
  13194. if(!is_error(ExtendedTriggerMessage))
  13195. {
  13196. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13197. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13198. {
  13199. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13200. }
  13201. else
  13202. {
  13203. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  13204. }
  13205. }
  13206. json_object_put(ExtendedTriggerMessage);
  13207. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  13208. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  13209. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13210. {
  13211. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13212. }
  13213. else
  13214. {
  13215. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13216. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13217. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13218. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13219. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13220. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13221. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13222. {
  13223. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13224. }
  13225. else
  13226. {
  13227. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13228. }
  13229. }
  13230. sendExtendedTriggerMessageConfirmation(uuid);
  13231. //==========================
  13232. // Trigger message
  13233. //==========================
  13234. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13235. {
  13236. //sendBootNotificationRequest();
  13237. server_sign = FALSE;
  13238. }
  13239. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13240. {
  13241. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13242. }
  13243. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13244. {
  13245. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13246. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13247. {
  13248. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13249. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13250. }
  13251. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13252. }
  13253. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13254. {
  13255. refreshStartTimer(&clientTime.Heartbeat);
  13256. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13257. }
  13258. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13259. {
  13260. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13261. {
  13262. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13263. }
  13264. else
  13265. {
  13266. for(int idx=0;idx< gunTotalNumber;idx++)
  13267. {
  13268. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13269. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13270. }
  13271. }
  13272. }
  13273. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13274. {
  13275. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  13276. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13277. {
  13278. 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\" &");
  13279. }
  13280. }
  13281. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13282. {
  13283. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13284. {
  13285. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13286. }
  13287. else
  13288. {
  13289. for(int idx=0;idx< gunTotalNumber;idx++)
  13290. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13291. }
  13292. }
  13293. return result;
  13294. }
  13295. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13296. {
  13297. mtrace();
  13298. int result = PASS;
  13299. json_object *GetInstalledCertificateIds;
  13300. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13301. GetInstalledCertificateIds = json_tokener_parse(payload);
  13302. if(!is_error(GetInstalledCertificateIds))
  13303. {
  13304. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13305. }
  13306. json_object_put(GetInstalledCertificateIds);
  13307. /*
  13308. * TODO: Return installed certificate process
  13309. */
  13310. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13311. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  13312. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13313. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13314. sendGetInstalledCertificateIdsConfirmation(uuid);
  13315. return result;
  13316. }
  13317. int handleGetLogRequest(char *uuid, char *payload)
  13318. {
  13319. mtrace();
  13320. int result = PASS;
  13321. json_object *GetLog;
  13322. DEBUG_INFO("handleGetLogRequest...\n");
  13323. GetLog = json_tokener_parse(payload);
  13324. if(!is_error(GetLog))
  13325. {
  13326. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13327. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13328. if(json_object_object_get(GetLog, "retries") != NULL)
  13329. {
  13330. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13331. }
  13332. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13333. {
  13334. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13335. }
  13336. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13337. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13338. {
  13339. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13340. }
  13341. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13342. {
  13343. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13344. }
  13345. }
  13346. json_object_put(GetLog);
  13347. /*
  13348. * TODO: Upload log process
  13349. */
  13350. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  13351. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  13352. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  13353. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  13354. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  13355. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  13356. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  13357. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  13358. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  13359. sendGetLogConfirmation(uuid);
  13360. return result;
  13361. }
  13362. int handleInstallCertificateRequest(char *uuid, char *payload)
  13363. {
  13364. mtrace();
  13365. int result = PASS;
  13366. json_object *InstallCertificate;
  13367. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13368. InstallCertificate = json_tokener_parse(payload);
  13369. if(!is_error(InstallCertificate))
  13370. {
  13371. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13372. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13373. /*
  13374. * TODO: Install certificate process
  13375. */
  13376. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  13377. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  13378. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  13379. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  13380. sendInstallCertificateConfirmation(uuid);
  13381. }
  13382. json_object_put(InstallCertificate);
  13383. return result;
  13384. }
  13385. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13386. {
  13387. mtrace();
  13388. int result = PASS;
  13389. json_object *SignedUpdateFirmware;
  13390. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13391. SignedUpdateFirmware = json_tokener_parse(payload);
  13392. if(!is_error(SignedUpdateFirmware))
  13393. {
  13394. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13395. {
  13396. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13397. }
  13398. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13399. {
  13400. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13401. }
  13402. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13403. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13404. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13405. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13406. {
  13407. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13408. }
  13409. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13410. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13411. }
  13412. json_object_put(SignedUpdateFirmware);
  13413. /*
  13414. * TODO: Upgrade firmware process
  13415. */
  13416. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13417. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  13418. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  13419. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  13420. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  13421. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  13422. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  13423. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  13424. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  13425. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  13426. sendInstallCertificateConfirmation(uuid);
  13427. return result;
  13428. }
  13429. int handleUnknownRequest(char *uuid, char *payload)
  13430. {
  13431. mtrace();
  13432. int result = PASS;
  13433. DEBUG_INFO("handleUnknownRequest...\n");
  13434. sendUnknownConfirmation(uuid);
  13435. result = PASS;
  13436. return result;
  13437. }
  13438. //==========================================
  13439. // Handle server response routine
  13440. //==========================================
  13441. void handleAuthorizeResponse(char *payload, int gun_index)
  13442. {
  13443. mtrace();
  13444. char expiryDatestr[30]={0};
  13445. char parentIdTagstr[20]={0};
  13446. char statusstr[20]={0};
  13447. int expiryDateISNULL=FALSE;
  13448. int parentIdTagISNULL=FALSE;
  13449. DEBUG_INFO("handleAuthorizeResponse...\n");
  13450. json_object *Authorize;
  13451. Authorize = json_tokener_parse(payload);
  13452. if(!is_error(Authorize))
  13453. {
  13454. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13455. {
  13456. // Required data
  13457. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13458. // Optional data
  13459. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13460. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13461. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13462. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13463. }
  13464. }
  13465. json_object_put(Authorize);
  13466. if(expiryDateISNULL == FALSE)
  13467. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13468. if(parentIdTagISNULL == FALSE)
  13469. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13470. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  13471. //Update idTag information to authorization cache if supproted
  13472. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13473. {
  13474. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13475. }
  13476. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  13477. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13478. authorizeRetryTimes = 0;
  13479. }
  13480. void handleBootNotificationResponse(char *payload, int gun_index)
  13481. {
  13482. mtrace();
  13483. char statusStr[12]={0};
  13484. char currentTimeStr[30]={0};
  13485. int intervalInt = 0;
  13486. DEBUG_INFO("handleBootNotificationResponse...\n");
  13487. json_object *BootNotification;
  13488. BootNotification = json_tokener_parse(payload);
  13489. if(!is_error(BootNotification))
  13490. {
  13491. // Required data
  13492. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13493. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13494. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13495. }
  13496. json_object_put(BootNotification);
  13497. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13498. BootNotificationInterval = intervalInt;
  13499. //write back to ShmOCPP16Data->BootNotification
  13500. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  13501. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13502. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  13503. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13504. {
  13505. if((intervalInt == 0) || (intervalInt >= 10))
  13506. {
  13507. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13508. HeartBeatWaitTime = intervalInt;
  13509. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13510. }
  13511. server_sign = TRUE;
  13512. server_pending =FALSE;
  13513. }
  13514. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13515. {
  13516. server_pending = TRUE;
  13517. }
  13518. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  13519. srand(time(NULL));
  13520. refreshStartTimer(&clientTime.Heartbeat);
  13521. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13522. SetOcppConnStatus(TRUE);
  13523. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  13524. }
  13525. void handleDataTransferResponse(char *payload, int gun_index)
  13526. {
  13527. json_object *DataTransfer = json_tokener_parse(payload);
  13528. char status[32];
  13529. if(!is_error(DataTransfer))
  13530. {
  13531. // Required data
  13532. sprintf(status, "%s", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13533. DEBUG_INFO("Status: %s.\n", status);
  13534. // Optional data
  13535. if(json_object_object_get(DataTransfer, "data") != NULL)
  13536. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13537. // YES call_reader message confirm
  13538. if(ShmOCPP16Data->YesCustomData.CallReaderReq == 1)
  13539. {
  13540. sprintf((char *)ShmOCPP16Data->YesCustomData.CallReaderStatus, "%s",status);
  13541. ShmOCPP16Data->YesCustomData.CallReaderConf = 1;
  13542. ShmOCPP16Data->YesCustomData.CallReaderReq = 0;
  13543. DEBUG_INFO("Report CallReader status to CSU: %s\n",ShmOCPP16Data->YesCustomData.CallReaderStatus);
  13544. }
  13545. }
  13546. }
  13547. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13548. {
  13549. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13550. //struct json_object *obj;
  13551. // obj = json_tokener_parse(payload);
  13552. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13553. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13554. //No fields are defined.
  13555. }
  13556. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13557. {
  13558. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13559. //struct json_object *obj;
  13560. // obj = json_tokener_parse(payload);
  13561. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13562. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13563. //No fields are defined.
  13564. }
  13565. void handleHeartbeatResponse(char *payload, int gun_index)
  13566. {
  13567. mtrace();
  13568. DEBUG_INFO("handleHeartbeatResponse...\n");
  13569. json_object *Heartbeat;
  13570. Heartbeat = json_tokener_parse(payload);
  13571. if(!is_error(Heartbeat))
  13572. {
  13573. // Required data
  13574. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13575. }
  13576. json_object_put(Heartbeat);
  13577. if(FirstHeartBeat == 0)
  13578. {
  13579. FirstHeartBeat = 1;
  13580. DEBUG_INFO("FirstHeartBeat \n");
  13581. }
  13582. HeartBeatWithNOResponse = 0;
  13583. refreshStartTimer(&clientTime.Heartbeat);
  13584. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  13585. }
  13586. void handleMeterValuesResponse(char *payload, int gun_index)
  13587. {
  13588. mtrace();
  13589. DEBUG_INFO("handleMeterValuesResponse...\n");
  13590. isQueueSendable = 1;
  13591. }
  13592. void handleStartTransactionResponse(char *payload, int gun_index)
  13593. {
  13594. mtrace();
  13595. //int transactionIdInt = 0;
  13596. FILE *outfile;
  13597. char data[100]={0};
  13598. DEBUG_INFO("handleStartTransactionResponse...\n");
  13599. json_object *StartTransaction;
  13600. StartTransaction = json_tokener_parse(payload);
  13601. if(!is_error(StartTransaction))
  13602. {
  13603. // Required data
  13604. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13605. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13606. // Optional data
  13607. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13608. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13609. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13610. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13611. }
  13612. json_object_put(StartTransaction);
  13613. isQueueSendable = 1;
  13614. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13615. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13616. //-----------Start : write to the Queue TransactionId file -----------------//
  13617. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  13618. {}
  13619. else
  13620. {
  13621. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  13622. if(log == NULL)
  13623. {
  13624. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13625. return ;
  13626. }
  13627. else
  13628. {
  13629. fclose(log);
  13630. }
  13631. }
  13632. // open file for writing
  13633. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13634. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  13635. {
  13636. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  13637. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13638. fputs(data, outfile);
  13639. fclose (outfile);
  13640. }
  13641. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13642. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13643. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13644. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  13645. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13646. }
  13647. void handleStatusNotificationResponse(char *payload, int gun_index)
  13648. {
  13649. mtrace();
  13650. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13651. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13652. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13653. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13654. }
  13655. void handleStopTransactionnResponse(char *payload, int gun_index)
  13656. {
  13657. mtrace();
  13658. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13659. json_object *StopTransaction;
  13660. StopTransaction = json_tokener_parse(payload);
  13661. if(!is_error(StopTransaction))
  13662. {
  13663. // Optional data
  13664. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13665. {
  13666. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13667. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13668. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13669. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13670. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13671. }
  13672. }
  13673. json_object_put(StopTransaction);
  13674. isQueueSendable = 1;
  13675. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13676. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13677. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13678. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13679. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13680. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13681. }
  13682. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13683. {
  13684. mtrace();
  13685. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13686. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  13687. }
  13688. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13689. {
  13690. mtrace();
  13691. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13692. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  13693. }
  13694. void handleSignCertificateResponse(char *payload, int gun_index)
  13695. {
  13696. mtrace();
  13697. DEBUG_INFO("handleSignCertificateResponse...\n");
  13698. json_object *SignCertificate;
  13699. SignCertificate = json_tokener_parse(payload);
  13700. if(!is_error(SignCertificate))
  13701. {
  13702. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13703. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  13704. }
  13705. json_object_put(SignCertificate);
  13706. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  13707. }
  13708. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13709. {
  13710. mtrace();
  13711. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13712. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13713. }
  13714. //==========================================
  13715. // Handle Error routine
  13716. //==========================================
  13717. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13718. {
  13719. mtrace();
  13720. #ifdef SystemLogMessage
  13721. DEBUG_INFO("errorCode: %s\n", errorCode);
  13722. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13723. DEBUG_INFO("errorDetails: %s\n", payload);
  13724. #endif
  13725. }
  13726. //===============================================
  13727. // Common routine
  13728. //===============================================
  13729. int initialConfigurationTable(void)
  13730. {
  13731. //clock_t start_t, end_t, total_t;
  13732. FILE *fp;
  13733. FILE *outfile;
  13734. char str[512]={0};
  13735. char sstr[256]={0};
  13736. int c = 0;
  13737. char *loc;
  13738. int confVersion = 11;
  13739. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13740. //start_t = clock();
  13741. //printf("Starting of the program, start_t = %ld\n", start_t);
  13742. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13743. // Check configuration file size is correct
  13744. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  13745. {
  13746. struct stat st;
  13747. stat("/Storage/OCPP/OCPPConfiguration", &st);
  13748. if(st.st_size < 3100)
  13749. {
  13750. system("rm -f /Storage/OCPP/OCPPConfiguration");
  13751. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13752. }
  13753. }
  13754. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  13755. {
  13756. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13757. if(outfile == NULL)
  13758. {
  13759. DEBUG_INFO("Error opening file\n");
  13760. return FALSE;
  13761. }
  13762. /*Core Profile*/
  13763. //AllowOfflineTxForUnknownId
  13764. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13767. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13768. //AuthorizationCacheEnabled
  13769. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13772. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13773. //AuthorizeRemoteTxRequests
  13774. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13776. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13778. //BlinkRepeat
  13779. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13782. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13783. //ClockAlignedDataInterval
  13784. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13787. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13788. //ConnectionTimeOut
  13789. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13791. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13792. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13793. //GetConfigurationMaxKeys
  13794. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13796. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13797. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13798. // HeartbeatInterval
  13799. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13802. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13803. // LightIntensity
  13804. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13805. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13807. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13808. // LocalAuthorizeOffline
  13809. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13812. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13813. // LocalPreAuthorize
  13814. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13817. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13818. // MaxEnergyOnInvalidId
  13819. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13822. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13823. // MeterValuesAlignedData
  13824. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13826. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13827. 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" );
  13828. else
  13829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13830. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13831. // MeterValuesAlignedDataMaxLength
  13832. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13834. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13835. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13836. else
  13837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13838. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13839. // MeterValuesSampledData
  13840. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13842. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13843. 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" );
  13844. else
  13845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13847. // MeterValuesSampledDataMaxLength
  13848. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13850. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13852. else
  13853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13855. // MeterValueSampleInterval
  13856. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13859. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13860. // MinimumStatusDuration
  13861. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13864. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13865. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13866. // NumberOfConnectors
  13867. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13869. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13870. {
  13871. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13872. }
  13873. else
  13874. {
  13875. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13876. }
  13877. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13878. // ResetRetries
  13879. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13883. // ConnectorPhaseRotation
  13884. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13885. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13887. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13888. // ConnectorPhaseRotationMaxLength
  13889. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13890. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13892. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13893. // StopTransactionOnEVSideDisconnect
  13894. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13896. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13897. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13898. // StopTransactionOnInvalidId
  13899. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13902. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13903. // StopTxnAlignedData
  13904. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13905. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13907. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13908. // StopTxnAlignedDataMaxLength
  13909. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13910. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13912. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13913. // StopTxnSampledData
  13914. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13916. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13918. else
  13919. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13920. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13921. // StopTxnSampledDataMaxLength
  13922. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13924. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13925. {
  13926. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13927. }
  13928. else
  13929. {
  13930. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13931. }
  13932. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13933. // SupportedFeatureProfiles
  13934. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13937. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13938. // SupportedFeatureProfilesMaxLength
  13939. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13940. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13942. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13943. // TransactionMessageAttempts
  13944. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13945. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13946. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13947. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13948. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13949. // TransactionMessageRetryInterval
  13950. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13952. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13953. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13954. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13955. // UnlockConnectorOnEVSideDisconnect
  13956. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13959. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13960. // WebSocketPingInterval
  13961. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13964. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13965. // QueueOffLineMeterValues
  13966. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13967. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13968. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13969. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13970. // AuthorizationKey
  13971. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  13974. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13975. // SecurityProfile
  13976. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13978. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  13979. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13980. // DefaultPrice
  13981. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13983. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13984. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13985. // CustomDisplayCostAndPrice
  13986. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13987. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13988. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13989. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13990. // CustomIdleFeeAfterStop
  13991. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13994. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13995. // TimeOffset
  13996. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13997. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  13999. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14000. // NextTimeOffsetTransitionDateTime
  14001. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14002. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14003. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  14004. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14005. // TimeOffsetNextTransition
  14006. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14008. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  14009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14010. // SystemUptimeSec
  14011. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14012. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14014. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14015. // FreeVend
  14016. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14017. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "Free-FreeVend");
  14018. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14019. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14020. // OcppServer
  14021. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14023. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14024. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14025. // MaintainServer
  14026. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14028. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  14029. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14030. // Configuration Version
  14031. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  14032. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14033. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  14034. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14035. //* Local Auth List Management Profile*/
  14036. #if 0
  14037. //For OCTT Test Case
  14038. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  14040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14041. #endif
  14042. #if 1
  14043. //LocalAuthListEnabled
  14044. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14045. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14046. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14047. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14048. #endif
  14049. //LocalAuthListMaxLength
  14050. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  14053. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14054. //SendLocalListMaxLength
  14055. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14058. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14059. //ReserveConnectorZeroSupported
  14060. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14063. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14064. //* Smart Charging Profile */
  14065. //ChargeProfileMaxStackLevel
  14066. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14067. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14069. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14070. // ChargingScheduleAllowedChargingRateUnit
  14071. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  14074. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14075. // ChargingScheduleMaxPeriods
  14076. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14079. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14080. // ConnectorSwitch3to1PhaseSupported
  14081. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14084. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14085. // MaxChargingProfilesInstalled
  14086. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14089. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14090. fclose(outfile);
  14091. }
  14092. else
  14093. {
  14094. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  14095. char keystr[60]={0};
  14096. char readonlystr[10]={0};
  14097. char valuestr[256]={0};
  14098. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  14099. if(fp == NULL) {
  14100. DEBUG_INFO("Error opening file");
  14101. return FALSE;
  14102. }
  14103. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14104. {
  14105. //DEBUG_INFO("Get Configuration \n");
  14106. if(strlen(str) > 0)
  14107. {
  14108. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14109. //*************************key*********************************/
  14110. if(strstr(str, "key") != NULL)
  14111. {
  14112. loc = strstr(str, "key");
  14113. c = 0;
  14114. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14115. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14116. {
  14117. sstr[c] = loc[strlen("key")+3+c];
  14118. c++;
  14119. }
  14120. sstr[c] = '\0';
  14121. strcpy(keystr,sstr);
  14122. }
  14123. //*************************readonly*********************************/
  14124. if(strstr(str, "readonly") != NULL)
  14125. {
  14126. loc = strstr(str, "readonly");
  14127. c = 0;
  14128. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14129. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14130. {
  14131. sstr[c] = loc[strlen("readonly")+2+c];
  14132. c++;
  14133. }
  14134. sstr[c] = '\0';
  14135. strcpy(readonlystr,sstr);
  14136. }
  14137. //*************************value*********************************/
  14138. if(strstr(str, "value") != NULL)
  14139. {
  14140. loc = strstr(str, "value");
  14141. c = 0;
  14142. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14143. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14144. {
  14145. sstr[c] = loc[strlen("value")+3+c];
  14146. c++;
  14147. }
  14148. sstr[c] = '\0';
  14149. strcpy(valuestr,sstr);
  14150. }
  14151. // DEBUG_INFO("keystr=%s\n",keystr);
  14152. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14153. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14154. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14155. {
  14156. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14157. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14158. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14159. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14160. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14161. }
  14162. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14163. {
  14164. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14165. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14166. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14167. }
  14168. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14169. {
  14170. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14171. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14172. }
  14173. if(strcmp(keystr, "BlinkRepeat") == 0)
  14174. {
  14175. //Charger.BlinkRepeat = Integer.parseInt(value);
  14176. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14177. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14178. }
  14179. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14180. {
  14181. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14182. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14183. }
  14184. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14185. {
  14186. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14187. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14188. }
  14189. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14190. {
  14191. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14192. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14193. }
  14194. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14195. {
  14196. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14197. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14198. HeartBeatWaitTime = atoi(valuestr);
  14199. }
  14200. if(strcmp(keystr, "LightIntensity") == 0)
  14201. {
  14202. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14204. }
  14205. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14206. {
  14207. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14208. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14209. }
  14210. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14211. {
  14212. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14213. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14214. }
  14215. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14216. {
  14217. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14218. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14219. }
  14220. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14221. {
  14222. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14223. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14224. }
  14225. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14226. {
  14227. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14228. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14229. }
  14230. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14231. {
  14232. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14233. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14234. }
  14235. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14236. {
  14237. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14238. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14239. }
  14240. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14241. {
  14242. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14243. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14244. }
  14245. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14246. {
  14247. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14248. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14249. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14250. }
  14251. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14252. {
  14253. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14254. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14255. }
  14256. if(strcmp(keystr, "ResetRetries") == 0)
  14257. {
  14258. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14259. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14260. }
  14261. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14262. {
  14263. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14264. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14265. }
  14266. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14267. {
  14268. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14269. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14270. }
  14271. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14272. {
  14273. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14274. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14275. }
  14276. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14277. {
  14278. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14279. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14280. }
  14281. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14282. {
  14283. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14284. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14285. }
  14286. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14287. {
  14288. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14289. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14290. }
  14291. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14292. {
  14293. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14294. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14295. }
  14296. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14297. {
  14298. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14299. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14300. }
  14301. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14302. {
  14303. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14304. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14305. }
  14306. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14307. {
  14308. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14309. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14310. }
  14311. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14312. {
  14313. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14314. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14315. TransactionMessageAttemptsValue = atoi(valuestr);
  14316. }
  14317. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14318. {
  14319. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14320. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14321. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14322. }
  14323. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14324. {
  14325. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14326. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14327. }
  14328. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14329. {
  14330. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14331. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14332. }
  14333. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14334. {
  14335. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14336. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14337. }
  14338. if(strcmp(keystr, "AuthorizationKey") == 0)
  14339. {
  14340. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14341. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14342. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14343. }
  14344. if(strcmp(keystr, "SecurityProfile") == 0)
  14345. {
  14346. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14347. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14348. }
  14349. if(strcmp(keystr, "DefaultPrice") == 0)
  14350. {
  14351. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14352. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14353. }
  14354. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14355. {
  14356. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14357. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14358. }
  14359. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14360. {
  14361. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14362. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14363. }
  14364. if(strcmp(keystr, "TimeOffset") == 0)
  14365. {
  14366. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14367. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  14368. }
  14369. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  14370. {
  14371. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14372. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  14373. }
  14374. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  14375. {
  14376. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14377. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  14378. }
  14379. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14380. {
  14381. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14382. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  14383. }
  14384. if(strcmp(keystr, "FreeVend") == 0)
  14385. {
  14386. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14387. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14388. }
  14389. if(strcmp(keystr, "OcppServer") == 0)
  14390. {
  14391. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14392. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14393. }
  14394. if(strcmp(keystr, "MaintainServer") == 0)
  14395. {
  14396. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14397. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14398. }
  14399. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14400. {
  14401. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14402. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14403. }
  14404. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14405. {
  14406. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14407. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14408. }
  14409. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14410. {
  14411. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14412. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14413. }
  14414. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14415. {
  14416. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14417. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14418. }
  14419. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14420. {
  14421. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14422. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14423. }
  14424. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14425. {
  14426. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14427. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14428. }
  14429. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14430. {
  14431. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14432. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14433. }
  14434. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14435. {
  14436. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14437. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14438. }
  14439. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14440. {
  14441. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14442. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14443. }
  14444. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14445. {
  14446. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14447. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14448. }
  14449. }
  14450. }
  14451. fclose(fp);
  14452. }
  14453. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14454. {
  14455. return PASS;
  14456. }
  14457. else
  14458. {
  14459. return FAIL;
  14460. }
  14461. }
  14462. void StoreConfigurationTable(void)
  14463. {
  14464. FILE *outfile;
  14465. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14466. if(outfile == NULL)
  14467. {
  14468. DEBUG_INFO("Error opening file");
  14469. return ;
  14470. }
  14471. /*Core Profile*/
  14472. //AllowOfflineTxForUnknownId
  14473. /*
  14474. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14475. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14477. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14478. */
  14479. //DEBUG_INFO("data=%s\n",data);
  14480. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14481. //AuthorizationCacheEnabled
  14482. /*
  14483. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14484. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14485. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14486. */
  14487. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14488. //AuthorizeRemoteTxRequests
  14489. /*
  14490. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14491. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14492. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14493. */
  14494. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14495. //BlinkRepeat
  14496. /*
  14497. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14498. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14499. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14500. */
  14501. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14502. //ClockAlignedDataInterval
  14503. /*
  14504. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14505. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14506. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14507. */
  14508. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14509. //ConnectionTimeOut
  14510. /*
  14511. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14512. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14513. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14514. */
  14515. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14516. //GetConfigurationMaxKeys
  14517. /*
  14518. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14520. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14521. */
  14522. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14523. // HeartbeatInterval
  14524. /*
  14525. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14528. */
  14529. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14530. // LightIntensity
  14531. /*
  14532. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14535. */
  14536. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14537. // LocalAuthorizeOffline
  14538. /*
  14539. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14542. */
  14543. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14544. // LocalPreAuthorize
  14545. /*
  14546. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14549. */
  14550. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14551. // MaxEnergyOnInvalidId
  14552. /*
  14553. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14556. */
  14557. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14558. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14559. // MeterValuesAlignedData
  14560. /*
  14561. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14564. */
  14565. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14566. // MeterValuesAlignedDataMaxLength
  14567. /*
  14568. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14571. */
  14572. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14573. // MeterValuesSampledData
  14574. /*
  14575. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14578. */
  14579. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14580. // MeterValuesSampledDataMaxLength
  14581. /*
  14582. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14585. */
  14586. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14587. // MeterValueSampleInterval
  14588. /*
  14589. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14592. */
  14593. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14594. // MinimumStatusDuration
  14595. /*
  14596. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14599. */
  14600. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14601. // NumberOfConnectors
  14602. /*
  14603. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14605. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14606. {
  14607. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14608. }
  14609. else
  14610. {
  14611. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14612. }
  14613. */
  14614. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14615. // ResetRetries
  14616. /*
  14617. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14620. */
  14621. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14622. // ConnectorPhaseRotation
  14623. /*
  14624. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14627. */
  14628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14629. // ConnectorPhaseRotationMaxLength
  14630. /*
  14631. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14634. */
  14635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14636. // StopTransactionOnEVSideDisconnect
  14637. /*
  14638. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14641. */
  14642. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14643. // StopTransactionOnInvalidId
  14644. /*
  14645. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14648. */
  14649. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14650. // StopTxnAlignedData
  14651. /*
  14652. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14655. */
  14656. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14657. // StopTxnAlignedDataMaxLength
  14658. /*
  14659. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14662. */
  14663. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14664. // StopTxnSampledData
  14665. /*
  14666. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14669. */
  14670. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14671. // StopTxnSampledDataMaxLength
  14672. /*
  14673. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14676. */
  14677. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14678. // SupportedFeatureProfiles
  14679. /*
  14680. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14683. */
  14684. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14685. // SupportedFeatureProfilesMaxLength
  14686. /*
  14687. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14690. */
  14691. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14692. // TransactionMessageAttempts
  14693. /*
  14694. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14697. */
  14698. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14699. // TransactionMessageRetryInterval
  14700. /*
  14701. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14704. */
  14705. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14706. // UnlockConnectorOnEVSideDisconnect
  14707. /*
  14708. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14711. */
  14712. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14713. // WebSocketPingInterval
  14714. /*
  14715. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14718. */
  14719. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14720. // QueueOffLineMeterValues
  14721. /*
  14722. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14725. */
  14726. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14727. // AuthorizationKey
  14728. /*
  14729. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14732. */
  14733. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14734. // SecurityProfile
  14735. /*
  14736. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14739. */
  14740. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14741. // DefaultPrice
  14742. /*
  14743. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14746. */
  14747. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14748. // CustomDisplayCostAndPrice
  14749. /*
  14750. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14753. */
  14754. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14755. // CustomIdleFeeAfterStop
  14756. /*
  14757. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14760. */
  14761. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14762. // TimeOffset
  14763. /*
  14764. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  14767. */
  14768. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14769. // NextTimeOffsetTransitionDateTime
  14770. /*
  14771. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  14774. */
  14775. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14776. // TimeOffsetNextTransition
  14777. /*
  14778. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  14781. */
  14782. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14783. // SystemUptimeSec
  14784. /*
  14785. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14788. */
  14789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14790. // FreeVend
  14791. /*
  14792. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14795. */
  14796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14797. // OcppServer
  14798. /*
  14799. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14802. */
  14803. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14804. // MaintainServer
  14805. /*
  14806. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14809. */
  14810. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14811. // ConfigurationVersion
  14812. /*
  14813. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14816. */
  14817. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14818. //* Local Auth List Management Profile*/
  14819. //LocalAuthListEnabled
  14820. /*
  14821. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14824. */
  14825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14826. //LocalAuthListMaxLength
  14827. /*
  14828. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14831. */
  14832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14833. //SendLocalListMaxLength
  14834. /*
  14835. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14838. */
  14839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14840. //ReserveConnectorZeroSupported
  14841. /*
  14842. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14845. */
  14846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14847. //* Smart Charging Profile */
  14848. //ChargeProfileMaxStackLevel
  14849. /*
  14850. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14853. */
  14854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14855. // ChargingScheduleAllowedChargingRateUnit
  14856. /*
  14857. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14860. */
  14861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14862. // ChargingScheduleMaxPeriods
  14863. /*
  14864. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14867. */
  14868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14869. // ConnectorSwitch3to1PhaseSupported
  14870. /*
  14871. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14874. */
  14875. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14876. // MaxChargingProfilesInstalled
  14877. /*
  14878. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14881. */
  14882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14883. fclose(outfile);
  14884. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14885. }
  14886. void getKeyValue(char *keyReq)
  14887. {
  14888. int isEmpty = FALSE;
  14889. int isKnowKey = FALSE;
  14890. DEBUG_INFO("keyReq = %s\n", keyReq);
  14891. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14892. isEmpty = TRUE;
  14893. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14894. {
  14895. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14897. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14898. {
  14899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14900. }
  14901. else
  14902. {
  14903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14904. }
  14905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14906. isKnowKey = TRUE;
  14907. }
  14908. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14909. {
  14910. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14912. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14913. {
  14914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14915. }
  14916. else
  14917. {
  14918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14919. }
  14920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14921. isKnowKey = TRUE;
  14922. }
  14923. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14924. {
  14925. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14927. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14928. {
  14929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14930. }
  14931. else
  14932. {
  14933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14934. }
  14935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14936. isKnowKey = TRUE;
  14937. }
  14938. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14939. {
  14940. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14942. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14943. {
  14944. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14945. }
  14946. else
  14947. {
  14948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14949. }
  14950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14951. isKnowKey = TRUE;
  14952. }
  14953. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14954. {
  14955. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14957. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14958. {
  14959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14960. }
  14961. else
  14962. {
  14963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14964. }
  14965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14966. isKnowKey = TRUE;
  14967. }
  14968. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14969. {
  14970. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14972. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14973. {
  14974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14975. }
  14976. else
  14977. {
  14978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14979. }
  14980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14981. isKnowKey = TRUE;
  14982. }
  14983. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14984. {
  14985. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14987. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14988. {
  14989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14990. }
  14991. else
  14992. {
  14993. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14994. }
  14995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14996. isKnowKey = TRUE;
  14997. }
  14998. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14999. {
  15000. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  15001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  15002. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15003. {
  15004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  15005. }
  15006. else
  15007. {
  15008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15009. }
  15010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15011. isKnowKey = TRUE;
  15012. }
  15013. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15014. {
  15015. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15017. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15018. {
  15019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15020. }
  15021. else
  15022. {
  15023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15024. }
  15025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15026. isKnowKey = TRUE;
  15027. }
  15028. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15029. {
  15030. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15032. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15033. {
  15034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15035. }
  15036. else
  15037. {
  15038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15039. }
  15040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15041. isKnowKey = TRUE;
  15042. }
  15043. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15044. {
  15045. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15047. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15048. {
  15049. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15050. }
  15051. else
  15052. {
  15053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15054. }
  15055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15056. isKnowKey = TRUE;
  15057. }
  15058. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15059. {
  15060. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15062. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15063. {
  15064. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15065. }
  15066. else
  15067. {
  15068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15069. }
  15070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15071. isKnowKey = TRUE;
  15072. }
  15073. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15074. {
  15075. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15077. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15078. {
  15079. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15080. }
  15081. else
  15082. {
  15083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15084. }
  15085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15086. isKnowKey = TRUE;
  15087. }
  15088. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15089. {
  15090. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15092. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15093. {
  15094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15095. }
  15096. else
  15097. {
  15098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15099. }
  15100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15101. isKnowKey = TRUE;
  15102. }
  15103. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15104. {
  15105. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15107. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15108. {
  15109. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15110. }
  15111. else
  15112. {
  15113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15114. }
  15115. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15116. isKnowKey = TRUE;
  15117. }
  15118. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15119. {
  15120. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15121. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15122. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15123. {
  15124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15125. }
  15126. else
  15127. {
  15128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15129. }
  15130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15131. isKnowKey = TRUE;
  15132. }
  15133. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15134. {
  15135. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15137. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15138. {
  15139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15140. }
  15141. else
  15142. {
  15143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15144. }
  15145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15146. isKnowKey = TRUE;
  15147. }
  15148. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15149. {
  15150. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15152. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15153. {
  15154. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15155. }
  15156. else
  15157. {
  15158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15159. }
  15160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  15161. isKnowKey = TRUE;
  15162. }
  15163. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15164. {
  15165. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15167. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15168. {
  15169. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15170. }
  15171. else
  15172. {
  15173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15174. }
  15175. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15177. isKnowKey = TRUE;
  15178. }
  15179. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15180. {
  15181. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15183. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15184. {
  15185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15186. }
  15187. else
  15188. {
  15189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15190. }
  15191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15192. isKnowKey = TRUE;
  15193. }
  15194. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15195. {
  15196. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15198. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15199. {
  15200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15201. }
  15202. else
  15203. {
  15204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15205. }
  15206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15207. isKnowKey = TRUE;
  15208. }
  15209. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15210. {
  15211. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15213. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15214. {
  15215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15216. }
  15217. else
  15218. {
  15219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15220. }
  15221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15222. isKnowKey = TRUE;
  15223. }
  15224. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15225. {
  15226. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15227. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15228. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15229. {
  15230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15231. }
  15232. else
  15233. {
  15234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15235. }
  15236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15237. isKnowKey = TRUE;
  15238. }
  15239. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15240. {
  15241. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15243. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15244. {
  15245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15246. }
  15247. else
  15248. {
  15249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15250. }
  15251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15252. isKnowKey = TRUE;
  15253. }
  15254. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15255. {
  15256. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15257. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15258. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15259. {
  15260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15261. }
  15262. else
  15263. {
  15264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15265. }
  15266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15267. isKnowKey = TRUE;
  15268. }
  15269. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15270. {
  15271. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15273. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15274. {
  15275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15276. }
  15277. else
  15278. {
  15279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15280. }
  15281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15282. isKnowKey = TRUE;
  15283. }
  15284. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15285. {
  15286. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15288. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15289. {
  15290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15291. }
  15292. else
  15293. {
  15294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15295. }
  15296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15297. isKnowKey = TRUE;
  15298. }
  15299. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15300. {
  15301. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15303. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15304. {
  15305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15306. }
  15307. else
  15308. {
  15309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15310. }
  15311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15312. isKnowKey = TRUE;
  15313. }
  15314. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15315. {
  15316. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15318. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15319. {
  15320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15321. }
  15322. else
  15323. {
  15324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15325. }
  15326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15327. isKnowKey = TRUE;
  15328. }
  15329. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15330. {
  15331. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15333. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15334. {
  15335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15336. }
  15337. else
  15338. {
  15339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15340. }
  15341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15342. isKnowKey = TRUE;
  15343. }
  15344. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15345. {
  15346. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15348. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15349. {
  15350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15351. }
  15352. else
  15353. {
  15354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15355. }
  15356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15357. isKnowKey = TRUE;
  15358. }
  15359. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15360. {
  15361. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15362. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15363. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15364. {
  15365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15366. }
  15367. else
  15368. {
  15369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15370. }
  15371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15372. isKnowKey = TRUE;
  15373. }
  15374. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15375. {
  15376. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15378. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15379. {
  15380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15381. }
  15382. else
  15383. {
  15384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15385. }
  15386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15387. isKnowKey = TRUE;
  15388. }
  15389. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15390. {
  15391. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15392. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15393. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15394. {
  15395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15396. }
  15397. else
  15398. {
  15399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15400. }
  15401. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15402. isKnowKey = TRUE;
  15403. }
  15404. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15405. {
  15406. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15407. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15408. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15409. {
  15410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15411. }
  15412. else
  15413. {
  15414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15415. }
  15416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15417. isKnowKey = TRUE;
  15418. }
  15419. /*
  15420. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15421. {
  15422. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15424. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15425. {
  15426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15427. }
  15428. else
  15429. {
  15430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15431. }
  15432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15433. isKnowKey = TRUE;
  15434. }*/
  15435. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15436. {
  15437. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15439. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15440. {
  15441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15442. }
  15443. else
  15444. {
  15445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15446. }
  15447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15448. isKnowKey = TRUE;
  15449. }
  15450. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15451. {
  15452. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15454. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15455. {
  15456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15457. }
  15458. else
  15459. {
  15460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15461. }
  15462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15463. isKnowKey = TRUE;
  15464. }
  15465. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15466. {
  15467. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15469. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15470. {
  15471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15472. }
  15473. else
  15474. {
  15475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15476. }
  15477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15478. isKnowKey = TRUE;
  15479. }
  15480. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15481. {
  15482. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15484. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15485. {
  15486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15487. }
  15488. else
  15489. {
  15490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15491. }
  15492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15493. isKnowKey = TRUE;
  15494. }
  15495. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  15496. {
  15497. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  15498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  15499. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15500. {
  15501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  15502. }
  15503. else
  15504. {
  15505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  15506. }
  15507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  15508. isKnowKey = TRUE;
  15509. }
  15510. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  15511. {
  15512. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  15513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  15514. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15515. {
  15516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  15517. }
  15518. else
  15519. {
  15520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  15521. }
  15522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  15523. isKnowKey = TRUE;
  15524. }
  15525. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  15526. {
  15527. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  15528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  15529. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15530. {
  15531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  15532. }
  15533. else
  15534. {
  15535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  15536. }
  15537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  15538. isKnowKey = TRUE;
  15539. }
  15540. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15541. {
  15542. struct sysinfo s_info;
  15543. int error = sysinfo(&s_info);
  15544. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15546. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15547. {
  15548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15549. }
  15550. else
  15551. {
  15552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15553. }
  15554. if(error != 0)
  15555. {
  15556. DEBUG_WARN("System uptime get error: %d\n", error);
  15557. }
  15558. else
  15559. {
  15560. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15561. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15562. }
  15563. isKnowKey = TRUE;
  15564. }
  15565. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15566. {
  15567. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15569. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15570. {
  15571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15572. }
  15573. else
  15574. {
  15575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15576. }
  15577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  15578. isKnowKey = TRUE;
  15579. }
  15580. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15581. {
  15582. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15584. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15585. {
  15586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15587. }
  15588. else
  15589. {
  15590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15591. }
  15592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15593. isKnowKey = TRUE;
  15594. }
  15595. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15596. {
  15597. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15599. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15600. {
  15601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15602. }
  15603. else
  15604. {
  15605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15606. }
  15607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15608. isKnowKey = TRUE;
  15609. }
  15610. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15611. {
  15612. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15614. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15615. {
  15616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15617. }
  15618. else
  15619. {
  15620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15621. }
  15622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15623. isKnowKey = TRUE;
  15624. }
  15625. #if 1
  15626. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15627. {
  15628. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15630. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15631. {
  15632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15633. }
  15634. else
  15635. {
  15636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15637. }
  15638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15639. isKnowKey = TRUE;
  15640. }
  15641. #endif
  15642. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15643. {
  15644. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15646. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15647. {
  15648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15649. }
  15650. else
  15651. {
  15652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15653. }
  15654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15655. isKnowKey = TRUE;
  15656. }
  15657. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15658. {
  15659. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15661. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15662. {
  15663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15664. }
  15665. else
  15666. {
  15667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15668. }
  15669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15670. isKnowKey = TRUE;
  15671. }
  15672. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15673. {
  15674. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15676. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15677. {
  15678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15679. }
  15680. else
  15681. {
  15682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15683. }
  15684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15685. isKnowKey = TRUE;
  15686. }
  15687. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15688. {
  15689. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15691. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15692. {
  15693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15694. }
  15695. else
  15696. {
  15697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15698. }
  15699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15700. isKnowKey = TRUE;
  15701. }
  15702. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15703. {
  15704. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15705. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15706. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15707. {
  15708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15709. }
  15710. else
  15711. {
  15712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15713. }
  15714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15715. isKnowKey = TRUE;
  15716. }
  15717. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15718. {
  15719. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15721. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15722. {
  15723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15724. }
  15725. else
  15726. {
  15727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15728. }
  15729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15730. isKnowKey = TRUE;
  15731. }
  15732. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15733. {
  15734. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15736. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15737. {
  15738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15739. }
  15740. else
  15741. {
  15742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15743. }
  15744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15745. isKnowKey = TRUE;
  15746. }
  15747. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15748. {
  15749. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15751. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15752. {
  15753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15754. }
  15755. else
  15756. {
  15757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15758. }
  15759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15760. isKnowKey = TRUE;
  15761. }
  15762. //=========================================================
  15763. if(!isEmpty && !isKnowKey)
  15764. {
  15765. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15766. strcpy(unknownkey[UnknownKeynum], keyReq);
  15767. UnknownKeynum = UnknownKeynum + 1;
  15768. }
  15769. }
  15770. void processUnkownKey(void)
  15771. {
  15772. DEBUG_INFO("processUnkownKey...\n");
  15773. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15774. for(int index=0; index < UnknownKeynum; index++)
  15775. {
  15776. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15777. {
  15778. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15779. }
  15780. }
  15781. }
  15782. int setKeyValue(char *key, char *value)
  15783. {
  15784. int isSuccess = NotSupported;
  15785. int check_ascii=0;
  15786. char str[501]={0};
  15787. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15788. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15789. {
  15790. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15791. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15792. {
  15793. strcpy(str, (const char*)value);
  15794. for(int i = 0; str[i]; i++){
  15795. str[i] = tolower(str[i]);
  15796. }
  15797. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15798. isSuccess = ConfigurationStatus_Accepted;
  15799. }
  15800. else
  15801. {
  15802. isSuccess = ConfigurationStatus_Rejected;
  15803. }
  15804. }
  15805. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15806. {
  15807. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15808. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15809. {
  15810. strcpy(str, (const char*)value);
  15811. for(int i = 0; str[i]; i++){
  15812. str[i] = tolower(str[i]);
  15813. }
  15814. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15815. isSuccess = ConfigurationStatus_Accepted;
  15816. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  15817. }
  15818. else
  15819. {
  15820. isSuccess = ConfigurationStatus_Rejected;
  15821. }
  15822. }
  15823. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15824. {
  15825. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15826. {
  15827. strcpy(str, (const char*)value);
  15828. for(int i = 0; str[i]; i++)
  15829. {
  15830. str[i] = tolower(str[i]);
  15831. }
  15832. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15833. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15834. isSuccess = ConfigurationStatus_Accepted;
  15835. }
  15836. else
  15837. {
  15838. isSuccess = ConfigurationStatus_Rejected;
  15839. }
  15840. }
  15841. if(strcmp(key, "BlinkRepeat") == 0)
  15842. {
  15843. //Charger.BlinkRepeat = Integer.parseInt(value);
  15844. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15845. {
  15846. check_ascii = value[0];
  15847. if( (check_ascii < 48) || (check_ascii > 57) )
  15848. {
  15849. isSuccess = ConfigurationStatus_Rejected;
  15850. }
  15851. else
  15852. {
  15853. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15854. isSuccess = ConfigurationStatus_Accepted;
  15855. }
  15856. }
  15857. else
  15858. {
  15859. isSuccess = ConfigurationStatus_Rejected;
  15860. }
  15861. }
  15862. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15863. {
  15864. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15865. {
  15866. check_ascii = value[0];
  15867. if( (check_ascii < 48) || (check_ascii > 57) )
  15868. {
  15869. isSuccess = ConfigurationStatus_Rejected;
  15870. }
  15871. else
  15872. {
  15873. if((atoi(value) == 0) || (atoi(value) >= 5))
  15874. {
  15875. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15876. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15877. isSuccess = ConfigurationStatus_Accepted;
  15878. }
  15879. else
  15880. isSuccess = ConfigurationStatus_Rejected;
  15881. }
  15882. }
  15883. else
  15884. {
  15885. isSuccess = ConfigurationStatus_Rejected;
  15886. }
  15887. }
  15888. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15889. {
  15890. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15891. {
  15892. check_ascii = value[0];
  15893. if( (check_ascii < 48) || (check_ascii > 57) )
  15894. {
  15895. isSuccess = ConfigurationStatus_Rejected;
  15896. }
  15897. else
  15898. {
  15899. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15900. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15901. isSuccess = ConfigurationStatus_Accepted;
  15902. }
  15903. }
  15904. else
  15905. {
  15906. isSuccess = ConfigurationStatus_Rejected;
  15907. }
  15908. }
  15909. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15910. {
  15911. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15912. {
  15913. check_ascii = value[0];
  15914. if( (check_ascii < 48) || (check_ascii > 57) )
  15915. {
  15916. isSuccess = ConfigurationStatus_Rejected;
  15917. }
  15918. else
  15919. {
  15920. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15921. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15922. isSuccess = ConfigurationStatus_Accepted;
  15923. }
  15924. }
  15925. else
  15926. {
  15927. isSuccess = ConfigurationStatus_Rejected;
  15928. }
  15929. }
  15930. if(strcmp(key, "HeartbeatInterval") == 0)
  15931. {
  15932. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15933. {
  15934. check_ascii = value[0];
  15935. if( (check_ascii < 48) || (check_ascii > 57) )
  15936. {
  15937. isSuccess = ConfigurationStatus_Rejected;
  15938. }
  15939. else
  15940. {
  15941. if((atoi(value) == 0) || (atoi(value) >= 10))
  15942. {
  15943. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15944. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15945. HeartBeatWaitTime = atoi(value);
  15946. isSuccess = ConfigurationStatus_Accepted;
  15947. }
  15948. else
  15949. {
  15950. isSuccess = ConfigurationStatus_Rejected;
  15951. }
  15952. }
  15953. }
  15954. else
  15955. {
  15956. isSuccess = ConfigurationStatus_Rejected;
  15957. }
  15958. }
  15959. if(strcmp(key, "LightIntensity") == 0)
  15960. {
  15961. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15962. {
  15963. check_ascii = value[0];
  15964. if( (check_ascii < 48) || (check_ascii > 57) )
  15965. {
  15966. isSuccess = ConfigurationStatus_Rejected;
  15967. }
  15968. else
  15969. {
  15970. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15971. isSuccess = ConfigurationStatus_Accepted;
  15972. }
  15973. }
  15974. else
  15975. {
  15976. isSuccess = ConfigurationStatus_Rejected;
  15977. }
  15978. }
  15979. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15980. {
  15981. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15982. {
  15983. strcpy(str, (const char*)value);
  15984. for(int i = 0; str[i]; i++)
  15985. {
  15986. str[i] = tolower(str[i]);
  15987. }
  15988. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15989. isSuccess = ConfigurationStatus_Accepted;
  15990. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15991. }
  15992. else
  15993. {
  15994. isSuccess = ConfigurationStatus_Rejected;
  15995. }
  15996. }
  15997. if(strcmp(key, "LocalPreAuthorize") == 0)
  15998. {
  15999. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16000. {
  16001. strcpy(str, (const char*)value);
  16002. for(int i = 0; str[i]; i++)
  16003. {
  16004. str[i] = tolower(str[i]);
  16005. }
  16006. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16007. isSuccess = ConfigurationStatus_Accepted;
  16008. }
  16009. else
  16010. {
  16011. isSuccess = ConfigurationStatus_Rejected;
  16012. }
  16013. }
  16014. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  16015. {
  16016. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16017. {
  16018. check_ascii = value[0];
  16019. if( (check_ascii < 48) || (check_ascii > 57) )
  16020. {
  16021. isSuccess = ConfigurationStatus_Rejected;
  16022. }
  16023. else
  16024. {
  16025. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  16026. isSuccess = ConfigurationStatus_Accepted;
  16027. }
  16028. }
  16029. else
  16030. {
  16031. isSuccess = ConfigurationStatus_Rejected;
  16032. }
  16033. }
  16034. if(strcmp(key, "MeterValuesAlignedData") == 0)
  16035. {
  16036. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16037. {
  16038. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  16039. isSuccess = ConfigurationStatus_Accepted;
  16040. }
  16041. else
  16042. {
  16043. isSuccess = ConfigurationStatus_Rejected;
  16044. }
  16045. }
  16046. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  16047. {
  16048. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16049. {
  16050. check_ascii = value[0];
  16051. if( (check_ascii < 48) || (check_ascii > 57) )
  16052. {
  16053. isSuccess = ConfigurationStatus_Rejected;
  16054. }
  16055. else
  16056. {
  16057. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16058. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  16059. isSuccess = ConfigurationStatus_Accepted;
  16060. }
  16061. }
  16062. else
  16063. {
  16064. isSuccess = ConfigurationStatus_Rejected;
  16065. }
  16066. }
  16067. if(strcmp(key, "MeterValuesSampledData") == 0 )
  16068. {
  16069. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16070. {
  16071. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  16072. isSuccess = ConfigurationStatus_Accepted;
  16073. }
  16074. else
  16075. {
  16076. isSuccess = ConfigurationStatus_Rejected;
  16077. }
  16078. }
  16079. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16080. {
  16081. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16082. {
  16083. check_ascii = value[0];
  16084. if( (check_ascii < 48) || (check_ascii > 57) )
  16085. {
  16086. isSuccess = ConfigurationStatus_Rejected;
  16087. }
  16088. else
  16089. {
  16090. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16091. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16092. isSuccess = ConfigurationStatus_Accepted;
  16093. }
  16094. }
  16095. else
  16096. {
  16097. isSuccess = ConfigurationStatus_Rejected;
  16098. }
  16099. }
  16100. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16101. {
  16102. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16103. {
  16104. check_ascii = value[0];
  16105. if( (check_ascii < 48) || (check_ascii > 57) )
  16106. {
  16107. isSuccess = ConfigurationStatus_Rejected;
  16108. }
  16109. else
  16110. {
  16111. if((atoi(value) == 0) || (atoi(value) >= 3))
  16112. {
  16113. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16114. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16115. isSuccess = ConfigurationStatus_Accepted;
  16116. }
  16117. else
  16118. {
  16119. isSuccess = ConfigurationStatus_Rejected;
  16120. }
  16121. }
  16122. }
  16123. else
  16124. {
  16125. isSuccess = ConfigurationStatus_Rejected;
  16126. }
  16127. }
  16128. if(strcmp(key, "MinimumStatusDuration") == 0)
  16129. {
  16130. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16131. {
  16132. check_ascii = value[0];
  16133. if( (check_ascii < 48) || (check_ascii > 57) )
  16134. {
  16135. isSuccess = ConfigurationStatus_Rejected;
  16136. }
  16137. else
  16138. {
  16139. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16140. {
  16141. isSuccess = ConfigurationStatus_Rejected;
  16142. }
  16143. else
  16144. {
  16145. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16146. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16147. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16148. isSuccess = ConfigurationStatus_Accepted;
  16149. }
  16150. }
  16151. }
  16152. else
  16153. {
  16154. isSuccess = ConfigurationStatus_Rejected;
  16155. }
  16156. }
  16157. if(strcmp(key, "NumberOfConnectors") == 0)
  16158. {
  16159. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16160. {
  16161. check_ascii = value[0];
  16162. if( (check_ascii < 48) || (check_ascii > 57) )
  16163. {
  16164. isSuccess = ConfigurationStatus_Rejected;
  16165. }
  16166. else
  16167. {
  16168. //Charger.ResetRetries = Integer.parseInt(value);
  16169. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16170. isSuccess = ConfigurationStatus_Accepted;
  16171. }
  16172. }
  16173. else
  16174. {
  16175. isSuccess = ConfigurationStatus_Rejected;
  16176. }
  16177. }
  16178. if(strcmp(key, "ResetRetries") == 0)
  16179. {
  16180. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16181. {
  16182. check_ascii = value[0];
  16183. if( (check_ascii < 48) || (check_ascii > 57) )
  16184. {
  16185. isSuccess = ConfigurationStatus_Rejected;
  16186. }
  16187. else
  16188. {
  16189. //Charger.ResetRetries = Integer.parseInt(value);
  16190. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16191. isSuccess = ConfigurationStatus_Accepted;
  16192. }
  16193. }
  16194. else
  16195. {
  16196. isSuccess = ConfigurationStatus_Rejected;
  16197. }
  16198. }
  16199. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16200. {
  16201. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16202. {
  16203. strcpy(str, (const char*)value);
  16204. for(int i = 0; str[i]; i++)
  16205. {
  16206. str[i] = tolower(str[i]);
  16207. }
  16208. if(strcmp(str, "notapplicable")== 0)
  16209. {
  16210. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16211. isSuccess = ConfigurationStatus_Accepted;
  16212. }
  16213. else if(strcmp(str, "unknown")== 0)
  16214. {
  16215. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16216. isSuccess = ConfigurationStatus_Accepted;
  16217. }
  16218. else if(strcmp(str, "rst")== 0)
  16219. {
  16220. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16221. isSuccess = ConfigurationStatus_Accepted;
  16222. }
  16223. else if(strcmp(str, "rts")== 0)
  16224. {
  16225. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16226. isSuccess = ConfigurationStatus_Accepted;
  16227. }
  16228. else if(strcmp(str, "srt")== 0)
  16229. {
  16230. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16231. isSuccess = ConfigurationStatus_Accepted;
  16232. }
  16233. else if(strcmp(str, "str")== 0)
  16234. {
  16235. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16236. isSuccess = ConfigurationStatus_Accepted;
  16237. }
  16238. else if(strcmp(str, "trs")== 0)
  16239. {
  16240. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16241. isSuccess = ConfigurationStatus_Accepted;
  16242. }
  16243. else if(strcmp(str, "tsr")== 0)
  16244. {
  16245. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16246. isSuccess = ConfigurationStatus_Accepted;
  16247. }
  16248. else
  16249. {
  16250. isSuccess = ConfigurationStatus_Rejected;
  16251. }
  16252. }
  16253. else
  16254. {
  16255. isSuccess = ConfigurationStatus_Rejected;
  16256. }
  16257. }
  16258. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16259. {
  16260. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16261. {
  16262. check_ascii = value[0];
  16263. if( (check_ascii < 48) || (check_ascii > 57) )
  16264. {
  16265. isSuccess = ConfigurationStatus_Rejected;
  16266. }
  16267. else
  16268. {
  16269. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16270. isSuccess = ConfigurationStatus_Accepted;
  16271. }
  16272. }
  16273. else
  16274. {
  16275. isSuccess = ConfigurationStatus_Rejected;
  16276. }
  16277. }
  16278. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16279. {
  16280. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16281. {
  16282. strcpy(str, (const char*)value);
  16283. for(int i = 0; str[i]; i++)
  16284. {
  16285. str[i] = tolower(str[i]);
  16286. }
  16287. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16288. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16289. isSuccess = ConfigurationStatus_Accepted;
  16290. }
  16291. else
  16292. {
  16293. isSuccess = ConfigurationStatus_Rejected;
  16294. }
  16295. }
  16296. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16297. {
  16298. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16299. {
  16300. strcpy(str, (const char*)value);
  16301. for(int i = 0; str[i]; i++)
  16302. {
  16303. str[i] = tolower(str[i]);
  16304. }
  16305. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16306. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16307. isSuccess = ConfigurationStatus_Accepted;
  16308. }
  16309. else
  16310. {
  16311. isSuccess = ConfigurationStatus_Rejected;
  16312. }
  16313. }
  16314. if(strcmp(key, "StopTxnAlignedData") == 0)
  16315. {
  16316. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16317. {
  16318. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16319. isSuccess = ConfigurationStatus_Accepted;
  16320. }
  16321. else
  16322. {
  16323. isSuccess = ConfigurationStatus_Rejected;
  16324. }
  16325. }
  16326. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16327. {
  16328. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16329. {
  16330. check_ascii = value[0];
  16331. if( (check_ascii < 48) || (check_ascii > 57) )
  16332. {
  16333. isSuccess = ConfigurationStatus_Rejected;
  16334. }
  16335. else
  16336. {
  16337. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16338. isSuccess = ConfigurationStatus_Accepted;
  16339. }
  16340. }
  16341. else
  16342. {
  16343. isSuccess = ConfigurationStatus_Rejected;
  16344. }
  16345. }
  16346. if(strcmp(key, "StopTxnSampledData") == 0)
  16347. {
  16348. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16349. {
  16350. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16351. isSuccess = ConfigurationStatus_Accepted;
  16352. }
  16353. else
  16354. {
  16355. isSuccess = ConfigurationStatus_Rejected;
  16356. }
  16357. }
  16358. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16359. {
  16360. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16361. {
  16362. check_ascii = value[0];
  16363. if( (check_ascii < 48) || (check_ascii > 57) )
  16364. {
  16365. isSuccess = ConfigurationStatus_Rejected;
  16366. }
  16367. else
  16368. {
  16369. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16370. isSuccess = ConfigurationStatus_Accepted;
  16371. }
  16372. }
  16373. else
  16374. {
  16375. isSuccess = ConfigurationStatus_Rejected;
  16376. }
  16377. }
  16378. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16379. {
  16380. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16381. {
  16382. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16383. isSuccess = ConfigurationStatus_Accepted;
  16384. }
  16385. else
  16386. {
  16387. isSuccess = ConfigurationStatus_Rejected;
  16388. }
  16389. }
  16390. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16391. {
  16392. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16393. {
  16394. check_ascii = value[0];
  16395. if( (check_ascii < 48) || (check_ascii > 57) )
  16396. {
  16397. isSuccess = ConfigurationStatus_Rejected;
  16398. }
  16399. else
  16400. {
  16401. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16402. isSuccess = ConfigurationStatus_Accepted;
  16403. }
  16404. }
  16405. else
  16406. {
  16407. isSuccess = ConfigurationStatus_Rejected;
  16408. }
  16409. }
  16410. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16411. {
  16412. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16413. {
  16414. check_ascii = value[0];
  16415. if( (check_ascii < 48) || (check_ascii > 57) )
  16416. {
  16417. isSuccess = ConfigurationStatus_Rejected;
  16418. }
  16419. else
  16420. {
  16421. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16422. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16423. TransactionMessageAttemptsValue = atoi(value);
  16424. isSuccess = ConfigurationStatus_Accepted;
  16425. }
  16426. }
  16427. else
  16428. {
  16429. isSuccess = ConfigurationStatus_Rejected;
  16430. }
  16431. }
  16432. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16433. {
  16434. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16435. {
  16436. check_ascii = value[0];
  16437. if( (check_ascii < 48) || (check_ascii > 57) )
  16438. {
  16439. isSuccess = ConfigurationStatus_Rejected;
  16440. }
  16441. else
  16442. {
  16443. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16444. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16445. TransactionMessageRetryIntervalValue = atoi(value);
  16446. isSuccess = ConfigurationStatus_Accepted;
  16447. }
  16448. }
  16449. else
  16450. {
  16451. isSuccess = ConfigurationStatus_Rejected;
  16452. }
  16453. }
  16454. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16455. {
  16456. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16457. {
  16458. strcpy(str, (const char*)value);
  16459. for(int i = 0; str[i]; i++)
  16460. {
  16461. str[i] = tolower(str[i]);
  16462. }
  16463. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16464. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16465. isSuccess = ConfigurationStatus_Accepted;
  16466. }
  16467. else
  16468. {
  16469. isSuccess = ConfigurationStatus_Rejected;
  16470. }
  16471. }
  16472. if(strcmp(key, "WebSocketPingInterval") == 0)
  16473. {
  16474. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16475. {
  16476. check_ascii = value[0];
  16477. if( (check_ascii < 48) || (check_ascii > 57) )
  16478. {
  16479. isSuccess = ConfigurationStatus_Rejected;
  16480. }
  16481. else
  16482. {
  16483. if((atoi(value) == 0) || (atoi(value) >= 10))
  16484. {
  16485. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16486. isSuccess = ConfigurationStatus_Accepted;
  16487. }
  16488. else
  16489. isSuccess = ConfigurationStatus_Rejected;
  16490. }
  16491. }
  16492. else
  16493. {
  16494. isSuccess = ConfigurationStatus_Rejected;
  16495. }
  16496. }
  16497. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16498. {
  16499. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16500. {
  16501. strcpy(str, (const char*)value);
  16502. for(int i = 0; str[i]; i++)
  16503. {
  16504. str[i] = tolower(str[i]);
  16505. }
  16506. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16507. isSuccess = ConfigurationStatus_Accepted;
  16508. }
  16509. else
  16510. {
  16511. isSuccess = ConfigurationStatus_Rejected;
  16512. }
  16513. }
  16514. if(strcmp(key, "AuthorizationKey") == 0)
  16515. {
  16516. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16517. {
  16518. strcpy(str, (const char*)value);
  16519. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16520. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16521. isSuccess = ConfigurationStatus_Accepted;
  16522. }
  16523. else
  16524. {
  16525. isSuccess = ConfigurationStatus_Rejected;
  16526. }
  16527. }
  16528. if(strcmp(key, "SecurityProfile") == 0)
  16529. {
  16530. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16531. {
  16532. check_ascii = value[0];
  16533. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16534. {
  16535. isSuccess = ConfigurationStatus_Rejected;
  16536. }
  16537. else if(check_ascii == 0x33)
  16538. {
  16539. isSuccess = NotSupported;
  16540. }
  16541. else
  16542. {
  16543. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16544. {
  16545. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16546. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  16547. isSuccess = ConfigurationStatus_Accepted;
  16548. }
  16549. else
  16550. isSuccess = ConfigurationStatus_Rejected;
  16551. }
  16552. }
  16553. else
  16554. {
  16555. isSuccess = ConfigurationStatus_Rejected;
  16556. }
  16557. }
  16558. if(strcmp(key, "DefaultPrice") == 0)
  16559. {
  16560. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16561. {
  16562. strcpy(str, (const char*)value);
  16563. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16564. isSuccess = ConfigurationStatus_Accepted;
  16565. }
  16566. else
  16567. {
  16568. isSuccess = ConfigurationStatus_Rejected;
  16569. }
  16570. }
  16571. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16572. {
  16573. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16574. {
  16575. strcpy(str, (const char*)value);
  16576. for(int i = 0; str[i]; i++)
  16577. {
  16578. str[i] = tolower(str[i]);
  16579. }
  16580. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16581. isSuccess = ConfigurationStatus_Accepted;
  16582. }
  16583. else
  16584. {
  16585. isSuccess = ConfigurationStatus_Rejected;
  16586. }
  16587. }
  16588. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16589. {
  16590. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16591. {
  16592. strcpy(str, (const char*)value);
  16593. for(int i = 0; str[i]; i++)
  16594. {
  16595. str[i] = tolower(str[i]);
  16596. }
  16597. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16598. isSuccess = ConfigurationStatus_Accepted;
  16599. }
  16600. else
  16601. {
  16602. isSuccess = ConfigurationStatus_Rejected;
  16603. }
  16604. }
  16605. if(strcmp(key, "TimeOffset") == 0)
  16606. {
  16607. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16608. {
  16609. strcpy(str, (const char*)value);
  16610. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  16611. isSuccess = ConfigurationStatus_Accepted;
  16612. }
  16613. else
  16614. {
  16615. isSuccess = ConfigurationStatus_Rejected;
  16616. }
  16617. }
  16618. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  16619. {
  16620. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  16621. {
  16622. strcpy(str, (const char*)value);
  16623. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  16624. isSuccess = ConfigurationStatus_Accepted;
  16625. }
  16626. else
  16627. {
  16628. isSuccess = ConfigurationStatus_Rejected;
  16629. }
  16630. }
  16631. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  16632. {
  16633. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  16634. {
  16635. strcpy(str, (const char*)value);
  16636. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  16637. isSuccess = ConfigurationStatus_Accepted;
  16638. }
  16639. else
  16640. {
  16641. isSuccess = ConfigurationStatus_Rejected;
  16642. }
  16643. }
  16644. if(strcmp(key, "SystemUptimeSec") == 0)
  16645. {
  16646. isSuccess = NotSupported;
  16647. }
  16648. if(strcmp(key, "FreeVend") == 0)
  16649. {
  16650. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16651. {
  16652. strcpy(str, (const char*)value);
  16653. for(int i = 0; str[i]; i++)
  16654. {
  16655. str[i] = tolower(str[i]);
  16656. }
  16657. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16658. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16659. isSuccess = ConfigurationStatus_Accepted;
  16660. }
  16661. else
  16662. {
  16663. isSuccess = ConfigurationStatus_Rejected;
  16664. }
  16665. }
  16666. if(strcmp(key, "OcppServer") == 0)
  16667. {
  16668. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16669. {
  16670. strcpy(str, (const char*)value);
  16671. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16672. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16673. isSuccess = ConfigurationStatus_Accepted;
  16674. }
  16675. else
  16676. {
  16677. isSuccess = ConfigurationStatus_Rejected;
  16678. }
  16679. }
  16680. if(strcmp(key, "MaintainServer") == 0)
  16681. {
  16682. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16683. {
  16684. strcpy(str, (const char*)value);
  16685. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16686. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16687. isSuccess = ConfigurationStatus_Accepted;
  16688. }
  16689. else
  16690. {
  16691. isSuccess = ConfigurationStatus_Rejected;
  16692. }
  16693. }
  16694. #if 0
  16695. //For OCPP Test Case
  16696. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16697. {
  16698. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16699. {
  16700. strcpy(str, (const char*)value);
  16701. for(int i = 0; str[i]; i++)
  16702. {
  16703. str[i] = tolower(str[i]);
  16704. }
  16705. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16706. isSuccess = ConfigurationStatus_Accepted;
  16707. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16708. }
  16709. else
  16710. {
  16711. isSuccess = ConfigurationStatus_Rejected;
  16712. }
  16713. }
  16714. #endif
  16715. #if 1
  16716. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16717. {
  16718. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16719. {
  16720. strcpy(str, (const char*)value);
  16721. for(int i = 0; str[i]; i++)
  16722. {
  16723. str[i] = tolower(str[i]);
  16724. }
  16725. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16726. isSuccess = ConfigurationStatus_Accepted;
  16727. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16728. }
  16729. else
  16730. {
  16731. isSuccess = ConfigurationStatus_Rejected;
  16732. }
  16733. }
  16734. #endif
  16735. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16736. {
  16737. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16738. {
  16739. check_ascii = value[0];
  16740. if( (check_ascii < 48) || (check_ascii > 57) )
  16741. {
  16742. isSuccess = ConfigurationStatus_Rejected;
  16743. }
  16744. else
  16745. {
  16746. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16747. isSuccess = ConfigurationStatus_Accepted;
  16748. }
  16749. }
  16750. else
  16751. {
  16752. isSuccess = ConfigurationStatus_Rejected;
  16753. }
  16754. }
  16755. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16756. {
  16757. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16758. {
  16759. check_ascii = value[0];
  16760. if( (check_ascii < 48) || (check_ascii > 57) )
  16761. {
  16762. isSuccess = ConfigurationStatus_Rejected;
  16763. }
  16764. else
  16765. {
  16766. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16767. isSuccess = ConfigurationStatus_Accepted;
  16768. }
  16769. }
  16770. else
  16771. {
  16772. isSuccess = ConfigurationStatus_Rejected;
  16773. }
  16774. }
  16775. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16776. {
  16777. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16778. {
  16779. strcpy(str, (const char*)value);
  16780. for(int i = 0; str[i]; i++)
  16781. {
  16782. str[i] = tolower(str[i]);
  16783. }
  16784. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16785. isSuccess = ConfigurationStatus_Accepted;
  16786. }
  16787. else
  16788. {
  16789. isSuccess = ConfigurationStatus_Rejected;
  16790. }
  16791. }
  16792. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16793. {
  16794. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16795. {
  16796. check_ascii = value[0];
  16797. if( (check_ascii < 48) || (check_ascii > 57) )
  16798. {
  16799. isSuccess = ConfigurationStatus_Rejected;
  16800. }
  16801. else
  16802. {
  16803. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16804. isSuccess = ConfigurationStatus_Accepted;
  16805. }
  16806. }
  16807. else
  16808. {
  16809. isSuccess = ConfigurationStatus_Rejected;
  16810. }
  16811. }
  16812. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16813. {
  16814. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16815. {
  16816. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16817. isSuccess = ConfigurationStatus_Accepted;
  16818. }
  16819. else
  16820. {
  16821. isSuccess = ConfigurationStatus_Rejected;
  16822. }
  16823. }
  16824. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16825. {
  16826. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16827. {
  16828. check_ascii = value[0];
  16829. if( (check_ascii < 48) || (check_ascii > 57) )
  16830. {
  16831. isSuccess = ConfigurationStatus_Rejected;
  16832. }
  16833. else
  16834. {
  16835. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16836. isSuccess = ConfigurationStatus_Accepted;
  16837. }
  16838. }
  16839. else
  16840. {
  16841. isSuccess = ConfigurationStatus_Rejected;
  16842. }
  16843. }
  16844. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16845. {
  16846. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16847. {
  16848. strcpy(str, (const char*)value);
  16849. for(int i = 0; str[i]; i++)
  16850. {
  16851. str[i] = tolower(str[i]);
  16852. }
  16853. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16854. isSuccess = ConfigurationStatus_Accepted;
  16855. }
  16856. else
  16857. {
  16858. isSuccess = ConfigurationStatus_Rejected;
  16859. }
  16860. }
  16861. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16862. {
  16863. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16864. {
  16865. check_ascii = value[0];
  16866. if( (check_ascii < 48) || (check_ascii > 57) )
  16867. {
  16868. isSuccess = ConfigurationStatus_Rejected;
  16869. }
  16870. else
  16871. {
  16872. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16873. isSuccess = ConfigurationStatus_Accepted;
  16874. }
  16875. }
  16876. else
  16877. {
  16878. isSuccess = ConfigurationStatus_Rejected;
  16879. }
  16880. }
  16881. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16882. return isSuccess;
  16883. }
  16884. int TransactionMessageAttemptsGet(void)
  16885. {
  16886. return TransactionMessageAttemptsValue;
  16887. }
  16888. int FirstHeartBeatResponse(void)
  16889. {
  16890. return FirstHeartBeat;
  16891. }
  16892. int TransactionMessageRetryIntervalGet(void)
  16893. {
  16894. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16895. }
  16896. int ReadHttpStatus(int sock)
  16897. {
  16898. //char c;
  16899. char buff[1024]="",*ptr=buff+1;
  16900. int bytes_received, status;
  16901. DEBUG_INFO("Begin Response ..\n");
  16902. while((bytes_received = recv(sock, ptr, 1, 0))){
  16903. if(bytes_received==-1){
  16904. perror("ReadHttpStatus");
  16905. exit(1);
  16906. }
  16907. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16908. ptr++;
  16909. }
  16910. *ptr=0;
  16911. ptr=buff+1;
  16912. sscanf(ptr,"%*s %d ", &status);
  16913. DEBUG_INFO("%s\n",ptr);
  16914. DEBUG_INFO("status=%d\n",status);
  16915. DEBUG_INFO("End Response ..\n");
  16916. return (bytes_received>0)?status:0;
  16917. }
  16918. //the only filed that it parsed is 'Content-Length'
  16919. int ParseHeader(int sock)
  16920. {
  16921. //char c;
  16922. char buff[1024]="",*ptr=buff+4;
  16923. int bytes_received;
  16924. DEBUG_INFO("Begin HEADER ..\n");
  16925. while((bytes_received = recv(sock, ptr, 1, 0))){
  16926. if(bytes_received==-1){
  16927. perror("Parse Header");
  16928. exit(1);
  16929. }
  16930. if(
  16931. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16932. (ptr[-1]=='\r') && (*ptr=='\n' )
  16933. ) break;
  16934. ptr++;
  16935. }
  16936. *ptr=0;
  16937. ptr=buff+4;
  16938. //printf("%s",ptr);
  16939. if(bytes_received){
  16940. ptr=strstr(ptr,"Content-Length:");
  16941. if(ptr){
  16942. sscanf(ptr,"%*s %d",&bytes_received);
  16943. }else
  16944. bytes_received=-1; //unknown size
  16945. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16946. }
  16947. DEBUG_INFO("End HEADER ..\n");
  16948. return bytes_received ;
  16949. }
  16950. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16951. {
  16952. int result = TRUE;
  16953. char rmFileCmd[100]={0};
  16954. char FilePath[100]={0};
  16955. char ftpbuf[200];
  16956. int systemresult;
  16957. sprintf(FilePath,"/mnt/%s",filename);
  16958. system("ping 8.8.8.8 &");
  16959. if((access(FilePath,F_OK))!=-1)
  16960. {
  16961. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16962. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16963. system(rmFileCmd);
  16964. }
  16965. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16966. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16967. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16968. systemresult = system(ftpbuf);
  16969. if(systemresult != 0)
  16970. {
  16971. DEBUG_INFO("http DownLoad error!\n");
  16972. result = FALSE;
  16973. }
  16974. system("pkill ping");
  16975. return result;
  16976. }
  16977. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16978. {
  16979. int result = TRUE;
  16980. char rmFileCmd[100]={0};
  16981. char FilePath[100]={0};
  16982. char ftpbuf[200];
  16983. int systemresult;
  16984. sprintf(FilePath,"/mnt/%s",filename);
  16985. system("ping 8.8.8.8 &");
  16986. if((access(FilePath,F_OK))!=-1)
  16987. {
  16988. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16989. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16990. system(rmFileCmd);
  16991. }
  16992. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16993. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16994. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16995. systemresult = system(ftpbuf);
  16996. if(systemresult != 0)
  16997. {
  16998. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16999. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17000. systemresult = system(ftpbuf);
  17001. if(systemresult != 0)
  17002. {
  17003. DEBUG_WARN("wget error!\n");
  17004. result = FALSE;
  17005. }
  17006. }
  17007. system("pkill ping");
  17008. return result;
  17009. }
  17010. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17011. {
  17012. char rmFileCmd[100]={0};
  17013. char FilePath[100]={0};
  17014. char buf[512];
  17015. int systemresult = 0;
  17016. //DEBUG_INFO("filename=%s\n",filename);
  17017. //DEBUG_INFO("url=%s\n",url);
  17018. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17019. if((access(FilePath,F_OK))!=-1)
  17020. {
  17021. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17022. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17023. system(rmFileCmd);
  17024. }
  17025. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17026. if(fp == NULL)
  17027. {
  17028. DEBUG_INFO("log is NULL\n");
  17029. return FALSE;
  17030. }
  17031. else
  17032. {
  17033. fprintf(fp, "%s\n", url);
  17034. fprintf(fp, "%s\n", filename);
  17035. fclose(fp);
  17036. }
  17037. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17038. if(phpFP == NULL)
  17039. {
  17040. DEBUG_INFO("PHP upload fail.\n");
  17041. return FALSE;
  17042. }
  17043. else
  17044. {
  17045. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17046. {
  17047. if(strstr(buf, "result") != NULL)
  17048. {
  17049. sscanf(buf, "result: %d", &systemresult);
  17050. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17051. }
  17052. }
  17053. pclose(phpFP);
  17054. }
  17055. if(systemresult != 1)
  17056. {
  17057. DEBUG_INFO("HTTP upload error!\n");
  17058. return FALSE;
  17059. }
  17060. return TRUE;
  17061. }
  17062. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17063. {
  17064. int result = FALSE;
  17065. char ftpbuf[200];
  17066. int systemresult;
  17067. /*
  17068. // Domaind name transfer to IP address
  17069. struct hostent* server;
  17070. char *IPbuffer;
  17071. server = gethostbyname(location);
  17072. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17073. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17074. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17075. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17076. systemresult = system(ftpbuf);
  17077. if(systemresult != 0)
  17078. {
  17079. DEBUG_INFO("ftpput error!\n");
  17080. }
  17081. else
  17082. {
  17083. result = TRUE;
  17084. DEBUG_INFO("ftpput OK!\n");
  17085. }
  17086. return result;
  17087. }
  17088. int GetOcppServerURL()
  17089. {
  17090. int result = FALSE;
  17091. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17092. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17093. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17094. struct yuarel url;
  17095. char urlStr[512];
  17096. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  17097. {
  17098. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  17099. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17100. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17101. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  17102. if(yuarel_parse(&url, urlStr) != -1)
  17103. {
  17104. sprintf(OcppProtocol, "%s", url.scheme);
  17105. sprintf(OcppHost, "%s", url.host);
  17106. if(url.path == NULL)
  17107. OcppTempPath[0] = '\0';
  17108. else
  17109. {
  17110. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  17111. {
  17112. sprintf(OcppTempPath, "%s/", url.path);
  17113. }
  17114. else
  17115. {
  17116. sprintf(OcppTempPath, "%s", url.path);
  17117. }
  17118. }
  17119. if(url.port == 0)
  17120. {
  17121. if(strcmp(OcppProtocol, "wss") == 0)
  17122. OcppPort = 443;
  17123. else
  17124. OcppPort = 80;
  17125. }
  17126. else
  17127. OcppPort = url.port;
  17128. result = TRUE;
  17129. }
  17130. }
  17131. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  17132. {
  17133. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  17134. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17135. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17136. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  17137. if(yuarel_parse(&url, urlStr) != -1)
  17138. {
  17139. sprintf(OcppProtocol, "%s", url.scheme);
  17140. sprintf(OcppHost, "%s", url.host);
  17141. if(url.path == NULL)
  17142. OcppTempPath[0] = '\0';
  17143. else
  17144. sprintf(OcppTempPath, "%s", url.path);
  17145. if(url.port == 0)
  17146. {
  17147. if(strcmp(OcppProtocol, "wss") == 0)
  17148. OcppPort = 443;
  17149. else
  17150. OcppPort = 80;
  17151. }
  17152. else
  17153. OcppPort = url.port;
  17154. result = TRUE;
  17155. }
  17156. }
  17157. else
  17158. {
  17159. strcpy(OcppHost,"");
  17160. }
  17161. return result;
  17162. }
  17163. int GetOcppPath()
  17164. {
  17165. int result = FALSE;
  17166. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  17167. {
  17168. if(OcppTempPath == NULL)
  17169. {
  17170. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17171. }
  17172. else
  17173. {
  17174. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17175. }
  17176. result = TRUE;
  17177. goto End;
  17178. }
  17179. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  17180. {
  17181. if(OcppTempPath == NULL)
  17182. {
  17183. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  17184. }
  17185. else
  17186. {
  17187. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  17188. }
  17189. result = TRUE;
  17190. goto End;
  17191. }
  17192. else
  17193. {
  17194. strcpy(OcppPath,"");
  17195. }
  17196. End:
  17197. return result;
  17198. }
  17199. int GetOcppPort()
  17200. {
  17201. return OcppPort;
  17202. }
  17203. int GetOcppConnStatus(void)
  17204. {
  17205. return ShmOCPP16Data->OcppConnStatus;
  17206. }
  17207. void SetOcppConnStatus(uint8_t status)
  17208. {
  17209. ShmOCPP16Data->OcppConnStatus = status;
  17210. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  17211. }
  17212. int GetHeartBeatWithNOResponse(void)
  17213. {
  17214. return HeartBeatWithNOResponse;
  17215. }
  17216. void SetHeartBeatWithNOResponse(void)
  17217. {
  17218. HeartBeatWithNOResponse = 0;
  17219. }
  17220. void GetStartTransactionIdTag(int gun_index)
  17221. {
  17222. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17223. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17224. }
  17225. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17226. {
  17227. char ch;
  17228. FILE *fptr1;
  17229. int temptransactionId;
  17230. char str[100]={0};
  17231. temptransactionId = 0;
  17232. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17233. {
  17234. DEBUG_INFO("IdTag is empty.\n");
  17235. return temptransactionId;
  17236. }
  17237. /*------ Read the file ----------------*/
  17238. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  17239. if (!fptr1)
  17240. {
  17241. DEBUG_INFO("QueueTransactionId file open error.\n");
  17242. //printf(" File not found or unable to open the input file!!\n");
  17243. return temptransactionId;
  17244. }
  17245. ch=fgetc(fptr1);
  17246. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  17247. rewind(fptr1);
  17248. if(ch!=EOF)
  17249. {
  17250. // printf("%c",ch);
  17251. while (fgets(str, 100, fptr1) != NULL)
  17252. {
  17253. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17254. if(str[0]=='\0')
  17255. {
  17256. break;
  17257. }
  17258. char *revbuf[8] = {0}; // Variable store string split
  17259. int num = 0;// Quantity after string split
  17260. DEBUG_INFO("Transaction queue data= %s\n", str);
  17261. splitstring(str,",",revbuf,&num); // String split
  17262. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17263. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17264. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17265. DEBUG_INFO("------------------------------\n");
  17266. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17267. {
  17268. if(isStopTransaction)
  17269. {
  17270. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17271. {
  17272. temptransactionId = atoi(revbuf[2]);
  17273. //break;
  17274. }
  17275. }
  17276. else
  17277. {
  17278. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17279. {
  17280. temptransactionId = atoi(revbuf[2]);
  17281. //break;
  17282. }
  17283. }
  17284. }
  17285. }
  17286. }
  17287. else
  17288. DEBUG_INFO("EOF\n");
  17289. fclose(fptr1);
  17290. /*------- End of reading ---------------*/
  17291. return temptransactionId;
  17292. }
  17293. void SetTransactionIdZero(int transactionId)
  17294. {
  17295. char ch;
  17296. FILE *fptr1, *fptr2;
  17297. int temptransactionId = 0;
  17298. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  17299. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  17300. if (!fptr1)
  17301. {
  17302. //printf(" File not found or unable to open the input file!!\n");
  17303. return ;
  17304. }
  17305. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17306. if (!fptr2)
  17307. {
  17308. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17309. fclose(fptr1);
  17310. return ;
  17311. }
  17312. ch=fgetc(fptr1);
  17313. rewind(fptr1);
  17314. if(ch!=EOF)
  17315. {
  17316. // copy all contents to the temporary file except the specific line
  17317. while (fgets(str, 100, fptr1) != NULL)
  17318. {
  17319. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17320. if(str[0]=='\0')
  17321. {
  17322. break;
  17323. }
  17324. char *revbuf[8] = {0};
  17325. int num = 0;
  17326. strcpy(strtemp, str);
  17327. splitstring(str,",",revbuf,&num);
  17328. if(revbuf[2][0] != '\0')
  17329. {
  17330. temptransactionId = atoi(revbuf[2]);
  17331. if(transactionId != temptransactionId)
  17332. {
  17333. fprintf(fptr2, "%s\n", strtemp);
  17334. }
  17335. }
  17336. }
  17337. }
  17338. fclose(fptr1);
  17339. fclose(fptr2);
  17340. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  17341. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  17342. /*------ Read the file ----------------*/
  17343. }
  17344. int InternetDisconnect(void)
  17345. {
  17346. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17347. }
  17348. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17349. void storeTempStopTransaction(int gun_index)
  17350. {
  17351. char guid[37]={0};
  17352. int tempIndex = 0;
  17353. char TempStopTransaction[256];
  17354. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  17355. DEBUG_INFO("storeTempStopTransaction...\n");
  17356. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17357. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  17358. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17359. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17360. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17361. {
  17362. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17363. {
  17364. tempIndex = ((gun_index==2) ? 1: 0);
  17365. }
  17366. else
  17367. {
  17368. tempIndex = gun_index;
  17369. }
  17370. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17371. {
  17372. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17373. {
  17374. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17375. }
  17376. }// END OF CHAdeMO_QUANTITY
  17377. }
  17378. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17379. {
  17380. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17381. {
  17382. tempIndex = ((gun_index==2) ? 1: 0);
  17383. }
  17384. else
  17385. {
  17386. tempIndex = gun_index;
  17387. }
  17388. for (int index = 0; index < CCS_QUANTITY; index++)
  17389. {
  17390. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17391. {
  17392. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17393. }
  17394. }// END OF CCS_QUANTITY
  17395. }
  17396. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17397. {
  17398. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17399. {
  17400. tempIndex = ((gun_index==2) ? 1: 0);
  17401. }
  17402. else
  17403. {
  17404. tempIndex = gun_index;
  17405. }
  17406. for (int index = 0; index < GB_QUANTITY; index++)
  17407. {
  17408. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17409. {
  17410. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17411. }
  17412. }// END OF GB_QUANTITY
  17413. }
  17414. else if(gunType[gun_index] == GUN_TYPE_DO)
  17415. {
  17416. tempIndex = gun_index;
  17417. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17418. {
  17419. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17420. {
  17421. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17422. }
  17423. }
  17424. }
  17425. else
  17426. {
  17427. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17428. {
  17429. tempIndex = 2;
  17430. }
  17431. else
  17432. {
  17433. tempIndex = gun_index;
  17434. }
  17435. for (int index = 0; index < AC_QUANTITY; index++)
  17436. {
  17437. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17438. {
  17439. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17440. }
  17441. }// END OF AC_QUANTITY
  17442. }
  17443. //Stop Transaction Time
  17444. struct timeval tmnow;
  17445. struct tm *tm;
  17446. char buf[28];//, usec_buf[6];
  17447. gettimeofday(&tmnow, NULL);
  17448. time_t t;
  17449. t = time(NULL);
  17450. /*UTC time and date*/
  17451. tm = gmtime(&t);
  17452. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17453. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  17454. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  17455. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17456. random_uuid(guid);
  17457. /***********************************transactionData******************************************************/
  17458. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17459. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17460. //=================================
  17461. //1. Transaction_Begin
  17462. //=================================
  17463. //============================== Energy.Active.Import.Interval ===========================================
  17464. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17465. {
  17466. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  17467. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17468. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  17469. 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*/]);
  17470. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17471. 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))
  17472. {
  17473. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  17474. }
  17475. else
  17476. {
  17477. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  17478. }
  17479. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  17480. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17481. }
  17482. //=================================
  17483. //2. Transaction_End
  17484. //=================================
  17485. //2.1====================================== Current.Import L1 ==============================================
  17486. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17487. {
  17488. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17489. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17490. {
  17491. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17492. {
  17493. tempIndex = ((gun_index==2) ? 1: 0);
  17494. }
  17495. else
  17496. {
  17497. tempIndex = gun_index;
  17498. }
  17499. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17500. {
  17501. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17502. {
  17503. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17504. }
  17505. }// End of for CHAdeMO_QUANTITY
  17506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17507. }
  17508. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17509. {
  17510. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17511. {
  17512. tempIndex = ((gun_index==2) ? 1: 0);
  17513. }
  17514. else
  17515. {
  17516. tempIndex = gun_index;
  17517. }
  17518. for (int index = 0; index < CCS_QUANTITY; index++)
  17519. {
  17520. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17521. {
  17522. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17523. }
  17524. }// End of for CCS_QUANTITY
  17525. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17526. }
  17527. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17528. {
  17529. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17530. {
  17531. tempIndex = ((gun_index==2) ? 1: 0);
  17532. }
  17533. else
  17534. {
  17535. tempIndex = gun_index;
  17536. }
  17537. for (int index = 0; index < GB_QUANTITY; index++)
  17538. {
  17539. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17540. {
  17541. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17542. }
  17543. }// End of for GB_QUANTITY
  17544. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17545. }
  17546. else if(gunType[gun_index] == GUN_TYPE_DO)
  17547. {
  17548. tempIndex = gun_index;
  17549. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17550. {
  17551. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17552. {
  17553. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17554. }
  17555. }
  17556. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17557. }
  17558. else
  17559. {
  17560. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17561. {
  17562. tempIndex = 2;
  17563. }
  17564. else
  17565. {
  17566. tempIndex = gun_index;
  17567. }
  17568. for (int index = 0; index < AC_QUANTITY; index++)
  17569. {
  17570. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17571. {
  17572. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17573. }
  17574. }// End of for AC_QUANTITY
  17575. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17576. }
  17577. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17578. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17579. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17580. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17581. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17582. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17583. }
  17584. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17585. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17586. {
  17587. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17588. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17589. {
  17590. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17591. {
  17592. tempIndex = ((gun_index==2) ? 1: 0);
  17593. }
  17594. else
  17595. {
  17596. tempIndex = gun_index;
  17597. }
  17598. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17599. {
  17600. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17601. {
  17602. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17603. }
  17604. }// END OF CHAdeMO_QUANTITY
  17605. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17606. }
  17607. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17608. {
  17609. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17610. {
  17611. tempIndex = ((gun_index==2) ? 1: 0);
  17612. }
  17613. else
  17614. {
  17615. tempIndex = gun_index;
  17616. }
  17617. for (int index = 0; index < CCS_QUANTITY; index++)
  17618. {
  17619. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17620. {
  17621. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17622. }
  17623. }// END OF CCS_QUANTITY
  17624. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17625. }
  17626. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17627. {
  17628. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17629. {
  17630. tempIndex = ((gun_index==2) ? 1: 0);
  17631. }
  17632. else
  17633. {
  17634. tempIndex = gun_index;
  17635. }
  17636. for (int index = 0; index < GB_QUANTITY; index++)
  17637. {
  17638. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17639. {
  17640. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17641. }
  17642. }// END OF GB_QUANTITY
  17643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17644. }
  17645. else if(gunType[gun_index] == GUN_TYPE_DO)
  17646. {
  17647. tempIndex = gun_index;
  17648. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17649. {
  17650. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17651. {
  17652. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17653. }
  17654. }
  17655. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17656. }
  17657. else
  17658. {
  17659. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17660. {
  17661. tempIndex = 2;
  17662. }
  17663. else
  17664. {
  17665. tempIndex = gun_index;
  17666. }
  17667. for (int index = 0; index < AC_QUANTITY; index++)
  17668. {
  17669. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17670. {
  17671. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17672. }
  17673. }// END OF AC_QUANTITY
  17674. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17675. }
  17676. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17677. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17678. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17679. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17680. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17681. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17682. }
  17683. //2.3====================================== Power.Active.Import =========================================
  17684. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17685. {
  17686. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17687. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17688. {
  17689. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17690. {
  17691. tempIndex = ((gun_index==2) ? 1: 0);
  17692. }
  17693. else
  17694. {
  17695. tempIndex = gun_index;
  17696. }
  17697. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17698. {
  17699. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17700. {
  17701. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17702. }
  17703. } // End for CHAdeMO_QUANTITY
  17704. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17705. }
  17706. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17707. {
  17708. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17709. {
  17710. tempIndex = ((gun_index==2) ? 1: 0);
  17711. }
  17712. else
  17713. {
  17714. tempIndex = gun_index;
  17715. }
  17716. for (int index = 0; index < CCS_QUANTITY; index++)
  17717. {
  17718. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17719. {
  17720. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17721. }
  17722. } // END for CCS_QUANTITY
  17723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17724. }
  17725. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17726. {
  17727. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17728. {
  17729. tempIndex = ((gun_index==2) ? 1: 0);
  17730. }
  17731. else
  17732. {
  17733. tempIndex = gun_index;
  17734. }
  17735. for (int index = 0; index < GB_QUANTITY; index++)
  17736. {
  17737. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17738. {
  17739. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17740. }
  17741. }// END for GB_QUANTITY
  17742. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17743. }
  17744. else if(gunType[gun_index] == GUN_TYPE_DO)
  17745. {
  17746. tempIndex = gun_index;
  17747. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17748. {
  17749. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17750. {
  17751. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17752. }
  17753. }
  17754. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17755. }
  17756. else
  17757. {
  17758. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17759. {
  17760. tempIndex = 2;
  17761. }
  17762. else
  17763. {
  17764. tempIndex = gun_index;
  17765. }
  17766. for (int index = 0; index < AC_QUANTITY; index++)
  17767. {
  17768. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17769. {
  17770. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17771. }
  17772. } // END for AC_QUANTITY
  17773. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17774. }
  17775. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17776. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17777. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17778. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17779. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17780. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17781. }
  17782. //2.4====================================== Voltage L1 ====================================================
  17783. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17784. {
  17785. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17786. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17787. {
  17788. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17789. {
  17790. tempIndex = ((gun_index==2) ? 1: 0);
  17791. }
  17792. else
  17793. {
  17794. tempIndex = gun_index;
  17795. }
  17796. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17797. {
  17798. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17799. {
  17800. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17801. }
  17802. } // END OF FOR CHAdeMO_QUANTITY
  17803. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17804. }
  17805. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17806. {
  17807. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17808. {
  17809. tempIndex = ((gun_index==2) ? 1: 0);
  17810. }
  17811. else
  17812. {
  17813. tempIndex = gun_index;
  17814. }
  17815. for (int index = 0; index < CCS_QUANTITY; index++)
  17816. {
  17817. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17818. {
  17819. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17820. }
  17821. } // END OF FOR CCS_QUANTITY
  17822. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17823. }
  17824. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17825. {
  17826. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17827. {
  17828. tempIndex = ((gun_index==2) ? 1: 0);
  17829. }
  17830. else
  17831. {
  17832. tempIndex = gun_index;
  17833. }
  17834. for (int index = 0; index < GB_QUANTITY; index++)
  17835. {
  17836. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17837. {
  17838. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17839. }
  17840. } // END OF FOR GB_QUANTITY
  17841. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17842. }
  17843. else if(gunType[gun_index] == GUN_TYPE_DO)
  17844. {
  17845. tempIndex = gun_index;
  17846. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17847. {
  17848. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17849. {
  17850. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17851. }
  17852. }
  17853. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17854. }
  17855. else
  17856. {
  17857. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17858. {
  17859. tempIndex = 2;
  17860. }
  17861. else
  17862. {
  17863. tempIndex = gun_index;
  17864. }
  17865. for (int index = 0; index < AC_QUANTITY; index++)
  17866. {
  17867. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17868. {
  17869. 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
  17870. }
  17871. } // END OF FOR AC_QUANTITY
  17872. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17873. }
  17874. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17875. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17876. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17877. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17878. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17879. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17880. }
  17881. //2.5============================================== End SoC =========================================================
  17882. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17883. {
  17884. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17885. 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))
  17886. {
  17887. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17888. {
  17889. tempIndex = ((gun_index==2) ? 1: 0);
  17890. }
  17891. else
  17892. {
  17893. tempIndex = gun_index;
  17894. }
  17895. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17896. {
  17897. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17898. {
  17899. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17900. {
  17901. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17902. }
  17903. }
  17904. }
  17905. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17906. {
  17907. for (int index = 0; index < CCS_QUANTITY; index++)
  17908. {
  17909. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17910. {
  17911. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17912. }
  17913. }
  17914. }
  17915. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17916. {
  17917. for (int index = 0; index < GB_QUANTITY; index++)
  17918. {
  17919. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17920. {
  17921. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17922. }
  17923. }
  17924. }
  17925. else if(gunType[gun_index] == GUN_TYPE_DO)
  17926. {
  17927. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17928. {
  17929. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17930. {
  17931. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17932. }
  17933. }
  17934. }
  17935. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17936. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17937. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17938. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17939. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17940. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17941. } // END FOR DC CASE
  17942. }
  17943. //2.6====================================== Current.Import L2 ==============================================
  17944. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17945. {
  17946. // AC 3 phase L2 current
  17947. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17948. {
  17949. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17950. {
  17951. tempIndex = 2;
  17952. }
  17953. else
  17954. {
  17955. tempIndex = gun_index;
  17956. }
  17957. for (int index = 0; index < AC_QUANTITY; index++)
  17958. {
  17959. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17960. {
  17961. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17962. }
  17963. }// End of for AC_QUANTITY
  17964. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17965. }
  17966. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17967. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17968. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17969. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17970. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17971. }
  17972. //2.7====================================== Current.Import L3 ==============================================
  17973. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17974. {
  17975. // AC 3 phase L3 current
  17976. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17977. {
  17978. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17979. {
  17980. tempIndex = 2;
  17981. }
  17982. else
  17983. {
  17984. tempIndex = gun_index;
  17985. }
  17986. for (int index = 0; index < AC_QUANTITY; index++)
  17987. {
  17988. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17989. {
  17990. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17991. }
  17992. }// End of for AC_QUANTITY
  17993. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17994. }
  17995. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17996. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17997. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17998. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17999. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18000. }
  18001. //2.9====================================== Voltage L2 ====================================================
  18002. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18003. {
  18004. // AC 3 phase L2 volatge
  18005. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18006. {
  18007. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18008. {
  18009. tempIndex = 2;
  18010. }
  18011. else
  18012. {
  18013. tempIndex = gun_index;
  18014. }
  18015. for (int index = 0; index < AC_QUANTITY; index++)
  18016. {
  18017. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18018. {
  18019. 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
  18020. }
  18021. } // END OF FOR AC_QUANTITY
  18022. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  18023. }
  18024. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18025. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18026. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18027. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18028. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18029. }
  18030. //2.10====================================== Voltage L3 ====================================================
  18031. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18032. {
  18033. // AC 3 phase L3 volatge
  18034. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18035. {
  18036. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18037. {
  18038. tempIndex = 2;
  18039. }
  18040. else
  18041. {
  18042. tempIndex = gun_index;
  18043. }
  18044. for (int index = 0; index < AC_QUANTITY; index++)
  18045. {
  18046. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18047. {
  18048. 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
  18049. }
  18050. } // END OF FOR AC_QUANTITY
  18051. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18052. }
  18053. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18054. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18055. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18056. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18057. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18058. }
  18059. //====================== Start SoC ================================
  18060. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18061. {
  18062. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18063. 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))
  18064. {
  18065. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18066. {
  18067. tempIndex = ((gun_index==2) ? 1: 0);
  18068. }
  18069. else
  18070. {
  18071. tempIndex = gun_index;
  18072. }
  18073. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18074. {
  18075. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18076. {
  18077. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18078. {
  18079. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18080. }
  18081. }
  18082. }
  18083. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18084. {
  18085. for (int index = 0; index < CCS_QUANTITY; index++)
  18086. {
  18087. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18088. {
  18089. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18090. }
  18091. }
  18092. }
  18093. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18094. {
  18095. for (int index = 0; index < GB_QUANTITY; index++)
  18096. {
  18097. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18098. {
  18099. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18100. }
  18101. }
  18102. }
  18103. else if(gunType[gun_index] == GUN_TYPE_DO)
  18104. {
  18105. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18106. {
  18107. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18108. {
  18109. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18110. }
  18111. }
  18112. }
  18113. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18114. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18115. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18116. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18117. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18118. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18119. } // END FOR DC CASE
  18120. }
  18121. //======================================== Message create ==============================================
  18122. json_object *StopTransaction = json_object_new_object();
  18123. json_object *transactionDatas = json_object_new_array();
  18124. json_object *sampledValues = json_object_new_array();
  18125. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  18126. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  18127. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  18128. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  18129. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  18130. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18131. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  18132. {
  18133. json_object *transactionData = json_object_new_object();
  18134. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18135. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18136. {
  18137. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18138. {
  18139. json_object *sampledValue = json_object_new_object();
  18140. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18141. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18142. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18143. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18144. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18145. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18146. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18147. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18148. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18149. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18150. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18151. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18152. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18153. json_object_array_add(sampledValues, sampledValue);
  18154. }
  18155. }
  18156. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18157. json_object_array_add(transactionDatas, transactionData);
  18158. }
  18159. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18160. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18161. ,MESSAGE_TYPE_CALL
  18162. ,guid
  18163. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18164. json_object_put(StopTransaction);
  18165. // Check File "TempStopTransaction" Exist
  18166. if((access(TempStopTransaction,F_OK))!=-1)
  18167. {
  18168. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18169. fclose(fopen(TempStopTransaction, "w"));
  18170. }
  18171. else
  18172. {
  18173. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18174. FILE *log = fopen(TempStopTransaction, "w+");
  18175. if(log == NULL)
  18176. {
  18177. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18178. return ;
  18179. }
  18180. else
  18181. {
  18182. fclose(log);
  18183. }
  18184. }
  18185. //Add TempStopTransaction | Update TempStopTransaction
  18186. // open file for writing
  18187. FILE *outfile;
  18188. outfile = fopen (TempStopTransaction, "a");
  18189. //DEBUG_INFO("data = %s\n", queuedata);
  18190. fputs(queuedata, outfile);
  18191. fputs("\n", outfile);
  18192. fclose (outfile);
  18193. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18194. OCPP_updatePeriodEnergy(gun_index);
  18195. }
  18196. void checkTempStopTransaction(int gun_index)
  18197. {
  18198. FILE *fptr1;
  18199. char ch;
  18200. char str[QUEUE_MESSAGE_LENGTH]={0};
  18201. char guid[37]={0};
  18202. char tempdata[65]={0};
  18203. char connectorStr[2]={0};
  18204. char TempStopTransaction[256];
  18205. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18206. fptr1 = fopen(TempStopTransaction, "r");
  18207. //TempStopTransaction格式: 槍號,StopTransaction封包
  18208. if (!fptr1)
  18209. {
  18210. //printf(" File not found or unable to open the input file!!\n");
  18211. return ;
  18212. }
  18213. ch=fgetc(fptr1);
  18214. //printf(" Now the content of the file %s is : \n",fname);
  18215. rewind(fptr1);
  18216. if(ch!=EOF)
  18217. {
  18218. // copy all contents to the temporary file except the specific line
  18219. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18220. {
  18221. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18222. if(str[0]=='\0')
  18223. {
  18224. break;
  18225. }
  18226. //TempStopTransaction格式: 槍號,StopTransaction封包
  18227. strncpy(connectorStr, str, 1);
  18228. if(atoi(connectorStr) != (gun_index+1))
  18229. {
  18230. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18231. fclose(fptr1);
  18232. return ;
  18233. }
  18234. //random_uuid(guid);
  18235. strncpy(guid, str+6, 36); //copy guid
  18236. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18237. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18238. {
  18239. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18240. }
  18241. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18242. OCPP_insert_transaction_msg(NO, str);
  18243. memset(str,0,ARRAY_SIZE(str));
  18244. }
  18245. }
  18246. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18247. fclose(fptr1);
  18248. remove(TempStopTransaction); // remove the original file
  18249. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18250. }
  18251. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18252. {
  18253. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18254. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18255. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18256. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18257. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18258. }
  18259. int GetWebSocketPingInterval(void)
  18260. {
  18261. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18262. }
  18263. int GetServerSign(void)
  18264. {
  18265. return server_sign;
  18266. }
  18267. uint8_t GetOcppSecurityProfile()
  18268. {
  18269. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18270. }
  18271. void GetOcppChargerBoxId(uint8_t *data)
  18272. {
  18273. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18274. }
  18275. void GetOcppSecurityPassword(uint8_t *data)
  18276. {
  18277. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18278. }
  18279. void SetOcppVersion(uint8_t *version)
  18280. {
  18281. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18282. DEBUG_INFO("ocpp version: %s\n", version);
  18283. if(strstr((char*)version, "ocpp1.6") != NULL)
  18284. {
  18285. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18286. }
  18287. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18288. {
  18289. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18290. system("pkill OcppBackend");
  18291. }
  18292. }
  18293. void SetServerSign(int value)
  18294. {
  18295. server_sign = value;
  18296. }
  18297. int GetBootNotificationInterval(void)
  18298. {
  18299. return BootNotificationInterval;
  18300. }
  18301. int GetInternetConn(void)
  18302. {
  18303. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18304. }
  18305. int GetBackendConnectionTimeout(void)
  18306. {
  18307. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18308. }
  18309. int isConnectorInitMode(int gun_index)
  18310. {
  18311. int tempIndex = 0;
  18312. int result = TRUE;
  18313. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18314. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18315. {
  18316. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18317. {
  18318. tempIndex = ((gun_index==2) ? 1: 0);
  18319. }
  18320. else
  18321. {
  18322. tempIndex = gun_index;
  18323. }
  18324. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18325. {
  18326. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18327. {
  18328. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18329. } //end of the same index
  18330. }//end of for CHAdeMO_QUANTITY
  18331. }
  18332. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18333. {
  18334. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18335. {
  18336. tempIndex = ((gun_index==2) ? 1: 0);
  18337. }
  18338. else
  18339. {
  18340. tempIndex = gun_index;
  18341. }
  18342. for (int index = 0; index < CCS_QUANTITY; index++)
  18343. {
  18344. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18345. {
  18346. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18347. } //end of the same index
  18348. } // end of for CCS_QUANTITY
  18349. }
  18350. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18351. {
  18352. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18353. {
  18354. tempIndex = ((gun_index==2) ? 1: 0);
  18355. }
  18356. else
  18357. {
  18358. tempIndex = gun_index;
  18359. }
  18360. for (int index = 0; index < GB_QUANTITY; index++)
  18361. {
  18362. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18363. {
  18364. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18365. } //end of the same index
  18366. } // end of for GB_QUANTITY
  18367. }
  18368. else if(gunType[gun_index] == GUN_TYPE_DO)
  18369. {
  18370. tempIndex = gun_index;
  18371. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18372. {
  18373. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18374. {
  18375. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18376. } //end of the same index
  18377. }
  18378. }
  18379. else
  18380. {
  18381. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18382. {
  18383. tempIndex = 2;
  18384. }
  18385. else
  18386. {
  18387. tempIndex = gun_index;
  18388. }
  18389. for (int index = 0; index < AC_QUANTITY; index++)
  18390. {
  18391. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18392. {
  18393. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18394. }//end of the same index
  18395. }//end of for AC_QUANTITY
  18396. }
  18397. return result;
  18398. }
  18399. void refreshProcDogTimer()
  18400. {
  18401. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  18402. }
  18403. void InitialSystemValue(void)
  18404. {
  18405. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18406. locallistVersion=0;
  18407. BootNotificationInterval = 0;
  18408. authorizeRetryTimes = 0;
  18409. GunStatusInterval = 10;
  18410. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18411. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18412. //Hear Beat
  18413. HeartBeatWithNOResponse = 0;
  18414. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18415. FirstHeartBeat = 0;
  18416. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18417. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18418. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18419. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18420. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18421. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18422. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18423. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18424. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18425. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18426. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18427. //Status && ConnectorPlugIn Setting
  18428. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18429. {
  18430. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18431. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18432. }
  18433. for (int index = 0; index < CCS_QUANTITY; index++)
  18434. {
  18435. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18436. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18437. }
  18438. for (int index = 0; index < GB_QUANTITY; index++)
  18439. {
  18440. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18441. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18442. }
  18443. for (int index = 0; index < AC_QUANTITY; index++)
  18444. {
  18445. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18446. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18447. }
  18448. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18449. {
  18450. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18451. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18452. }
  18453. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18454. {
  18455. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18456. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18457. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18458. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18459. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18460. }
  18461. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18462. refreshStartTimer(&clientTime.Heartbeat);
  18463. sleep(1);
  18464. }
  18465. void LWS_Send(char *str)
  18466. {
  18467. //=====================================================
  18468. // Check InternetConn 0: disconnected, 1: connected
  18469. //====================================================
  18470. if(GetOcppConnStatus() == 0)
  18471. {
  18472. DEBUG_INFO("offline now !!!\n");
  18473. return;
  18474. }
  18475. // Only disable isWebsocketSendable operation initiated by charger
  18476. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18477. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18478. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18479. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18480. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18481. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18482. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18483. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18484. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18485. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18486. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18487. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18488. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18489. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18490. {
  18491. isWebsocketSendable = 0;
  18492. }
  18493. pthread_mutex_lock(&lock_send);
  18494. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18495. sprintf((char *)SendBuffer, "%s", str);
  18496. SendBufLen = strlen(str);
  18497. pthread_mutex_unlock(&lock_send);
  18498. lws_callback_on_writable(wsi_client);
  18499. //lws_service(context, 0);
  18500. //sleep(1);
  18501. }
  18502. void LWS_SendNow(char *str)
  18503. {
  18504. //=====================================================
  18505. // Check InternetConn 0: disconnected, 1: connected
  18506. //====================================================
  18507. if(GetOcppConnStatus() == 0)
  18508. {
  18509. DEBUG_INFO("offline now !!!\n");
  18510. return;
  18511. }
  18512. // Only disable isWebsocketSendable operation initiated by charger
  18513. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18514. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18515. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18516. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18517. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18518. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18519. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18520. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18521. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18522. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18523. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18524. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18525. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18526. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18527. {
  18528. isWebsocketSendable = 0;
  18529. }
  18530. pthread_mutex_lock(&lock_send);
  18531. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18532. sprintf((char *)SendBuffer, "%s", str);
  18533. SendBufLen = strlen(str);
  18534. pthread_mutex_unlock(&lock_send);
  18535. lws_callback_on_writable(wsi_client);
  18536. lws_service(context, 0);
  18537. //sleep(1);
  18538. }