MessageHandler.c 910 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777
  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 HeartBeat Response Not Receive Counts
  81. //============================================
  82. static int HeartBeatWithNOResponse = 0;
  83. extern sqlite3 *db;
  84. int TransactionMessageAttemptsGet(void);
  85. int TransactionMessageRetryIntervalGet(void);
  86. int GetOcppConnStatus(void);
  87. void SetOcppConnStatus(uint8_t status);
  88. int setKeyValue(char *key, char *value);
  89. void OCPP_get_TableAuthlocalAllData(void);
  90. void processUnkownKey(void);
  91. struct InterLock
  92. {
  93. unsigned char isGetDiagnosticGoing:1;
  94. unsigned char isUpdateFirmwareGoing:1;
  95. }interLock;
  96. struct ClientTime
  97. {
  98. struct timespec Heartbeat;
  99. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  100. struct timespec StartTransaction;
  101. struct timespec StopTransaction;
  102. struct timespec MeterValues[CONNECTOR_QUANTITY];
  103. struct timespec RemoteStartWait;
  104. }clientTime;
  105. typedef union
  106. {
  107. //Operations Initiated by Central System
  108. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  109. struct
  110. {
  111. //CsMsgValue[0]
  112. unsigned char StatusNotificationReq:1; //bit 0,
  113. unsigned char StatusNotificationConf:1; //bit 1,
  114. unsigned char TriggerMeterValue:1; //bit 2,
  115. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  116. unsigned char isOnCharging:1; //bit 4,
  117. unsigned char :3; //bit5~7
  118. }bits[CONNECTOR_QUANTITY];
  119. }CpinitiateMsg;
  120. CpinitiateMsg cpinitateMsg;
  121. //GetConfiguration Array
  122. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  123. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  124. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  125. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  126. #if 0
  127. static char *ChargePointErrorCodeStr[] = {
  128. MACROSTR(ConnectorLockFailure),
  129. MACROSTR(EVCommunicationError),
  130. MACROSTR(GroundFailure),
  131. MACROSTR(HighTemperature),
  132. MACROSTR(InternalError),
  133. MACROSTR(LocalListConflict),
  134. MACROSTR(NoError),
  135. MACROSTR(OtherError),
  136. MACROSTR(OverCurrentFailure),
  137. MACROSTR(OverVoltage),
  138. MACROSTR(PowerMeterFailure),
  139. MACROSTR(PowerSwitchFailure),
  140. MACROSTR(ReaderFailure),
  141. MACROSTR(ResetFailure),
  142. MACROSTR(UnderVoltage),
  143. MACROSTR(WeakSignal)
  144. };
  145. #endif
  146. static char * ChargePointStatusStr[] = {
  147. MACROSTR(Available),
  148. MACROSTR(Preparing),
  149. MACROSTR(Charging),
  150. MACROSTR(SuspendedEVSE),
  151. MACROSTR(SuspendedEV),
  152. MACROSTR(Finishing),
  153. MACROSTR(Reserved),
  154. MACROSTR(Unavailable),
  155. MACROSTR(Faulted)
  156. };
  157. static char *RegistrationStatusStr[] = {
  158. MACROSTR(Accepted),
  159. MACROSTR(Pending),
  160. MACROSTR(Rejected)
  161. };
  162. static char *AvailabilityTypeStr[] = {
  163. MACROSTR(Inoperative),
  164. MACROSTR(Operative)
  165. };
  166. static char *AvailabilityStatusStr[] = {
  167. MACROSTR(Accepted),
  168. MACROSTR(Rejected),
  169. MACROSTR(Scheduled)
  170. };
  171. static char *ConfigurationStatusStr[] = {
  172. MACROSTR(Accepted),
  173. MACROSTR(Rejected),
  174. MACROSTR(RebootRequired),
  175. MACROSTR(NotSupported)
  176. };
  177. static char *ClearCacheStatusStr[] = {
  178. MACROSTR(Accepted),
  179. MACROSTR(Rejected)
  180. };
  181. static char *ChargingProfilePurposeTypeStr[] = {
  182. MACROSTR(ChargePointMaxProfile),
  183. MACROSTR(TxDefaultProfile),
  184. MACROSTR(TxProfile)
  185. };
  186. static char *ChargingProfileStatusStr[] = {
  187. MACROSTR(Accepted),
  188. MACROSTR(Rejected),
  189. MACROSTR(NotSupported)
  190. };
  191. static char *ClearChargingProfileStatusStr[] = {
  192. MACROSTR(Accepted),
  193. MACROSTR(Unknown)
  194. };
  195. static char *GetCompositeScheduleStatusStr[] = {
  196. MACROSTR(Accepted),
  197. MACROSTR(Rejected)
  198. };
  199. static char *UpdateTypeStr[] = {
  200. MACROSTR(Differential),
  201. MACROSTR(Full)
  202. };
  203. static char *UpdateStatusStr[] = {
  204. MACROSTR(Accepted),
  205. MACROSTR(Failed),
  206. MACROSTR(NotSupported),
  207. MACROSTR(VersionMismatch)
  208. };
  209. static char *RemoteStartStopStatusStr[] = {
  210. MACROSTR(Accepted),
  211. MACROSTR(Rejected)
  212. };
  213. static char *ReservationStatusStr[] = {
  214. MACROSTR(Accepted),
  215. MACROSTR(Faulted),
  216. MACROSTR(Occupied),
  217. MACROSTR(Rejected),
  218. MACROSTR(Unavailable)
  219. };
  220. static char *ResetTypeStr[] = {
  221. MACROSTR(Hard),
  222. MACROSTR(Soft)
  223. };
  224. static char *ResetStatusStr[] = {
  225. MACROSTR(Accepted),
  226. MACROSTR(Rejected)
  227. };
  228. static char * DiagnosticsStatusStr[] = {
  229. MACROSTR(Idle),
  230. MACROSTR(Uploaded),
  231. MACROSTR(UploadFailed),
  232. MACROSTR(Uploading)
  233. };
  234. static char * FirmwareStatusStr[] = {
  235. MACROSTR(Downloaded),
  236. MACROSTR(DownloadFailed),
  237. MACROSTR(Downloading),
  238. MACROSTR(Idle),
  239. MACROSTR(InstallationFailed),
  240. MACROSTR(Installing),
  241. MACROSTR(Installed)
  242. };
  243. static char * MessageTriggerStr[] = {
  244. MACROSTR(BootNotification),
  245. MACROSTR(DiagnosticsStatusNotification),
  246. MACROSTR(FirmwareStatusNotification),
  247. MACROSTR(Heartbeat),
  248. MACROSTR(MeterValues),
  249. MACROSTR(StatusNotification)
  250. };
  251. static char * TriggerMessageStatusStr[] = {
  252. MACROSTR(Accepted),
  253. MACROSTR(Rejected),
  254. MACROSTR(NotImplemented)
  255. };
  256. static char * UnlockStatusStr[] = {
  257. MACROSTR(Unlocked),
  258. MACROSTR(UnlockFailed),
  259. MACROSTR(NotSupported)
  260. };
  261. #if 0
  262. static char * StopTransactionReasonStr[] = {
  263. MACROSTR(EmergencyStop),
  264. MACROSTR(EVDisconnected),
  265. MACROSTR(HardReset),
  266. MACROSTR(Local),
  267. MACROSTR(Other),
  268. MACROSTR(PowerLoss),
  269. MACROSTR(Reboot),
  270. MACROSTR(Remote),
  271. MACROSTR(SoftReset),
  272. MACROSTR(UnlockCommand),
  273. MACROSTR(DeAuthorized)
  274. };
  275. #endif
  276. static char * CancelReservationStatusStr[] = {
  277. MACROSTR(Accepted),
  278. MACROSTR(Rejected)
  279. };
  280. static char * ReadingContextStr[] = {
  281. MACROSTR(Interruption.Begin),
  282. MACROSTR(Interruption.End),
  283. MACROSTR(Other),
  284. MACROSTR(Sample.Clock),
  285. MACROSTR(Sample.Periodic),
  286. MACROSTR(Transaction.Begin),
  287. MACROSTR(Transaction.End),
  288. MACROSTR(Trigger)
  289. };
  290. static char * ValueFormatStr[] = {
  291. MACROSTR(Raw),
  292. MACROSTR(SignedData)
  293. };
  294. static char * MeasurandStr[] = {
  295. MACROSTR(Current.Export),
  296. MACROSTR(Current.Import),
  297. MACROSTR(Current.Offered),
  298. MACROSTR(Energy.Active.Export.Register),
  299. MACROSTR(Energy.Active.Import.Register),
  300. MACROSTR(Energy.Reactive.Export.Register),
  301. MACROSTR(Energy.Reactive.Import.Register),
  302. MACROSTR(Energy.Active.Export.Interval),
  303. MACROSTR(Energy.Active.Import.Interval),
  304. MACROSTR(Energy.Reactive.Export.Interval),
  305. MACROSTR(Energy.Reactive.Import.Interval),
  306. MACROSTR(Frequency),
  307. MACROSTR(Power.Active.Export),
  308. MACROSTR(Power.Active.Import),
  309. MACROSTR(Power.Factor),
  310. MACROSTR(Power.Offered),
  311. MACROSTR(Power.Reactive.ExportMACROSTR),
  312. MACROSTR(Power.Reactive.Import),
  313. MACROSTR(RPM),
  314. MACROSTR(SoC),
  315. MACROSTR(Temperature),
  316. MACROSTR(Voltage)
  317. };
  318. static char * LocationStr[] = {
  319. MACROSTR(Body),
  320. MACROSTR(Cable),
  321. MACROSTR(EV),
  322. MACROSTR(Inlet),
  323. MACROSTR(Outlet)
  324. };
  325. static char * PhaseStr[] = {
  326. MACROSTR(L1),
  327. MACROSTR(L2),
  328. MACROSTR(L3),
  329. MACROSTR(N),
  330. MACROSTR(L1-N),
  331. MACROSTR(L2-N),
  332. MACROSTR(L3-N),
  333. MACROSTR(L1-L2),
  334. MACROSTR(L2-L3),
  335. MACROSTR(L3-L1)
  336. };
  337. static char * UnitOfMeasureStr[] = {
  338. MACROSTR(Wh),
  339. MACROSTR(kWh),
  340. MACROSTR(varh),
  341. MACROSTR(kvarh),
  342. MACROSTR(W),
  343. MACROSTR(kW),
  344. MACROSTR(VA),
  345. MACROSTR(kVA),
  346. MACROSTR(var),
  347. MACROSTR(kvar),
  348. MACROSTR(A),
  349. MACROSTR(V),
  350. MACROSTR(Celsius),
  351. MACROSTR(Fahrenheit),
  352. MACROSTR(K),
  353. MACROSTR(Percent)
  354. };
  355. //=========================================
  356. // TTIA routine
  357. //=========================================
  358. int sendTTIAInfo(uint8_t gun_index)
  359. {
  360. static int sn = 0;
  361. int result = FAIL;
  362. struct hostent *server;
  363. int udp_socket_fd;
  364. struct sockaddr_in dest_addr = {0};
  365. uint8_t tx_buf[80] = {0};
  366. uint8_t logBuf[256]= {0};
  367. uint8_t tx_len, tempIndex, socStart, socEnd;
  368. uint16_t PresentChargedEnergy;
  369. struct tm tmStart, tmEnd;
  370. DEBUG_INFO("sendTTIAInfo...\n");
  371. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  372. {
  373. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  374. {
  375. tempIndex = ((gun_index==2) ? 1: 0);
  376. }
  377. else
  378. {
  379. tempIndex = gun_index;
  380. }
  381. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  382. {
  383. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  384. {
  385. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  386. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  387. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  388. }
  389. }
  390. }
  391. else if(gunType[gun_index] == GUN_TYPE_CCS)
  392. {
  393. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  394. {
  395. tempIndex = ((gun_index==2) ? 1: 0);
  396. }
  397. else
  398. {
  399. tempIndex = gun_index;
  400. }
  401. for (int index = 0; index < CCS_QUANTITY; index++)
  402. {
  403. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  404. {
  405. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  406. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  407. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  408. }
  409. }
  410. }
  411. else if(gunType[gun_index] == GUN_TYPE_GBT)
  412. {
  413. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  414. {
  415. tempIndex = ((gun_index==2) ? 1: 0);
  416. }
  417. else
  418. {
  419. tempIndex = gun_index;
  420. }
  421. for (int index = 0; index < GB_QUANTITY; index++)
  422. {
  423. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  424. {
  425. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  426. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  427. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  428. }
  429. }
  430. }
  431. else if(gunType[gun_index] == GUN_TYPE_DO)
  432. {
  433. tempIndex = gun_index;
  434. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  435. {
  436. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  437. {
  438. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  439. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  440. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  441. }
  442. }
  443. }
  444. else
  445. {
  446. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  447. {
  448. tempIndex = 2;
  449. }
  450. else
  451. {
  452. tempIndex = gun_index;
  453. }
  454. for (int index = 0; index < AC_QUANTITY; index++)
  455. {
  456. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  457. {
  458. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  459. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  460. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  461. }
  462. }// END
  463. }
  464. // Message assembly
  465. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  466. tx_buf[4] = 0x02; // Protocol Version
  467. tx_buf[5] = 0xb0; // Message ID
  468. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  469. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  470. tx_buf[8] = 0x00; // CarID low byte
  471. tx_buf[9] = 0x00; // CarID high byte
  472. tx_buf[10] = 0x00; // ID Storage
  473. tx_buf[11] = 0x00; // Driver lowest byte
  474. tx_buf[12] = 0x00; // Driver 2nd byte
  475. tx_buf[13] = 0x00; // Driver 3rd byte
  476. tx_buf[14] = 0x00; // Driver highest byte
  477. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  478. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  479. tx_buf[17] = 0x00; // Reserve
  480. tx_buf[18] = 60 & 0xff; // Payload length low byte
  481. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  482. // EVSE provider
  483. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  484. // EVSE provider
  485. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  486. // EVSE id
  487. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  488. // Connector id
  489. tx_buf[37] = gun_index;
  490. // EVSE station
  491. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  492. // Vehicle SN
  493. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  494. // Mileage
  495. tx_buf[61] = 0x00; // lowest byte
  496. tx_buf[62] = 0x00; // 2nd byte
  497. tx_buf[63] = 0x00; // highest byte
  498. // Start date time 6 bytes
  499. 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))
  500. {
  501. struct tm *tmTarget;
  502. struct timeb tbTarget;
  503. tmStart.tm_year -= 1900;
  504. tmStart.tm_mon -= 1;
  505. tmStart.tm_gmtoff = 0;
  506. tbTarget.time = mktime(&tmStart);
  507. tbTarget.timezone = 0;
  508. tbTarget.time += (8*3600);
  509. tmTarget = gmtime(&tbTarget.time);
  510. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  511. tx_buf[65] = (tmTarget->tm_mon+1);
  512. tx_buf[66] = tmTarget->tm_mday;
  513. tx_buf[67] = tmTarget->tm_hour;
  514. tx_buf[68] = tmTarget->tm_min;
  515. tx_buf[69] = tmTarget->tm_sec;
  516. }
  517. // Stop date time 6 bytes
  518. 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))
  519. {
  520. struct tm *tmTarget;
  521. struct timeb tbTarget;
  522. tmEnd.tm_year -= 1900;
  523. tmEnd.tm_mon -= 1;
  524. tmEnd.tm_gmtoff = 0;
  525. tbTarget.time = mktime(&tmEnd);
  526. tbTarget.timezone = 0;
  527. tbTarget.time += (8*3600);
  528. tmTarget = gmtime(&tbTarget.time);
  529. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  530. tx_buf[71] = (tmTarget->tm_mon+1);
  531. tx_buf[72] = tmTarget->tm_mday;
  532. tx_buf[73] = tmTarget->tm_hour;
  533. tx_buf[74] = tmTarget->tm_min;
  534. tx_buf[75] = tmTarget->tm_sec;
  535. }
  536. // Session energy 2 bytes
  537. tx_buf[76] = PresentChargedEnergy & 0xff;
  538. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  539. // Start SOC 1 byte
  540. tx_buf[78] = socStart;
  541. // Stop SOC 1 byte
  542. tx_buf[79] = socEnd;
  543. // Open socket
  544. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  545. if(udp_socket_fd == -1)
  546. {
  547. DEBUG_ERROR("UDP socket create failed!\n");
  548. }
  549. else
  550. {
  551. // Get server DNS entry
  552. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  553. if (server == NULL)
  554. {
  555. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  556. }
  557. else
  558. {
  559. // Build the server's Internet address
  560. bzero((char *) &dest_addr, sizeof(dest_addr));
  561. dest_addr.sin_family = AF_INET;
  562. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  563. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  564. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  565. {
  566. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  567. {
  568. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  569. }
  570. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  571. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  572. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  573. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  574. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  575. DEBUG_TTIA_INFO("---------- Header ----------\n");
  576. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  577. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  578. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  579. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  580. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  581. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  582. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  583. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  584. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  585. DEBUG_TTIA_INFO("Len: 0x3C\n");
  586. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  587. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  588. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  589. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  590. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  591. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  592. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  593. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  594. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  595. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  596. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  597. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  598. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  599. DEBUG_TTIA_INFO("=========================================\n");
  600. sn++;
  601. result = PASS;
  602. }
  603. else
  604. {
  605. DEBUG_ERROR("UDP sent out fail.\n");
  606. }
  607. }
  608. }
  609. return result;
  610. }
  611. //=========================================
  612. // Save configuration
  613. //=========================================
  614. int runShellCmd(const char*cmd)
  615. {
  616. int result = FAIL;
  617. char buf[256];
  618. FILE *fp;
  619. fp = popen(cmd, "r");
  620. if(fp != NULL)
  621. {
  622. while(fgets(buf, sizeof(buf), fp) != NULL)
  623. {
  624. DEBUG_INFO("%s\n", buf);
  625. }
  626. result = PASS;
  627. }
  628. pclose(fp);
  629. return result;
  630. }
  631. int StoreUsrConfigData(struct SysConfigData *UsrData)
  632. {
  633. int result = PASS;
  634. int fd,wrd;
  635. unsigned int i,Chk;
  636. unsigned char *ptr, *BufTmp;
  637. int MtdBlockSize = 0x300000;
  638. Chk=0;
  639. ptr=(unsigned char *)UsrData;
  640. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  641. {
  642. memset(BufTmp,0,MtdBlockSize);
  643. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  644. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  645. Chk+=*(BufTmp+i);
  646. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  647. // Output configuration to file.
  648. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  649. if (fd < 0)
  650. {
  651. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  652. free(BufTmp);
  653. return 0;
  654. }
  655. wrd=write(fd, BufTmp, MtdBlockSize);
  656. close(fd);
  657. if(wrd<MtdBlockSize)
  658. {
  659. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  660. free(BufTmp);
  661. return 0;
  662. }
  663. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  664. DEBUG_INFO("Erase /dev/mtd10.\n");
  665. runShellCmd("flash_erase /dev/mtd10 0 0");
  666. DEBUG_INFO("Write /dev/mtd10.\n");
  667. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  668. DEBUG_INFO("Erase /dev/mtd11.\n");
  669. runShellCmd("flash_erase /dev/mtd11 0 0");
  670. DEBUG_INFO("Write /dev/mtd11.\n");
  671. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  672. system("rm -f /mnt/EvseConfig.bin");
  673. DEBUG_INFO("EvseConfig write to flash OK\n");
  674. }
  675. else
  676. {
  677. DEBUG_ERROR("alloc BlockSize NG\r\n");
  678. result = FAIL;
  679. }
  680. if(BufTmp!=NULL)
  681. free(BufTmp);
  682. return result;
  683. }
  684. //=========================================
  685. // Sqlite3 related function
  686. //=========================================
  687. static int selectSqlCount = 0;
  688. static int callback(void *data, int argc, char **argv, char **azColName){
  689. int i;
  690. //printf("%s: ", (const char*)data);
  691. selectSqlCount = argc;
  692. for(i = 0; i<argc; i++){
  693. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  694. }
  695. //printf("\n");
  696. return 0;
  697. }
  698. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  699. //int i;
  700. //printf("%s:\n", (const char*)data);
  701. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  702. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  703. return 0;
  704. }
  705. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  706. //printf("%s:\n", (const char*)data);
  707. //idTag
  708. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  709. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  710. //parentIdTag
  711. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  712. //expir_date
  713. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  714. //status
  715. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  716. //version
  717. if(columenCount > 5)
  718. idTagQuery.listVersionInt = atoi(columnValue[5]);
  719. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  720. return 0;
  721. }
  722. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  723. {
  724. // localversion = argv[5] ? atoi(argv[5]) : 0;
  725. // printf("localversion=%d\n", localversion);
  726. return 0;
  727. }
  728. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  729. {
  730. for (int i = 0; i < n_columns; i++)
  731. {
  732. DEBUG_INFO("%s\t", col_values[i]);
  733. }
  734. DEBUG_INFO("\n");
  735. return 0;
  736. }
  737. int OCPP_cleanLocalCache()
  738. {
  739. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  740. char *errMsg = 0;
  741. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  742. if (SQLITE_OK != rc)
  743. {
  744. DEBUG_INFO("SQL error: %s\n",errMsg);
  745. return FALSE;
  746. }
  747. return TRUE;
  748. }
  749. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  750. {
  751. int isSuccess = TRUE;
  752. int ret = 0;
  753. //const char* data = "Callback function called";
  754. char sql[300];
  755. char zErrMsg[200];
  756. memset(sql, 0, 300);
  757. memset(zErrMsg, 0, 200);
  758. 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);
  759. //* Execute SQL statement */
  760. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  761. if( ret != SQLITE_OK )
  762. {
  763. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  764. isSuccess = FALSE;
  765. }
  766. return isSuccess;
  767. }
  768. void OCPP_getIdTagFromLocalCache(char idTag[])
  769. {
  770. int rc = 0;
  771. char sql[100];
  772. char zErrMsg[100];
  773. memset(sql, 0, 100);
  774. memset(zErrMsg, 0, 100);
  775. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  776. memset(&idTagQuery, 0, sizeof(idTagQuery));
  777. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  778. /* Execute SQL statement */
  779. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  780. if( rc != SQLITE_OK )
  781. {
  782. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  783. }
  784. }
  785. void OCPP_getListVerion()
  786. {
  787. int rc = 0;
  788. // const char* data = "Callback function called";
  789. char sql[100];
  790. char zErrMsg[100];
  791. memset(sql, 0, 100);
  792. memset(zErrMsg, 0, 100);
  793. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  794. /* Execute SQL statement */
  795. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  796. if( rc != SQLITE_OK )
  797. {
  798. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  799. }
  800. }
  801. void OCPP_get_TableAuthlocalAllData(void)
  802. {
  803. int rc = 0;
  804. char sql[100];
  805. char zErrMsg[100];
  806. memset(sql, 0, 100);
  807. memset(zErrMsg, 0, 100);
  808. sprintf(sql,"select * from ocpp_auth_local ");
  809. /* Execute SQL statement */
  810. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  811. if( rc != SQLITE_OK )
  812. {
  813. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  814. }
  815. //return ver;
  816. }
  817. int OCPP_cleanLocalList()
  818. {
  819. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  820. char *errMsg = 0;
  821. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  822. if (SQLITE_OK != rc)
  823. {
  824. DEBUG_INFO("%s\n",errMsg);
  825. return FALSE;
  826. }
  827. return TRUE;
  828. }
  829. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  830. {
  831. int isSuccess = FALSE;
  832. int ret = 0;
  833. //const char* data = "Callback function called";
  834. char sql[300];
  835. char zErrMsg[200];
  836. memset(sql, 0, 300);
  837. memset(zErrMsg, 0, 200);
  838. 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);
  839. //* Execute SQL statement */
  840. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  841. if( ret != SQLITE_OK )
  842. {
  843. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  844. return isSuccess;
  845. }
  846. memset(sql, 0, 300);
  847. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  848. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  849. if( ret != SQLITE_OK )
  850. {
  851. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  852. return isSuccess;
  853. }
  854. isSuccess = TRUE;
  855. return isSuccess;
  856. }
  857. void OCPP_getIdTagFromLocalList(char idTag[])
  858. {
  859. int rc = 0;
  860. // const char* data = "Callback function called";
  861. char sql[100];
  862. char zErrMsg[100];
  863. memset(sql, 0, 100);
  864. memset(zErrMsg, 0, 100);
  865. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  866. memset(&idTagQuery, 0, sizeof(idTagQuery));
  867. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  868. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  869. /* Execute SQL statement */
  870. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  871. if( rc != SQLITE_OK )
  872. {
  873. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  874. }
  875. //return ver;
  876. }
  877. void OCPP_deleteIdTagFromLocalList(char idTag[])
  878. {
  879. //int ver = 0;
  880. //int isSuccess = FALSE;
  881. int rc = 0;
  882. char sql[100];
  883. char zErrMsg[100];
  884. memset(sql, 0, 100);
  885. memset(zErrMsg, 0, 100);
  886. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  887. //* Execute SQL statement */
  888. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  889. if( rc != SQLITE_OK )
  890. {
  891. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  892. }
  893. }
  894. int getCurrentYear()
  895. {
  896. int result = 0;
  897. time_t CurrentTime;
  898. struct tm *tm;
  899. CurrentTime = time(NULL);
  900. tm=localtime(&CurrentTime);
  901. result = (tm->tm_year + 1900);
  902. return result;
  903. }
  904. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  905. {
  906. int result = PASS;
  907. char* errMsg = NULL;
  908. char sqlStr[8192];
  909. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  910. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  911. {
  912. result = FAIL;
  913. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  914. }
  915. 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));
  916. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  917. {
  918. result = FAIL;
  919. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  920. }
  921. return result;
  922. }
  923. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  924. {
  925. int isSuccess = TRUE;
  926. int tempIndex;
  927. json_object *EnergyDataTransfer = json_object_new_object();
  928. json_object *periodEnergys = json_object_new_object();
  929. char sql[1024];
  930. char zErrMsg[200];
  931. memset(sql, 0, ARRAY_SIZE(sql));
  932. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  933. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  934. {
  935. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  936. {
  937. tempIndex = ((gun_index==2) ? 1: 0);
  938. }
  939. else
  940. {
  941. tempIndex = gun_index;
  942. }
  943. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  944. {
  945. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  946. {
  947. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  948. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  949. {
  950. uint8_t period[3];
  951. sprintf((char*)period, "%d", idxPeriod);
  952. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  953. }
  954. json_object_object_add(EnergyDataTransfer, "periodEnergy", json_object_new_string(json_object_to_json_string_ext(periodEnergys, JSON_C_TO_STRING_PLAIN)));
  955. } //end of the same index
  956. }//end of for CHAdeMO_QUANTITY
  957. }
  958. else if(gunType[gun_index] == GUN_TYPE_CCS)
  959. {
  960. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  961. {
  962. tempIndex = ((gun_index==2) ? 1: 0);
  963. }
  964. else
  965. {
  966. tempIndex = gun_index;
  967. }
  968. for (int index = 0; index < CCS_QUANTITY; index++)
  969. {
  970. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  971. {
  972. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  973. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  974. {
  975. uint8_t period[3];
  976. sprintf((char*)period, "%d", idxPeriod);
  977. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  978. }
  979. json_object_object_add(EnergyDataTransfer, "periodEnergy", json_object_new_string(json_object_to_json_string_ext(periodEnergys, JSON_C_TO_STRING_PLAIN)));
  980. } //end of the same index
  981. } // end of for CCS_QUANTITY
  982. }
  983. else if(gunType[gun_index] == GUN_TYPE_GBT)
  984. {
  985. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  986. {
  987. tempIndex = ((gun_index==2) ? 1: 0);
  988. }
  989. else
  990. {
  991. tempIndex = gun_index;
  992. }
  993. for (int index = 0; index < GB_QUANTITY; index++)
  994. {
  995. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  996. {
  997. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  998. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  999. {
  1000. uint8_t period[3];
  1001. sprintf((char*)period, "%d", idxPeriod);
  1002. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1003. }
  1004. json_object_object_add(EnergyDataTransfer, "periodEnergy", json_object_new_string(json_object_to_json_string_ext(periodEnergys, JSON_C_TO_STRING_PLAIN)));
  1005. } //end of the same index
  1006. } // end of for GB_QUANTITY
  1007. }
  1008. else if(gunType[gun_index] == GUN_TYPE_DO)
  1009. {
  1010. tempIndex = gun_index;
  1011. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1012. {
  1013. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1014. {
  1015. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1016. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1017. {
  1018. uint8_t period[3];
  1019. sprintf((char*)period, "%d", idxPeriod);
  1020. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1021. }
  1022. json_object_object_add(EnergyDataTransfer, "periodEnergy", json_object_new_string(json_object_to_json_string_ext(periodEnergys, JSON_C_TO_STRING_PLAIN)));
  1023. } //end of the same index
  1024. }
  1025. }
  1026. else
  1027. {
  1028. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1029. {
  1030. tempIndex = 2;
  1031. }
  1032. else
  1033. {
  1034. tempIndex = gun_index;
  1035. }
  1036. for (int index = 0; index < AC_QUANTITY; index++)
  1037. {
  1038. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1039. {
  1040. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1041. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1042. {
  1043. uint8_t period[3];
  1044. sprintf((char*)period, "%d", idxPeriod);
  1045. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1046. }
  1047. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1048. }//end of the same index
  1049. }//end of for AC_QUANTITY
  1050. }
  1051. 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));
  1052. json_object_put(EnergyDataTransfer);
  1053. //* Execute SQL statement */
  1054. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1055. {
  1056. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1057. isSuccess = FALSE;
  1058. }
  1059. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1060. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1061. {
  1062. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1063. isSuccess = FALSE;
  1064. }
  1065. return isSuccess;
  1066. }
  1067. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1068. {
  1069. int isSuccess = TRUE;
  1070. char sql[512];
  1071. char zErrMsg[200];
  1072. int rows, cols;
  1073. char **resultData;
  1074. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1075. /* Execute SQL statement */
  1076. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1077. {
  1078. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1079. isSuccess = FALSE;
  1080. }
  1081. else
  1082. {
  1083. if((rows > 0) && (atoi(resultData[4]) > 0))
  1084. {
  1085. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1086. }
  1087. else
  1088. {
  1089. DEBUG_WARN("There is not match transaction data.\n");
  1090. isSuccess = FALSE;
  1091. }
  1092. }
  1093. return isSuccess;
  1094. }
  1095. //==========================================
  1096. // Check time passed since today
  1097. //==========================================
  1098. long long DiffTimebWithNow(struct timeb ST)
  1099. {
  1100. //return milli-second
  1101. struct timeb ET;
  1102. long long StartTime,StopTime;
  1103. ftime(&ET);
  1104. StartTime=(long long)ST.time;
  1105. StopTime=(long long)ET.time;
  1106. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1107. }
  1108. int getTimePassSinceToday(uint8_t gun_index)
  1109. {
  1110. int result = -1;
  1111. static time_t lastTime[4];
  1112. time_t t;
  1113. struct tm *tmStartToday;
  1114. struct timeb tbStartToday;
  1115. t=time(NULL);
  1116. if(difftime(t, lastTime[gun_index])>0)
  1117. {
  1118. tmStartToday=localtime(&t);
  1119. tmStartToday->tm_hour = 0;
  1120. tmStartToday->tm_min = 0;
  1121. tmStartToday->tm_sec = 0;
  1122. tbStartToday.time = mktime(tmStartToday);
  1123. tbStartToday.millitm = 0;
  1124. result = DiffTimebWithNow(tbStartToday)/1000;
  1125. lastTime[gun_index] = t;
  1126. }
  1127. return result;
  1128. }
  1129. void getNowDatetime(uint8_t *data)
  1130. {
  1131. time_t t = time(NULL);
  1132. struct tm tm = *localtime(&t);
  1133. 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);
  1134. }
  1135. int syncDateTimeRTC(uint8_t *data)
  1136. {
  1137. struct ParsingResult
  1138. {
  1139. int result;
  1140. int scanedElement;
  1141. int year;
  1142. int month;
  1143. int mday;
  1144. int hour;
  1145. int min;
  1146. int sec;
  1147. int tz_hour;
  1148. int tz_min;
  1149. float minSec;
  1150. }result;
  1151. struct tm tmOrg;
  1152. struct tm *tmTarget;
  1153. struct timeb tbTarget;
  1154. char buf[128];
  1155. memset(&result, 0x00, sizeof(struct ParsingResult));
  1156. result.result = PASS;
  1157. if(strstr((char*)data, ".") != NULL)
  1158. {
  1159. // Original data with mini second
  1160. if(strstr((char*)data, "Z") != NULL)
  1161. {
  1162. // Original data with Z
  1163. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1164. &result.year,
  1165. &result.month,
  1166. &result.mday,
  1167. &result.hour,
  1168. &result.min,
  1169. &result.sec,
  1170. &result.minSec);
  1171. }
  1172. else
  1173. {
  1174. // Original data without Z
  1175. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1176. &result.year,
  1177. &result.month,
  1178. &result.mday,
  1179. &result.hour,
  1180. &result.min,
  1181. &result.sec,
  1182. &result.minSec,
  1183. &result.tz_hour,
  1184. &result.tz_min);
  1185. }
  1186. }
  1187. else
  1188. {
  1189. // Original data without mini second
  1190. if(strstr((char*)data, "Z") != NULL)
  1191. {
  1192. // Original data with Z
  1193. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1194. &result.year,
  1195. &result.month,
  1196. &result.mday,
  1197. &result.hour,
  1198. &result.min,
  1199. &result.sec);
  1200. }
  1201. else
  1202. {
  1203. // Original data without Z
  1204. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1205. &result.year,
  1206. &result.month,
  1207. &result.mday,
  1208. &result.hour,
  1209. &result.min,
  1210. &result.sec,
  1211. &result.tz_hour,
  1212. &result.tz_min);
  1213. }
  1214. }
  1215. tmOrg.tm_year = result.year - 1900;
  1216. tmOrg.tm_mon = result.month - 1;
  1217. tmOrg.tm_mday = result.mday;
  1218. tmOrg.tm_hour = result.hour;
  1219. tmOrg.tm_min = result.min;
  1220. tmOrg.tm_sec = result.sec;
  1221. tmOrg.tm_gmtoff = 0;
  1222. tbTarget.time = mktime(&tmOrg);
  1223. tbTarget.timezone = 0;
  1224. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1225. tmTarget = gmtime(&tbTarget.time);
  1226. 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);
  1227. //DEBUG_INFO(" org date time: %s\n", data);
  1228. //DEBUG_INFO("parse date time: %s\n", buf);
  1229. system(buf);
  1230. system("/sbin/hwclock -w --systohc");
  1231. if(result.scanedElement < 6)
  1232. result.result = FAIL;
  1233. return result.result;
  1234. }
  1235. //==========================================
  1236. // GetCompositeSchedule logic related function
  1237. //==========================================
  1238. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1239. {
  1240. //return milli-second
  1241. unsigned int StartTime,StopTime;
  1242. StartTime=(unsigned int)ST.time;
  1243. StopTime=(unsigned int)ET.time;
  1244. return (StopTime-StartTime);
  1245. }
  1246. int DiffTimebWithNowSec(struct timeb ST)
  1247. {
  1248. //return milli-second
  1249. struct timeb ET;
  1250. unsigned int StartTime,StopTime;
  1251. ftime(&ET);
  1252. StartTime=(unsigned int)ST.time;
  1253. StopTime=(unsigned int)ET.time;
  1254. return (StopTime-StartTime);
  1255. }
  1256. int getStartStop(uint8_t *start, uint8_t *stop)
  1257. {
  1258. int result = -1;
  1259. struct tm tmStart;
  1260. struct timeb tbStart;
  1261. struct tm tmStop;
  1262. struct timeb tbStop;
  1263. 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) &&
  1264. (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))
  1265. {
  1266. //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);
  1267. //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);
  1268. tmStart.tm_year -= 1900;
  1269. tmStart.tm_mon -= 1;
  1270. tbStart.time = mktime(&tmStart);
  1271. tbStart.millitm = 0;
  1272. tmStop.tm_year -= 1900;
  1273. tmStop.tm_mon -= 1;
  1274. tbStop.time = mktime(&tmStop);
  1275. tbStop.millitm = 0;
  1276. result = DiffTimebSec(tbStart, tbStop);
  1277. //DEBUG_INFO("getStartStop(): %d\n", result);
  1278. }
  1279. else
  1280. {
  1281. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1282. }
  1283. return result;
  1284. }
  1285. int isOvertNow(uint8_t *start)
  1286. {
  1287. int result = NO;
  1288. struct ParsingResult
  1289. {
  1290. int result;
  1291. int scanedElement;
  1292. int year;
  1293. int month;
  1294. int mday;
  1295. int hour;
  1296. int min;
  1297. int sec;
  1298. int tz_hour;
  1299. int tz_min;
  1300. float minSec;
  1301. }parsingResult;
  1302. struct tm tmStart;
  1303. struct timeb tbStart;
  1304. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1305. if(strstr((char*)start, ".") != NULL)
  1306. {
  1307. // Original data with mini second
  1308. if(strstr((char*)start, "Z") != NULL)
  1309. {
  1310. // Original data with Z
  1311. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1312. &parsingResult.year,
  1313. &parsingResult.month,
  1314. &parsingResult.mday,
  1315. &parsingResult.hour,
  1316. &parsingResult.min,
  1317. &parsingResult.sec,
  1318. &parsingResult.minSec);
  1319. }
  1320. else
  1321. {
  1322. // Original data without Z
  1323. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1324. &parsingResult.year,
  1325. &parsingResult.month,
  1326. &parsingResult.mday,
  1327. &parsingResult.hour,
  1328. &parsingResult.min,
  1329. &parsingResult.sec,
  1330. &parsingResult.minSec,
  1331. &parsingResult.tz_hour,
  1332. &parsingResult.tz_min);
  1333. }
  1334. }
  1335. else
  1336. {
  1337. // Original data without mini second
  1338. if(strstr((char*)start, "Z") != NULL)
  1339. {
  1340. // Original data with Z
  1341. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1342. &parsingResult.year,
  1343. &parsingResult.month,
  1344. &parsingResult.mday,
  1345. &parsingResult.hour,
  1346. &parsingResult.min,
  1347. &parsingResult.sec);
  1348. }
  1349. else
  1350. {
  1351. // Original data without Z
  1352. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1353. &parsingResult.year,
  1354. &parsingResult.month,
  1355. &parsingResult.mday,
  1356. &parsingResult.hour,
  1357. &parsingResult.min,
  1358. &parsingResult.sec,
  1359. &parsingResult.tz_hour,
  1360. &parsingResult.tz_min);
  1361. }
  1362. }
  1363. if(parsingResult.scanedElement >= 6)
  1364. {
  1365. tmStart.tm_year = parsingResult.year - 1900;
  1366. tmStart.tm_mon = parsingResult.month - 1;
  1367. tmStart.tm_mday = parsingResult.mday;
  1368. tmStart.tm_hour = parsingResult.hour;
  1369. tmStart.tm_min = parsingResult.min;
  1370. tmStart.tm_sec = parsingResult.sec;
  1371. tmStart.tm_gmtoff = 0;
  1372. tbStart.time = mktime(&tmStart);
  1373. tbStart.timezone = 0;
  1374. tbStart.millitm = 0;
  1375. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1376. if(DiffTimebWithNowSec(tbStart) <= 0)
  1377. result = NO;
  1378. else
  1379. result = YES;
  1380. }
  1381. else
  1382. {
  1383. DEBUG_WARN("Start date parsing error.\n");
  1384. }
  1385. return result;
  1386. }
  1387. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1388. {
  1389. int result = -1;
  1390. struct tm tmStart;
  1391. struct timeb tbStart;
  1392. struct tm tmStop;
  1393. struct timeb tbStop;
  1394. 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) &&
  1395. (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))
  1396. {
  1397. tmStart.tm_year -= 1900;
  1398. tmStart.tm_mon -= 1;
  1399. tbStart.time = mktime(&tmStart);
  1400. tbStart.millitm = 0;
  1401. tmStop.tm_year -= 1900;
  1402. tmStop.tm_mon -= 1;
  1403. tbStop.time = mktime(&tmStop);
  1404. tbStop.millitm = 0;
  1405. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1406. }
  1407. return result;
  1408. }
  1409. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1410. {
  1411. FILE *fp;
  1412. char profileFileName[128];
  1413. char *line = NULL;
  1414. size_t len = 0;
  1415. time_t CurrentTime;
  1416. struct tm *tmComposite;
  1417. struct StructChargingProfile maxProfile;
  1418. uint8_t limitMax=0;
  1419. int compositePeriodIdx = 0;
  1420. CurrentTime = time(NULL);
  1421. tmComposite=localtime(&CurrentTime);
  1422. 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);
  1423. if(isUnitA)
  1424. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1425. else
  1426. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1427. compositeProfile->ChargingSchedule.Duration = durationReq;
  1428. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1429. {
  1430. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1431. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1432. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1433. }
  1434. compositeProfile->ChargingProfileId = 0;
  1435. compositeProfile->StackLevel = 99 ;
  1436. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1437. maxProfile.ChargingProfileId = -1;
  1438. maxProfile.ChargingSchedule.Duration = -1;
  1439. system("rm -f /tmp/*.json");
  1440. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1441. // Search max profile
  1442. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1443. if((access(profileFileName, F_OK))!=-1)
  1444. {
  1445. fp = fopen(profileFileName, "r");
  1446. while(getline(&line, &len, fp) != -1)
  1447. {
  1448. json_object *obj = NULL;
  1449. obj = json_tokener_parse(line);
  1450. if(is_error(obj))
  1451. {
  1452. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1453. }
  1454. else
  1455. {
  1456. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1457. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1458. )
  1459. {
  1460. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1461. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1462. )
  1463. {
  1464. struct tm tmFrom, tmTo;
  1465. struct timeb tbFrom, tbTo;
  1466. 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) &&
  1467. (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))
  1468. {
  1469. tmFrom.tm_year -= 1900;
  1470. tmFrom.tm_mon -= 1;
  1471. tbFrom.time = mktime(&tmFrom);
  1472. tmTo.tm_year -= 1900;
  1473. tmTo.tm_mon -= 1;
  1474. tbTo.time = mktime(&tmTo);
  1475. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1476. {
  1477. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1478. {
  1479. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1480. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1481. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1482. }
  1483. maxProfile.ChargingProfileId = -1;
  1484. maxProfile.StackLevel = -1;
  1485. if(maxProfile.ChargingProfileId == -1)
  1486. DEBUG_INFO("MaxProfile found.\n");
  1487. else
  1488. DEBUG_INFO("MaxProfile updated.\n");
  1489. // Required item
  1490. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1491. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1492. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1493. if(isUnitA)
  1494. {
  1495. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1496. 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++)
  1497. {
  1498. 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"));
  1499. 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?
  1500. 3:
  1501. 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")));
  1502. 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")));
  1503. }
  1504. }
  1505. else
  1506. {
  1507. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1508. 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++)
  1509. {
  1510. 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"));
  1511. 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?
  1512. 3:
  1513. 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")));
  1514. 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));
  1515. }
  1516. }
  1517. // Optional item
  1518. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1519. {
  1520. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1521. }
  1522. else
  1523. {
  1524. sprintf((char*)maxProfile.ValidFrom, " ");
  1525. }
  1526. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1527. {
  1528. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1529. }
  1530. else
  1531. {
  1532. sprintf((char*)maxProfile.ValidTo, " ");
  1533. }
  1534. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1535. {
  1536. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1537. }
  1538. else
  1539. {
  1540. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1541. }
  1542. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1543. {
  1544. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1545. }
  1546. else
  1547. {
  1548. maxProfile.TransactionId = -1;
  1549. }
  1550. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1551. {
  1552. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1553. }
  1554. else
  1555. {
  1556. maxProfile.ChargingSchedule.Duration = 86400;
  1557. }
  1558. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1559. {
  1560. 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")));
  1561. }
  1562. else
  1563. {
  1564. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1565. }
  1566. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1567. {
  1568. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1569. }
  1570. else
  1571. {
  1572. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1573. }
  1574. }
  1575. }
  1576. }
  1577. else
  1578. {
  1579. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1580. {
  1581. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1582. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1583. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1584. }
  1585. maxProfile.ChargingProfileId = -1;
  1586. maxProfile.StackLevel = -1;
  1587. if(maxProfile.ChargingProfileId == -1)
  1588. DEBUG_INFO("MaxProfile found.\n");
  1589. else
  1590. DEBUG_INFO("MaxProfile updated.\n");
  1591. // Required item
  1592. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1593. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1594. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1595. if(isUnitA)
  1596. {
  1597. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1598. 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++)
  1599. {
  1600. 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"));
  1601. 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?
  1602. 3:
  1603. 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")));
  1604. 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")));
  1605. }
  1606. }
  1607. else
  1608. {
  1609. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1610. 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++)
  1611. {
  1612. 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"));
  1613. 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?
  1614. 3:
  1615. 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")));
  1616. 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));
  1617. }
  1618. }
  1619. // Optional item
  1620. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1621. {
  1622. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1623. }
  1624. else
  1625. {
  1626. sprintf((char*)maxProfile.ValidFrom, " ");
  1627. }
  1628. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1629. {
  1630. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1631. }
  1632. else
  1633. {
  1634. sprintf((char*)maxProfile.ValidTo, " ");
  1635. }
  1636. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1637. {
  1638. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1639. }
  1640. else
  1641. {
  1642. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1643. }
  1644. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1645. {
  1646. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1647. }
  1648. else
  1649. {
  1650. maxProfile.TransactionId = -1;
  1651. }
  1652. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1653. {
  1654. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1655. }
  1656. else
  1657. {
  1658. maxProfile.ChargingSchedule.Duration = 86400;
  1659. }
  1660. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1661. {
  1662. 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")));
  1663. }
  1664. else
  1665. {
  1666. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1667. }
  1668. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1669. {
  1670. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1671. }
  1672. else
  1673. {
  1674. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1675. }
  1676. }
  1677. }
  1678. }
  1679. json_object_put(obj);
  1680. }
  1681. fclose(fp);
  1682. /*
  1683. if(maxProfile.ChargingProfileId !=-1)
  1684. {
  1685. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1686. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1687. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1688. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1689. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1690. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1691. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1692. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1693. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1694. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1695. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1696. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1697. {
  1698. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1699. {
  1700. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1701. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1702. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1703. }
  1704. }
  1705. }
  1706. else
  1707. DEBUG_INFO("MaxProfile not found.\n");
  1708. DEBUG_INFO("------------------------------------\n");*/
  1709. }
  1710. if(maxProfile.ChargingProfileId != -1)
  1711. {
  1712. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1713. {
  1714. if(maxProfile.ChargingSchedule.Duration != -1)
  1715. {
  1716. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1717. 0:
  1718. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1719. }
  1720. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1721. {
  1722. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1723. {
  1724. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1725. 0:
  1726. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1727. if(idxPeriod > 0)
  1728. {
  1729. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1730. {
  1731. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1732. }
  1733. }
  1734. }
  1735. }
  1736. }
  1737. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1738. {
  1739. if(maxProfile.ChargingSchedule.Duration != -1)
  1740. {
  1741. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1742. }
  1743. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1744. {
  1745. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1746. {
  1747. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1748. if(idxPeriod > 0)
  1749. {
  1750. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1751. {
  1752. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1753. }
  1754. }
  1755. }
  1756. }
  1757. }
  1758. else
  1759. {
  1760. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1761. {
  1762. if(maxProfile.ChargingSchedule.Duration != -1)
  1763. {
  1764. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1765. 0:
  1766. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1767. }
  1768. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1769. {
  1770. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1771. {
  1772. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1773. 0:
  1774. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1775. if(idxPeriod > 0)
  1776. {
  1777. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1778. {
  1779. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1780. }
  1781. }
  1782. }
  1783. }
  1784. }
  1785. else
  1786. {
  1787. if(maxProfile.ChargingSchedule.Duration != -1)
  1788. {
  1789. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1790. 0:
  1791. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1792. }
  1793. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1794. {
  1795. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1796. {
  1797. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1798. 0:
  1799. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1800. if(idxPeriod > 0)
  1801. {
  1802. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1803. {
  1804. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1805. }
  1806. }
  1807. }
  1808. }
  1809. }
  1810. }
  1811. /*
  1812. DEBUG_INFO("MaxProfile after align.\n");
  1813. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1814. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1815. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1816. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1817. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1818. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1819. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1820. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1821. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1822. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1823. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1824. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1825. {
  1826. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1827. {
  1828. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1829. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1830. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1831. }
  1832. }
  1833. DEBUG_INFO("------------------------------------\n");*/
  1834. }
  1835. // Find each profile period quantity
  1836. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1837. {
  1838. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1839. limitMax = idx+1;
  1840. }
  1841. if(maxProfile.ChargingProfileId != -1)
  1842. {
  1843. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1844. {
  1845. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1846. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1847. (maxProfile.ChargingSchedule.Duration > 0))
  1848. {
  1849. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1850. {
  1851. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1852. compositePeriodIdx++;
  1853. }
  1854. else
  1855. {
  1856. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1857. }
  1858. }
  1859. }
  1860. }
  1861. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1862. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1863. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1864. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1865. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1866. {
  1867. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1868. {
  1869. compositeProfile->ChargingProfileId = 1;
  1870. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1871. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1872. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1873. }
  1874. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1875. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1876. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1877. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1878. }
  1879. if(line)
  1880. free(line);
  1881. }
  1882. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1883. {
  1884. FILE *fp;
  1885. char profileFileName[128];
  1886. char *line = NULL;
  1887. size_t len = 0;
  1888. time_t CurrentTime;
  1889. struct tm *tmComposite;
  1890. struct StructChargingProfile maxProfile;
  1891. struct StructChargingProfile defaultTxProfile;
  1892. struct StructChargingProfile txProfile;
  1893. struct StructChargingSchedulePeriod tmpPeriod;
  1894. uint8_t limitMax=0;
  1895. uint8_t limitDef=0;
  1896. uint8_t limitTx=0;
  1897. int compositePeriodIdx = 0;
  1898. CurrentTime = time(NULL);
  1899. tmComposite=localtime(&CurrentTime);
  1900. 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);
  1901. if(isUnitA)
  1902. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1903. else
  1904. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1905. compositeProfile->ChargingSchedule.Duration = durationReq;
  1906. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1907. {
  1908. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1909. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1910. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1911. }
  1912. compositeProfile->ChargingProfileId = 0;
  1913. compositeProfile->StackLevel = 99 ;
  1914. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1915. maxProfile.ChargingProfileId = -1;
  1916. defaultTxProfile.ChargingProfileId = -1;
  1917. txProfile.ChargingProfileId = -1;
  1918. maxProfile.ChargingSchedule.Duration = -1;
  1919. defaultTxProfile.ChargingSchedule.Duration = -1;
  1920. txProfile.ChargingSchedule.Duration = -1;
  1921. system("rm -f /tmp/*.json");
  1922. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1923. /*
  1924. * Search valid charging profile
  1925. */
  1926. //DEBUG_INFO("====================================\n");
  1927. // Search tx profile
  1928. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1929. if((access(profileFileName, F_OK))!=-1)
  1930. {
  1931. fp = fopen(profileFileName, "r");
  1932. while(getline(&line, &len, fp) != -1)
  1933. {
  1934. json_object *obj = NULL;
  1935. obj = json_tokener_parse(line);
  1936. if(is_error(obj))
  1937. {
  1938. DEBUG_ERROR("Parse txProfile from file error.\n");
  1939. }
  1940. else
  1941. {
  1942. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1943. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1944. )
  1945. {
  1946. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1947. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1948. )
  1949. {
  1950. struct tm tmFrom, tmTo;
  1951. struct timeb tbFrom, tbTo;
  1952. 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) &&
  1953. (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))
  1954. {
  1955. tmFrom.tm_year -= 1900;
  1956. tmFrom.tm_mon -= 1;
  1957. tbFrom.time = mktime(&tmFrom);
  1958. tmTo.tm_year -= 1900;
  1959. tmTo.tm_mon -= 1;
  1960. tbTo.time = mktime(&tmTo);
  1961. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1962. {
  1963. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1964. {
  1965. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1966. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1967. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1968. }
  1969. txProfile.ChargingProfileId = -1;
  1970. txProfile.StackLevel = -1;
  1971. if(txProfile.ChargingProfileId == -1)
  1972. DEBUG_INFO("TxProfile found.\n");
  1973. else
  1974. DEBUG_INFO("TxProfile updated.\n");
  1975. // Required item
  1976. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1977. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1978. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1979. if(isUnitA)
  1980. {
  1981. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1982. 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++)
  1983. {
  1984. 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"));
  1985. 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?
  1986. 3:
  1987. 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")));
  1988. 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")));
  1989. }
  1990. }
  1991. else
  1992. {
  1993. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1994. 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++)
  1995. {
  1996. 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"));
  1997. 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?
  1998. 3:
  1999. 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")));
  2000. 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));
  2001. }
  2002. }
  2003. // Optional item
  2004. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2005. {
  2006. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2007. }
  2008. else
  2009. {
  2010. sprintf((char*)txProfile.ValidFrom, " ");
  2011. }
  2012. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2013. {
  2014. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2015. }
  2016. else
  2017. {
  2018. sprintf((char*)txProfile.ValidTo, " ");
  2019. }
  2020. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2021. {
  2022. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2023. }
  2024. else
  2025. {
  2026. sprintf((char*)txProfile.RecurrencyKind, " ");
  2027. }
  2028. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2029. {
  2030. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2031. }
  2032. else
  2033. {
  2034. txProfile.TransactionId = -1;
  2035. }
  2036. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2037. {
  2038. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2039. }
  2040. else
  2041. {
  2042. txProfile.ChargingSchedule.Duration = 86400;
  2043. }
  2044. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2045. {
  2046. 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")));
  2047. }
  2048. else
  2049. {
  2050. 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));
  2051. }
  2052. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2053. {
  2054. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2055. }
  2056. else
  2057. {
  2058. txProfile.ChargingSchedule.MinChargingRate = -1;
  2059. }
  2060. }
  2061. }
  2062. }
  2063. else
  2064. {
  2065. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2066. {
  2067. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2068. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2069. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2070. }
  2071. txProfile.ChargingProfileId = -1;
  2072. txProfile.StackLevel = -1;
  2073. if(txProfile.ChargingProfileId == -1)
  2074. DEBUG_INFO("TxProfile found.\n");
  2075. else
  2076. DEBUG_INFO("TxProfile updated.\n");
  2077. // Required item
  2078. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2079. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2080. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2081. if(isUnitA)
  2082. {
  2083. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2084. 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++)
  2085. {
  2086. 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"));
  2087. 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?
  2088. 3:
  2089. 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")));
  2090. 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")));
  2091. }
  2092. }
  2093. else
  2094. {
  2095. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2096. 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++)
  2097. {
  2098. 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"));
  2099. 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?
  2100. 3:
  2101. 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")));
  2102. 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));
  2103. }
  2104. }
  2105. // Optional item
  2106. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2107. {
  2108. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2109. }
  2110. else
  2111. {
  2112. sprintf((char*)txProfile.ValidFrom, " ");
  2113. }
  2114. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2115. {
  2116. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2117. }
  2118. else
  2119. {
  2120. sprintf((char*)txProfile.ValidTo, " ");
  2121. }
  2122. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2123. {
  2124. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2125. }
  2126. else
  2127. {
  2128. sprintf((char*)txProfile.RecurrencyKind, " ");
  2129. }
  2130. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2131. {
  2132. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2133. }
  2134. else
  2135. {
  2136. txProfile.TransactionId = -1;
  2137. }
  2138. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2139. {
  2140. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2141. }
  2142. else
  2143. {
  2144. txProfile.ChargingSchedule.Duration = 86400;
  2145. }
  2146. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2147. {
  2148. 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")));
  2149. }
  2150. else
  2151. {
  2152. 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));
  2153. }
  2154. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2155. {
  2156. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2157. }
  2158. else
  2159. {
  2160. txProfile.ChargingSchedule.MinChargingRate = -1;
  2161. }
  2162. }
  2163. }
  2164. }
  2165. json_object_put(obj);
  2166. }
  2167. fclose(fp);
  2168. /*
  2169. if(txProfile.ChargingProfileId != -1)
  2170. {
  2171. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2172. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2173. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2174. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2175. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2176. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2177. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2178. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2179. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2180. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2181. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2182. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2183. {
  2184. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2185. {
  2186. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2187. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2188. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2189. }
  2190. }
  2191. }
  2192. else
  2193. DEBUG_INFO("TxProfile not found.\n");*/
  2194. }
  2195. // Search default tx profile
  2196. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2197. if((access(profileFileName, F_OK))==-1)
  2198. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2199. if((access(profileFileName, F_OK))!=-1)
  2200. {
  2201. fp = fopen(profileFileName, "r");
  2202. while(getline(&line, &len, fp) != -1)
  2203. {
  2204. json_object *obj = NULL;
  2205. obj = json_tokener_parse(line);
  2206. if(is_error(obj))
  2207. {
  2208. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2209. }
  2210. else
  2211. {
  2212. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2213. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2214. )
  2215. {
  2216. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2217. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2218. )
  2219. {
  2220. struct tm tmFrom, tmTo;
  2221. struct timeb tbFrom, tbTo;
  2222. 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) &&
  2223. (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))
  2224. {
  2225. tmFrom.tm_year -= 1900;
  2226. tmFrom.tm_mon -= 1;
  2227. tbFrom.time = mktime(&tmFrom);
  2228. tmTo.tm_year -= 1900;
  2229. tmTo.tm_mon -= 1;
  2230. tbTo.time = mktime(&tmTo);
  2231. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2232. {
  2233. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2234. {
  2235. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2236. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2237. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2238. }
  2239. defaultTxProfile.ChargingProfileId = -1;
  2240. defaultTxProfile.StackLevel = -1;
  2241. if(defaultTxProfile.ChargingProfileId == -1)
  2242. DEBUG_INFO("TxDefaultProfile found.\n");
  2243. else
  2244. DEBUG_INFO("TxDefaultProfile updated.\n");
  2245. // Required item
  2246. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2247. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2248. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2249. if(isUnitA)
  2250. {
  2251. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2252. 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++)
  2253. {
  2254. 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"));
  2255. 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?
  2256. 3:
  2257. 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")));
  2258. 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")));
  2259. }
  2260. }
  2261. else
  2262. {
  2263. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2264. 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++)
  2265. {
  2266. 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"));
  2267. 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?
  2268. 3:
  2269. 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")));
  2270. 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));
  2271. }
  2272. }
  2273. // Optional item
  2274. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2275. {
  2276. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2277. }
  2278. else
  2279. {
  2280. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2281. }
  2282. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2283. {
  2284. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2285. }
  2286. else
  2287. {
  2288. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2289. }
  2290. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2291. {
  2292. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2293. }
  2294. else
  2295. {
  2296. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2297. }
  2298. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2299. {
  2300. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2301. }
  2302. else
  2303. {
  2304. defaultTxProfile.TransactionId = -1;
  2305. }
  2306. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2307. {
  2308. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2309. }
  2310. else
  2311. {
  2312. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2313. }
  2314. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2315. {
  2316. 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")));
  2317. }
  2318. else
  2319. {
  2320. 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));
  2321. }
  2322. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2323. {
  2324. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2325. }
  2326. else
  2327. {
  2328. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2329. }
  2330. }
  2331. }
  2332. }
  2333. else
  2334. {
  2335. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2336. {
  2337. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2338. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2339. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2340. }
  2341. defaultTxProfile.ChargingProfileId = -1;
  2342. defaultTxProfile.StackLevel = -1;
  2343. if(defaultTxProfile.ChargingProfileId == -1)
  2344. DEBUG_INFO("TxDefaultProfile found.\n");
  2345. else
  2346. DEBUG_INFO("TxDefaultProfile updated.\n");
  2347. // Required item
  2348. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2349. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2350. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2351. if(isUnitA)
  2352. {
  2353. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2354. 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++)
  2355. {
  2356. 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"));
  2357. 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?
  2358. 3:
  2359. 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")));
  2360. 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")));
  2361. }
  2362. }
  2363. else
  2364. {
  2365. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2366. 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++)
  2367. {
  2368. 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"));
  2369. 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?
  2370. 3:
  2371. 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")));
  2372. 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));
  2373. }
  2374. }
  2375. // Optional item
  2376. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2377. {
  2378. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2379. }
  2380. else
  2381. {
  2382. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2383. }
  2384. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2385. {
  2386. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2387. }
  2388. else
  2389. {
  2390. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2391. }
  2392. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2393. {
  2394. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2395. }
  2396. else
  2397. {
  2398. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2399. }
  2400. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2401. {
  2402. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2403. }
  2404. else
  2405. {
  2406. defaultTxProfile.TransactionId = -1;
  2407. }
  2408. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2409. {
  2410. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2411. }
  2412. else
  2413. {
  2414. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2415. }
  2416. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2417. {
  2418. 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")));
  2419. }
  2420. else
  2421. {
  2422. 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));
  2423. }
  2424. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2425. {
  2426. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2427. }
  2428. else
  2429. {
  2430. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2431. }
  2432. }
  2433. }
  2434. }
  2435. json_object_put(obj);
  2436. }
  2437. fclose(fp);
  2438. /*
  2439. if(defaultTxProfile.ChargingProfileId != -1)
  2440. {
  2441. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2442. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2443. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2444. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2445. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2446. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2447. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2448. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2449. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2450. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2451. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2452. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2453. {
  2454. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2455. {
  2456. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2457. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2458. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2459. }
  2460. }
  2461. }
  2462. else
  2463. DEBUG_INFO("TxDefaultProfile not found.\n");
  2464. DEBUG_INFO("------------------------------------\n");*/
  2465. }
  2466. // Search max profile
  2467. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2468. if((access(profileFileName, F_OK))!=-1)
  2469. {
  2470. fp = fopen(profileFileName, "r");
  2471. while(getline(&line, &len, fp) != -1)
  2472. {
  2473. json_object *obj = NULL;
  2474. obj = json_tokener_parse(line);
  2475. if(is_error(obj))
  2476. {
  2477. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2478. }
  2479. else
  2480. {
  2481. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2482. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2483. )
  2484. {
  2485. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2486. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2487. )
  2488. {
  2489. struct tm tmFrom, tmTo;
  2490. struct timeb tbFrom, tbTo;
  2491. 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) &&
  2492. (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))
  2493. {
  2494. tmFrom.tm_year -= 1900;
  2495. tmFrom.tm_mon -= 1;
  2496. tbFrom.time = mktime(&tmFrom);
  2497. tmTo.tm_year -= 1900;
  2498. tmTo.tm_mon -= 1;
  2499. tbTo.time = mktime(&tmTo);
  2500. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2501. {
  2502. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2503. {
  2504. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2505. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2506. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2507. }
  2508. maxProfile.ChargingProfileId = -1;
  2509. maxProfile.StackLevel = -1;
  2510. if(maxProfile.ChargingProfileId == -1)
  2511. DEBUG_INFO("MaxProfile found.\n");
  2512. else
  2513. DEBUG_INFO("MaxProfile updated.\n");
  2514. // Required item
  2515. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2516. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2517. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2518. if(isUnitA)
  2519. {
  2520. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2521. 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++)
  2522. {
  2523. 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"));
  2524. 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?
  2525. 3:
  2526. 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")));
  2527. 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")));
  2528. }
  2529. }
  2530. else
  2531. {
  2532. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2533. 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++)
  2534. {
  2535. 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"));
  2536. 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?
  2537. 3:
  2538. 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")));
  2539. 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));
  2540. }
  2541. }
  2542. // Optional item
  2543. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2544. {
  2545. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2546. }
  2547. else
  2548. {
  2549. sprintf((char*)maxProfile.ValidFrom, " ");
  2550. }
  2551. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2552. {
  2553. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2554. }
  2555. else
  2556. {
  2557. sprintf((char*)maxProfile.ValidTo, " ");
  2558. }
  2559. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2560. {
  2561. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2562. }
  2563. else
  2564. {
  2565. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2566. }
  2567. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2568. {
  2569. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2570. }
  2571. else
  2572. {
  2573. maxProfile.TransactionId = -1;
  2574. }
  2575. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2576. {
  2577. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2578. }
  2579. else
  2580. {
  2581. maxProfile.ChargingSchedule.Duration = 86400;
  2582. }
  2583. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2584. {
  2585. 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")));
  2586. }
  2587. else
  2588. {
  2589. 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));
  2590. }
  2591. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2592. {
  2593. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2594. }
  2595. else
  2596. {
  2597. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2598. }
  2599. }
  2600. }
  2601. }
  2602. else
  2603. {
  2604. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2605. {
  2606. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2607. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2608. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2609. }
  2610. maxProfile.ChargingProfileId = -1;
  2611. maxProfile.StackLevel = -1;
  2612. if(maxProfile.ChargingProfileId == -1)
  2613. DEBUG_INFO("MaxProfile found.\n");
  2614. else
  2615. DEBUG_INFO("MaxProfile updated.\n");
  2616. // Required item
  2617. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2618. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2619. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2620. if(isUnitA)
  2621. {
  2622. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2623. 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++)
  2624. {
  2625. 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"));
  2626. 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?
  2627. 3:
  2628. 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")));
  2629. 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")));
  2630. }
  2631. }
  2632. else
  2633. {
  2634. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2635. 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++)
  2636. {
  2637. 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"));
  2638. 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?
  2639. 3:
  2640. 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")));
  2641. 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));
  2642. }
  2643. }
  2644. // Optional item
  2645. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2646. {
  2647. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2648. }
  2649. else
  2650. {
  2651. sprintf((char*)maxProfile.ValidFrom, " ");
  2652. }
  2653. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2654. {
  2655. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2656. }
  2657. else
  2658. {
  2659. sprintf((char*)maxProfile.ValidTo, " ");
  2660. }
  2661. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2662. {
  2663. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2664. }
  2665. else
  2666. {
  2667. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2668. }
  2669. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2670. {
  2671. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2672. }
  2673. else
  2674. {
  2675. maxProfile.TransactionId = -1;
  2676. }
  2677. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2678. {
  2679. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2680. }
  2681. else
  2682. {
  2683. maxProfile.ChargingSchedule.Duration = 86400;
  2684. }
  2685. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2686. {
  2687. 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")));
  2688. }
  2689. else
  2690. {
  2691. 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));
  2692. }
  2693. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2694. {
  2695. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2696. }
  2697. else
  2698. {
  2699. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2700. }
  2701. }
  2702. }
  2703. }
  2704. json_object_put(obj);
  2705. }
  2706. fclose(fp);
  2707. /*
  2708. if(maxProfile.ChargingProfileId !=-1)
  2709. {
  2710. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2711. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2712. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2713. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2714. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2715. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2716. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2717. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2718. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2719. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2720. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2721. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2722. {
  2723. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2724. {
  2725. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2726. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2727. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2728. }
  2729. }
  2730. }
  2731. else
  2732. DEBUG_INFO("MaxProfile not found.\n");
  2733. DEBUG_INFO("------------------------------------\n");*/
  2734. }
  2735. /*
  2736. * Align found profile start schedule & periods
  2737. */
  2738. //DEBUG_INFO("====================================\n");
  2739. /*
  2740. // For local test usage, force modify found profile start schedule info
  2741. 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);
  2742. 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);
  2743. 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);
  2744. */
  2745. if(txProfile.ChargingProfileId != -1)
  2746. {
  2747. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2748. {
  2749. if(txProfile.ChargingSchedule.Duration != -1)
  2750. {
  2751. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2752. 0:
  2753. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2754. }
  2755. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2756. {
  2757. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2758. {
  2759. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2760. 0:
  2761. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2762. if(idxPeriod > 0)
  2763. {
  2764. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2765. {
  2766. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2767. }
  2768. }
  2769. }
  2770. }
  2771. }
  2772. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2773. {
  2774. if(txProfile.ChargingSchedule.Duration != -1)
  2775. {
  2776. 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?
  2777. 0:
  2778. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2779. }
  2780. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2781. {
  2782. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2783. {
  2784. 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?
  2785. 0:
  2786. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2787. if(idxPeriod > 0)
  2788. {
  2789. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2790. {
  2791. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2792. }
  2793. }
  2794. }
  2795. }
  2796. }
  2797. else
  2798. {
  2799. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2800. {
  2801. if(txProfile.ChargingSchedule.Duration != -1)
  2802. {
  2803. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2804. 0:
  2805. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2806. }
  2807. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2808. {
  2809. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2810. {
  2811. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2812. 0:
  2813. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2814. if(idxPeriod > 0)
  2815. {
  2816. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2817. {
  2818. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2819. }
  2820. }
  2821. }
  2822. }
  2823. }
  2824. else
  2825. {
  2826. if(txProfile.ChargingSchedule.Duration != -1)
  2827. {
  2828. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2829. 0:
  2830. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2831. }
  2832. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2833. {
  2834. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2835. {
  2836. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2837. 0:
  2838. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2839. if(idxPeriod > 0)
  2840. {
  2841. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2842. {
  2843. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2844. }
  2845. }
  2846. }
  2847. }
  2848. }
  2849. }
  2850. /*
  2851. DEBUG_INFO("txProfile after align.\n");
  2852. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2853. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2854. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2855. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2856. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2857. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2858. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2859. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2860. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2861. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2862. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2863. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2864. {
  2865. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2866. {
  2867. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2868. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2869. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2870. }
  2871. }*/
  2872. }
  2873. if(defaultTxProfile.ChargingProfileId != -1)
  2874. {
  2875. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2876. {
  2877. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2878. {
  2879. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2880. 0:
  2881. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2882. }
  2883. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2884. {
  2885. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2886. {
  2887. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2888. 0:
  2889. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2890. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2891. {
  2892. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2893. }
  2894. if(idxPeriod > 0)
  2895. {
  2896. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2897. {
  2898. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2899. }
  2900. }
  2901. }
  2902. }
  2903. }
  2904. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2905. {
  2906. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2907. {
  2908. 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?
  2909. 0:
  2910. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2911. }
  2912. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2913. {
  2914. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2915. {
  2916. 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?
  2917. 0:
  2918. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2919. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2920. {
  2921. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2922. }
  2923. if(idxPeriod > 0)
  2924. {
  2925. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2926. {
  2927. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2928. }
  2929. }
  2930. }
  2931. }
  2932. }
  2933. else
  2934. {
  2935. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2936. {
  2937. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2938. {
  2939. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2940. 0:
  2941. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2942. }
  2943. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2944. {
  2945. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2946. {
  2947. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2948. 0:
  2949. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2950. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2951. {
  2952. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2953. }
  2954. if(idxPeriod > 0)
  2955. {
  2956. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2957. {
  2958. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2959. }
  2960. }
  2961. }
  2962. }
  2963. }
  2964. else
  2965. {
  2966. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2967. {
  2968. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2969. 0:
  2970. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2971. }
  2972. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2973. {
  2974. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2975. {
  2976. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2977. 0:
  2978. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2979. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2980. {
  2981. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2982. }
  2983. if(idxPeriod > 0)
  2984. {
  2985. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2986. {
  2987. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2988. }
  2989. }
  2990. }
  2991. }
  2992. }
  2993. }
  2994. /*
  2995. DEBUG_INFO("defaultTxProfile after align.\n");
  2996. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2997. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2998. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2999. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3000. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3001. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3002. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3003. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3004. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3005. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3006. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3007. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3008. {
  3009. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3010. {
  3011. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3012. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3013. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3014. }
  3015. }
  3016. DEBUG_INFO("------------------------------------\n");*/
  3017. }
  3018. if(maxProfile.ChargingProfileId != -1)
  3019. {
  3020. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3021. {
  3022. if(maxProfile.ChargingSchedule.Duration != -1)
  3023. {
  3024. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  3025. 0:
  3026. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  3027. }
  3028. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3029. {
  3030. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3031. {
  3032. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  3033. 0:
  3034. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  3035. if(idxPeriod > 0)
  3036. {
  3037. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3038. {
  3039. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3040. }
  3041. }
  3042. }
  3043. }
  3044. }
  3045. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3046. {
  3047. if(maxProfile.ChargingSchedule.Duration != -1)
  3048. {
  3049. 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?
  3050. 0:
  3051. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  3052. }
  3053. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3054. {
  3055. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3056. {
  3057. 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?
  3058. 0:
  3059. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  3060. if(idxPeriod > 0)
  3061. {
  3062. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3063. {
  3064. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3065. }
  3066. }
  3067. }
  3068. }
  3069. }
  3070. else
  3071. {
  3072. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3073. {
  3074. if(maxProfile.ChargingSchedule.Duration != -1)
  3075. {
  3076. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  3077. 0:
  3078. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  3079. }
  3080. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3081. {
  3082. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3083. {
  3084. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  3085. 0:
  3086. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  3087. if(idxPeriod > 0)
  3088. {
  3089. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3090. {
  3091. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3092. }
  3093. }
  3094. }
  3095. }
  3096. }
  3097. else
  3098. {
  3099. if(maxProfile.ChargingSchedule.Duration != -1)
  3100. {
  3101. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  3102. 0:
  3103. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  3104. }
  3105. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3106. {
  3107. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3108. {
  3109. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  3110. 0:
  3111. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  3112. if(idxPeriod > 0)
  3113. {
  3114. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3115. {
  3116. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3117. }
  3118. }
  3119. }
  3120. }
  3121. }
  3122. }
  3123. /*
  3124. DEBUG_INFO("MaxProfile after align.\n");
  3125. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3126. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3127. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3128. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3129. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3130. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3131. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3132. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3133. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3134. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3135. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3136. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3137. {
  3138. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3139. {
  3140. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3141. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3142. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3143. }
  3144. }
  3145. DEBUG_INFO("------------------------------------\n");*/
  3146. }
  3147. /*
  3148. * Merge to conposite schedule
  3149. */
  3150. //DEBUG_INFO("====================================\n");
  3151. // Find each profile period quantity
  3152. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3153. {
  3154. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3155. limitMax = idx+1;
  3156. }
  3157. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3158. {
  3159. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3160. limitDef = idx+1;
  3161. }
  3162. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3163. {
  3164. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3165. limitTx = idx+1;
  3166. }
  3167. // TxProfile found, composite schedule based on it
  3168. if(txProfile.ChargingProfileId != -1)
  3169. {
  3170. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3171. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3172. {
  3173. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3174. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3175. (txProfile.ChargingSchedule.Duration > 0))
  3176. {
  3177. if(maxProfile.ChargingProfileId != -1)
  3178. {
  3179. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3180. {
  3181. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3182. {
  3183. if((maxProfile.ChargingSchedule.Duration > 0))
  3184. {
  3185. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3186. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3187. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3188. }
  3189. else
  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;
  3194. }
  3195. }
  3196. if(idxMaxPeriod == (limitMax-1))
  3197. {
  3198. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3199. {
  3200. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3201. {
  3202. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3203. compositePeriodIdx++;
  3204. }
  3205. else
  3206. {
  3207. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3208. }
  3209. }
  3210. }
  3211. }
  3212. }
  3213. else
  3214. {
  3215. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3216. {
  3217. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3218. compositePeriodIdx++;
  3219. }
  3220. else
  3221. {
  3222. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3223. }
  3224. }
  3225. }
  3226. if(idxTxPeriod == (limitTx-1))
  3227. {
  3228. if(defaultTxProfile.ChargingProfileId != -1)
  3229. {
  3230. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  3231. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3232. {
  3233. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3234. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3235. (defaultTxProfile.ChargingSchedule.Duration>0))
  3236. {
  3237. if(maxProfile.ChargingProfileId != -1)
  3238. {
  3239. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3240. {
  3241. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3242. {
  3243. if((maxProfile.ChargingSchedule.Duration > 0))
  3244. {
  3245. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3246. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3247. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3248. }
  3249. else
  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;
  3254. }
  3255. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3256. {
  3257. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3258. {
  3259. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3260. compositePeriodIdx++;
  3261. }
  3262. else
  3263. {
  3264. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3265. }
  3266. }
  3267. // Delete duplicate period
  3268. if(compositePeriodIdx > 1)
  3269. {
  3270. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3271. {
  3272. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3273. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3274. compositePeriodIdx -= 1;
  3275. }
  3276. }
  3277. }
  3278. else
  3279. {
  3280. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3281. {
  3282. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3283. compositePeriodIdx++;
  3284. }
  3285. else
  3286. {
  3287. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3288. }
  3289. break;
  3290. }
  3291. }
  3292. }
  3293. else
  3294. {
  3295. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3296. {
  3297. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3298. compositePeriodIdx++;
  3299. }
  3300. else
  3301. {
  3302. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3303. }
  3304. }
  3305. }
  3306. }
  3307. }
  3308. }
  3309. }
  3310. }
  3311. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3312. else if(defaultTxProfile.ChargingProfileId != -1)
  3313. {
  3314. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3315. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3316. {
  3317. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3318. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3319. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3320. {
  3321. if(maxProfile.ChargingProfileId != -1)
  3322. {
  3323. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3324. {
  3325. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3326. {
  3327. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3328. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3329. if((maxProfile.ChargingSchedule.Duration > 0))
  3330. {
  3331. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3332. }
  3333. else
  3334. {
  3335. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3336. }
  3337. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3338. {
  3339. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3340. {
  3341. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3342. compositePeriodIdx++;
  3343. }
  3344. else
  3345. {
  3346. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3347. }
  3348. }
  3349. // Delete duplicate period
  3350. if(compositePeriodIdx > 1)
  3351. {
  3352. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3353. {
  3354. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3355. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3356. compositePeriodIdx -= 1;
  3357. }
  3358. }
  3359. }
  3360. else
  3361. {
  3362. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3363. {
  3364. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3365. compositePeriodIdx++;
  3366. }
  3367. else
  3368. {
  3369. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3370. }
  3371. break;
  3372. }
  3373. }
  3374. }
  3375. else
  3376. {
  3377. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3378. {
  3379. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3380. compositePeriodIdx++;
  3381. }
  3382. else
  3383. {
  3384. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3385. }
  3386. }
  3387. }
  3388. }
  3389. }
  3390. // Fill other period by MaxProfile
  3391. if(maxProfile.ChargingProfileId != -1)
  3392. {
  3393. if(compositePeriodIdx==0)
  3394. {
  3395. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3396. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3397. {
  3398. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3399. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3400. (maxProfile.ChargingSchedule.Duration > 0))
  3401. {
  3402. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3403. {
  3404. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3405. compositePeriodIdx++;
  3406. }
  3407. else
  3408. {
  3409. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3410. }
  3411. }
  3412. }
  3413. }
  3414. else
  3415. {
  3416. int lastCompositePeriodIdx = compositePeriodIdx;
  3417. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3418. {
  3419. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3420. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3421. (maxProfile.ChargingSchedule.Duration > 0))
  3422. {
  3423. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3424. {
  3425. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3426. {
  3427. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3428. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3429. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3430. }
  3431. else
  3432. {
  3433. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3434. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3435. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3436. }
  3437. }
  3438. if(tmpPeriod.Limit != -1)
  3439. {
  3440. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3441. {
  3442. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3443. {
  3444. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3445. compositePeriodIdx++;
  3446. }
  3447. else
  3448. {
  3449. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3450. }
  3451. }
  3452. // Delete duplicate period
  3453. if(compositePeriodIdx > 1)
  3454. {
  3455. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3456. {
  3457. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3458. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3459. compositePeriodIdx -= 1;
  3460. }
  3461. }
  3462. }
  3463. }
  3464. }
  3465. }
  3466. }
  3467. compositeProfile->ChargingSchedule.Duration = durationReq;
  3468. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3469. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3470. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3471. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3472. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3473. {
  3474. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3475. {
  3476. compositeProfile->ChargingProfileId = 1;
  3477. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3478. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3479. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3480. }
  3481. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3482. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3483. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3484. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3485. }
  3486. if(line)
  3487. free(line);
  3488. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3489. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3490. }
  3491. //==========================================
  3492. // Init all share memory
  3493. //==========================================
  3494. int InitShareMemory()
  3495. {
  3496. int result = PASS;
  3497. int MeterSMId;
  3498. //creat ShmSysConfigAndInfo
  3499. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3500. {
  3501. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3502. result = FAIL;
  3503. }
  3504. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3505. {
  3506. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3507. result = FAIL;
  3508. }
  3509. else
  3510. {}
  3511. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3512. {
  3513. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3514. result = FAIL;
  3515. }
  3516. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3517. {
  3518. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3519. result = FAIL;
  3520. }
  3521. else
  3522. {}
  3523. //creat ShmPsuData
  3524. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3525. {
  3526. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3527. result = FAIL;
  3528. }
  3529. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3530. {
  3531. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3532. result = FAIL;
  3533. }
  3534. else
  3535. {}
  3536. //creat ShmOCPP16Data
  3537. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3538. {
  3539. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3540. result = FAIL;
  3541. }
  3542. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3543. {
  3544. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3545. result = FAIL;
  3546. }
  3547. else
  3548. {}
  3549. /****************************** For Initial Settings************************************************/
  3550. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3551. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3552. // allocate Configuration memory address
  3553. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3554. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3555. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3556. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3557. //offline MeterValue Interval
  3558. TempMeterValueInterval = 0;
  3559. return result;
  3560. }
  3561. int ProcessShareMemory()
  3562. {
  3563. int result = PASS;
  3564. if(InitShareMemory() == FAIL)
  3565. {
  3566. DEBUG_ERROR("InitShareMemory NG\n");
  3567. if(ShmStatusCodeData!=NULL)
  3568. {
  3569. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3570. }
  3571. result = FAIL;
  3572. }
  3573. // Model name parsing
  3574. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3575. {
  3576. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3577. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3578. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3579. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3580. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3581. ) // 'D' means DC
  3582. {
  3583. // DO series
  3584. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3585. {
  3586. SystemInitial += 1;
  3587. gunTotalNumber += 1;
  3588. gunType[gun_index] = GUN_TYPE_DO;
  3589. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3590. {
  3591. case Gun_Type_Chademo:
  3592. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3593. break;
  3594. case Gun_Type_CCS_2:
  3595. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3596. break;
  3597. case Gun_Type_GB:
  3598. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3599. break;
  3600. case Gun_Type_AC:
  3601. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3602. break;
  3603. default:
  3604. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3605. break;
  3606. }
  3607. }
  3608. }
  3609. else
  3610. {
  3611. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3612. {
  3613. SystemInitial += 1;
  3614. gunTotalNumber += 1;
  3615. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3616. {
  3617. case Gun_Type_Chademo:
  3618. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3619. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3620. break;
  3621. case Gun_Type_CCS_2:
  3622. gunType[gun_index] = GUN_TYPE_CCS;
  3623. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3624. break;
  3625. case Gun_Type_GB:
  3626. gunType[gun_index] = GUN_TYPE_GBT;
  3627. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3628. break;
  3629. case Gun_Type_AC:
  3630. gunType[gun_index] = GUN_TYPE_AC;
  3631. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3632. break;
  3633. default:
  3634. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3635. break;
  3636. }
  3637. }
  3638. }
  3639. }
  3640. else
  3641. {
  3642. DEBUG_ERROR("Model name parsing fail.\n");
  3643. result = FAIL;
  3644. }
  3645. if(result != PASS)sleep(5);
  3646. return result;
  3647. }
  3648. void checkRemoteStart(uint8_t connectorIdInt)
  3649. {
  3650. uint8_t tempIndex;
  3651. int result = PASS;
  3652. char cmdBuf[512];
  3653. //check Transaction active
  3654. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3655. {
  3656. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3657. {
  3658. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3659. }
  3660. else
  3661. {
  3662. tempIndex = connectorIdInt -1;
  3663. }
  3664. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3665. {
  3666. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3667. {
  3668. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3669. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3670. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3671. {
  3672. //Reserved
  3673. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3674. }
  3675. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3676. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3677. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3678. {
  3679. //Reserved
  3680. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3681. result = FAIL;
  3682. goto end;
  3683. }
  3684. else
  3685. {
  3686. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3687. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3688. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3689. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3690. {
  3691. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  3692. result = FAIL;
  3693. goto end;
  3694. }
  3695. }//END FOR ELSE
  3696. }
  3697. }// END FOR CHAdeMO_QUANTITY
  3698. }
  3699. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3700. {
  3701. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3702. {
  3703. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3704. }
  3705. else
  3706. {
  3707. tempIndex = connectorIdInt -1;
  3708. }
  3709. for (int index = 0; index < CCS_QUANTITY; index++)
  3710. {
  3711. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3712. {
  3713. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3714. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3715. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3716. {
  3717. //Reserved
  3718. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3719. }
  3720. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3721. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3722. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3723. {
  3724. //Reserved
  3725. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3726. result = FAIL;
  3727. goto end;
  3728. }
  3729. else
  3730. {
  3731. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3732. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3733. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3734. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3735. {
  3736. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3737. result = FAIL;
  3738. goto end;
  3739. }
  3740. }// END FOR ELSE
  3741. }
  3742. }// END FOR CCS_QUANTITY
  3743. }
  3744. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3745. {
  3746. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3747. {
  3748. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3749. }
  3750. else
  3751. {
  3752. tempIndex = connectorIdInt -1;
  3753. }
  3754. for (int index = 0; index < GB_QUANTITY; index++)
  3755. {
  3756. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3757. {
  3758. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3759. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3760. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3761. {
  3762. //Reserved
  3763. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3764. }
  3765. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3766. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3767. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3768. {
  3769. //Reserved
  3770. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3771. result = FAIL;
  3772. goto end;
  3773. }
  3774. else
  3775. {
  3776. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3777. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3778. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3779. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3780. {
  3781. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  3782. result = FAIL;
  3783. goto end;
  3784. }
  3785. }// END FOR ELSE
  3786. }
  3787. } // END FOR GB_QUANTITY
  3788. }
  3789. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3790. {
  3791. tempIndex = connectorIdInt -1;
  3792. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3793. {
  3794. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3795. {
  3796. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3797. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3798. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3799. {
  3800. //Reserved
  3801. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3802. }
  3803. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3804. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3805. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3806. {
  3807. //Reserved
  3808. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3809. result = FAIL;
  3810. goto end;
  3811. }
  3812. else
  3813. {
  3814. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3815. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3816. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3817. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3818. {
  3819. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  3820. result = FAIL;
  3821. goto end;
  3822. }
  3823. }// END FOR ELSE
  3824. }
  3825. } // END FOR GB_QUANTITY
  3826. }
  3827. else
  3828. {
  3829. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3830. {
  3831. tempIndex = 2;
  3832. }
  3833. else
  3834. {
  3835. tempIndex = connectorIdInt -1;
  3836. }
  3837. for (int index = 0; index < AC_QUANTITY; index++)
  3838. {
  3839. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3840. {
  3841. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3842. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3843. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3844. {
  3845. //Reserved
  3846. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3847. }
  3848. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3849. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3850. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3851. {
  3852. //Reserved
  3853. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3854. result = FAIL;
  3855. goto end;
  3856. }
  3857. else
  3858. {
  3859. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3860. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3861. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3862. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3863. {
  3864. DEBUG_WARN("AC connector not allow start cause busy.\n");
  3865. result = FAIL;
  3866. goto end;
  3867. }
  3868. }//END FOR ELSE
  3869. }
  3870. }// END FOR AC_QUANTITY
  3871. }
  3872. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3873. {
  3874. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3875. {
  3876. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  3877. {
  3878. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3879. system(cmdBuf);
  3880. }
  3881. }
  3882. else
  3883. {
  3884. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3885. result = FAIL;
  3886. }
  3887. }
  3888. end:
  3889. if(result == PASS)
  3890. {
  3891. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3892. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3893. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3894. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3895. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3896. }
  3897. }
  3898. void CheckSystemValue(void)
  3899. {
  3900. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  3901. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  3902. char filenmae[100]={0};
  3903. char str[100]={0};
  3904. int tempIndex = 0;
  3905. //===============================
  3906. // send Heartbeat
  3907. //===============================
  3908. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3909. {
  3910. //parameter for test
  3911. sendHeartbeatRequest(0);
  3912. //==============================================
  3913. // Reset Waiting Time
  3914. //==============================================
  3915. HeartBeatWithNOResponse += 1;
  3916. }
  3917. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3918. {
  3919. //==========================================
  3920. // Check remote start without connector id
  3921. //==========================================
  3922. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  3923. {
  3924. int connectorIdInt = -1;
  3925. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  3926. {
  3927. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  3928. {
  3929. connectorIdInt = (gun_index+1);
  3930. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  3931. checkRemoteStart(connectorIdInt);
  3932. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  3933. break;
  3934. }
  3935. }
  3936. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  3937. {
  3938. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  3939. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  3940. }
  3941. }
  3942. //==========================================
  3943. // csu trigger DataTransferReq
  3944. //==========================================
  3945. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  3946. {
  3947. sendDataTransferRequest(gun_index);
  3948. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  3949. }
  3950. //==========================================
  3951. // CSU Trigger Authorize Request
  3952. //==========================================
  3953. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3954. {
  3955. sendAuthorizeRequest(0);
  3956. authorizeRetryTimes = authorizeRetryTimes + 1;
  3957. if(authorizeRetryTimes < 3)
  3958. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3959. }
  3960. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3961. {
  3962. authorizeRetryTimes = 0;
  3963. SetOcppConnStatus(FALSE);
  3964. server_sign = FALSE;
  3965. }
  3966. 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))
  3967. {
  3968. sendAuthorizeRequest(0);
  3969. }
  3970. //==========================================
  3971. // Charger start transaction
  3972. //==========================================
  3973. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3974. {
  3975. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3976. sendStartTransactionRequest(gun_index);
  3977. refreshStartTimer(&clientTime.StartTransaction);
  3978. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  3979. storeTempStopTransaction(gun_index);
  3980. }
  3981. //==========================================
  3982. // Charger stop transaction
  3983. //==========================================
  3984. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3985. {
  3986. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3987. sendStopTransactionRequest(gun_index);
  3988. OCPP_updatePeriodEnergy(gun_index);
  3989. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  3990. refreshStartTimer(&clientTime.StopTransaction);
  3991. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  3992. }
  3993. //==========================================
  3994. // Charger status report
  3995. //==========================================
  3996. //--- Check Mode Change ---//
  3997. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3998. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3999. {
  4000. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4001. {
  4002. tempIndex = ((gun_index==2) ? 1: 0);
  4003. }
  4004. else
  4005. {
  4006. tempIndex = gun_index;
  4007. }
  4008. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4009. {
  4010. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4011. {
  4012. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4013. {
  4014. // Sent unplug message for California pricing logic
  4015. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  4016. {
  4017. uint8_t ts[20];
  4018. getNowDatetime(ts);
  4019. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4020. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4021. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4022. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4023. }
  4024. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4025. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4026. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4027. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4028. {
  4029. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4030. if((access(filenmae,F_OK))!=-1)
  4031. {
  4032. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4033. sprintf(str,"rm -f %s",filenmae);
  4034. system(str);
  4035. }
  4036. }
  4037. }
  4038. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4039. #if 1 // for TempStopTransaction
  4040. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4041. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4042. {
  4043. checkTempStopTransaction(gun_index);
  4044. }
  4045. #endif
  4046. }
  4047. }
  4048. }
  4049. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4050. {
  4051. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4052. {
  4053. tempIndex = ((gun_index==2) ? 1: 0);
  4054. }
  4055. else
  4056. {
  4057. tempIndex = gun_index;
  4058. }
  4059. for (int index = 0; index < CCS_QUANTITY; index++)
  4060. {
  4061. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4062. {
  4063. 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]*/ )
  4064. {
  4065. // Sent unplug message for California pricing logic
  4066. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  4067. {
  4068. uint8_t ts[20];
  4069. getNowDatetime(ts);
  4070. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4071. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4072. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4073. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4074. }
  4075. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4076. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4077. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4078. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4079. {
  4080. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4081. if((access(filenmae,F_OK))!=-1)
  4082. {
  4083. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4084. sprintf(str,"rm -f %s",filenmae);
  4085. system(str);
  4086. }
  4087. }
  4088. }
  4089. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4090. #if 1 // for TempStopTransaction
  4091. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4092. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4093. {
  4094. checkTempStopTransaction(gun_index);
  4095. }
  4096. #endif
  4097. }
  4098. }
  4099. }
  4100. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4101. {
  4102. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4103. {
  4104. tempIndex = ((gun_index==2) ? 1: 0);
  4105. }
  4106. else
  4107. {
  4108. tempIndex = gun_index;
  4109. }
  4110. for (int index = 0; index < GB_QUANTITY; index++)
  4111. {
  4112. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4113. {
  4114. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4115. {
  4116. // Sent unplug message for California pricing logic
  4117. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  4118. {
  4119. uint8_t ts[20];
  4120. getNowDatetime(ts);
  4121. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4122. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4123. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4124. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4125. }
  4126. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4127. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4128. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4129. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4130. {
  4131. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4132. if((access(filenmae,F_OK))!=-1)
  4133. {
  4134. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4135. sprintf(str,"rm -f %s",filenmae);
  4136. system(str);
  4137. }
  4138. }
  4139. }
  4140. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4141. #if 1 // for TempStopTransaction
  4142. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4143. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4144. {
  4145. checkTempStopTransaction(gun_index);
  4146. }
  4147. #endif
  4148. }
  4149. }
  4150. }
  4151. else if(gunType[gun_index] == GUN_TYPE_DO)
  4152. {
  4153. tempIndex = gun_index;
  4154. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4155. {
  4156. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4157. {
  4158. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4159. {
  4160. // Sent unplug message for California pricing logic
  4161. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  4162. {
  4163. uint8_t ts[20];
  4164. getNowDatetime(ts);
  4165. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4166. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4167. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4168. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4169. }
  4170. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4171. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4172. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4173. 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
  4174. {
  4175. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4176. if((access(filenmae,F_OK))!=-1)
  4177. {
  4178. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4179. sprintf(str,"rm -f %s",filenmae);
  4180. system(str);
  4181. }
  4182. }
  4183. }
  4184. 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);
  4185. #if 1 // for TempStopTransaction
  4186. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4187. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4188. {
  4189. checkTempStopTransaction(gun_index);
  4190. }
  4191. #endif
  4192. }
  4193. }
  4194. }
  4195. else
  4196. {
  4197. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4198. {
  4199. tempIndex = 2;
  4200. }
  4201. else
  4202. {
  4203. tempIndex = gun_index;
  4204. }
  4205. for (int index = 0; index < AC_QUANTITY; index++)
  4206. {
  4207. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4208. {
  4209. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4210. {
  4211. // Sent unplug message for California pricing logic
  4212. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  4213. {
  4214. uint8_t ts[20];
  4215. getNowDatetime(ts);
  4216. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4217. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4218. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4219. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4220. }
  4221. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4222. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4223. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4224. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4225. {
  4226. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4227. if((access(filenmae,F_OK))!=-1)
  4228. {
  4229. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4230. sprintf(str,"rm -f %s",filenmae);
  4231. system(str);
  4232. }
  4233. }
  4234. }
  4235. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4236. #if 1 // for TempStopTransaction
  4237. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4238. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4239. {
  4240. checkTempStopTransaction(gun_index);
  4241. }
  4242. #endif
  4243. }
  4244. }// END
  4245. }
  4246. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  4247. (
  4248. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  4249. )
  4250. )
  4251. {
  4252. if(SystemInitial > 0)
  4253. SystemInitial -= 1;
  4254. sendStatusNotificationRequest(gun_index);
  4255. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4256. }
  4257. //==============================================
  4258. // CSU Trigger Smart Charging Profilw
  4259. //==============================================
  4260. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4261. {
  4262. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4263. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4264. }
  4265. //==============================================
  4266. // Meter report
  4267. //==============================================
  4268. // Trigger MeterValue
  4269. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4270. {
  4271. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4272. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4273. }
  4274. // ClockAlign MeterValue
  4275. 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))
  4276. {
  4277. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4278. {
  4279. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4280. {
  4281. tempIndex = ((gun_index==2) ? 1: 0);
  4282. }
  4283. else
  4284. {
  4285. tempIndex = gun_index;
  4286. }
  4287. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4288. {
  4289. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4290. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4291. {
  4292. reqClockAlignMeter[gun_index] = 1;
  4293. }
  4294. }// End for CHAdeMO
  4295. }
  4296. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4297. {
  4298. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4299. {
  4300. tempIndex = ((gun_index==2) ? 1: 0);
  4301. }
  4302. else
  4303. {
  4304. tempIndex = gun_index;
  4305. }
  4306. for (int index = 0; index < CCS_QUANTITY; index++)
  4307. {
  4308. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4309. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4310. {
  4311. reqClockAlignMeter[gun_index] = 1;
  4312. }
  4313. } // End for CCS
  4314. }
  4315. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4316. {
  4317. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4318. {
  4319. tempIndex = ((gun_index==2) ? 1: 0);
  4320. }
  4321. else
  4322. {
  4323. tempIndex = gun_index;
  4324. }
  4325. for (int index = 0; index < GB_QUANTITY; index++)
  4326. {
  4327. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4328. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4329. {
  4330. reqClockAlignMeter[gun_index] = 1;
  4331. }
  4332. }// End for GB
  4333. }
  4334. else if(gunType[gun_index] == GUN_TYPE_DO)
  4335. {
  4336. tempIndex = gun_index;
  4337. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4338. {
  4339. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4340. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4341. {
  4342. reqClockAlignMeter[gun_index] = 1;
  4343. }
  4344. }
  4345. }
  4346. else
  4347. {
  4348. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4349. {
  4350. tempIndex = 2;
  4351. }
  4352. else
  4353. {
  4354. tempIndex = gun_index;
  4355. }
  4356. for (int index = 0; index < AC_QUANTITY; index++)
  4357. {
  4358. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4359. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4360. {
  4361. reqClockAlignMeter[gun_index] = 1;
  4362. }
  4363. }//End for AC
  4364. }
  4365. }
  4366. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4367. {
  4368. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4369. reqClockAlignMeter[gun_index] = 0;
  4370. }
  4371. // Sample period MeterValue
  4372. if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>5?(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):5))))
  4373. {
  4374. //check Transaction active
  4375. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4376. {
  4377. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4378. {
  4379. tempIndex = ((gun_index==2) ? 1: 0);
  4380. }
  4381. else
  4382. {
  4383. tempIndex = gun_index;
  4384. }
  4385. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4386. {
  4387. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4388. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4389. {
  4390. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4391. {
  4392. reqSampleMeter[gun_index] = 1;
  4393. }
  4394. }
  4395. }// End for CHAdeMO
  4396. }
  4397. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4398. {
  4399. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4400. {
  4401. tempIndex = ((gun_index==2) ? 1: 0);
  4402. }
  4403. else
  4404. {
  4405. tempIndex = gun_index;
  4406. }
  4407. for (int index = 0; index < CCS_QUANTITY; index++)
  4408. {
  4409. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4410. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4411. {
  4412. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4413. {
  4414. reqSampleMeter[gun_index] = 1;
  4415. }
  4416. }
  4417. } // End for CCS
  4418. }
  4419. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4420. {
  4421. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4422. {
  4423. tempIndex = ((gun_index==2) ? 1: 0);
  4424. }
  4425. else
  4426. {
  4427. tempIndex = gun_index;
  4428. }
  4429. for (int index = 0; index < GB_QUANTITY; index++)
  4430. {
  4431. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4432. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4433. {
  4434. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4435. {
  4436. reqSampleMeter[gun_index] = 1;
  4437. }
  4438. }
  4439. }// End for GB
  4440. }
  4441. else if(gunType[gun_index] == GUN_TYPE_DO)
  4442. {
  4443. tempIndex = gun_index;
  4444. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4445. {
  4446. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4447. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4448. {
  4449. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4450. {
  4451. reqSampleMeter[gun_index] = 1;
  4452. }
  4453. }
  4454. }
  4455. }
  4456. else
  4457. {
  4458. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4459. {
  4460. tempIndex = 2;
  4461. }
  4462. else
  4463. {
  4464. tempIndex = gun_index;
  4465. }
  4466. for (int index = 0; index < AC_QUANTITY; index++)
  4467. {
  4468. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4469. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4470. {
  4471. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4472. {
  4473. reqSampleMeter[gun_index] = 1;
  4474. }
  4475. }
  4476. }//End for AC
  4477. }
  4478. if(reqSampleMeter[gun_index] == 1)
  4479. {
  4480. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4481. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4482. storeTempStopTransaction(gun_index);
  4483. }
  4484. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4485. }
  4486. //==============================================
  4487. // Check Connector reserved
  4488. //==============================================
  4489. //===============================
  4490. // Check if Reserve is expired
  4491. //===============================
  4492. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4493. {
  4494. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4495. {
  4496. DEBUG_INFO("reserve expired.\n");
  4497. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4498. }
  4499. }//END OF Check if Reserve is expired
  4500. //==========================================
  4501. // csu trigger FirmwareStatusNotificationReq
  4502. //==========================================
  4503. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4504. {
  4505. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  4506. }
  4507. //==========================================
  4508. // csu trigger DiagnosticsStatusNotificationReq
  4509. //==========================================
  4510. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4511. {
  4512. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  4513. }
  4514. //==========================================
  4515. // csu trigger CancelReservationConf
  4516. //==========================================
  4517. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4518. {
  4519. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  4520. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4521. }
  4522. //==========================================
  4523. // csu trigger ChangeAvailabilityConf
  4524. //==========================================
  4525. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4526. {
  4527. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  4528. }
  4529. //==========================================
  4530. // csu trigger UnlockConnectorConf
  4531. //==========================================
  4532. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4533. {
  4534. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  4535. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4536. }
  4537. //==========================================
  4538. // csu trigger ReserveNowConf
  4539. //==========================================
  4540. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4541. {
  4542. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  4543. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4544. }
  4545. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  4546. {
  4547. sendSignCertificateRequest();
  4548. }
  4549. }
  4550. }
  4551. //==========================================
  4552. // send request routine
  4553. //==========================================
  4554. int sendAuthorizeRequest(int gun_index)
  4555. {
  4556. mtrace();
  4557. int result = FAIL;
  4558. char message[100]={0};
  4559. char guid[37];
  4560. char tempdata[65]={0};
  4561. DEBUG_INFO("sendAuthorizeRequest...\n");
  4562. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4563. //Local Authorize
  4564. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  4565. {
  4566. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4567. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4568. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4569. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4570. result = PASS;
  4571. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4572. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4573. authorizeRetryTimes = 0;
  4574. return result;
  4575. }
  4576. 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))||
  4577. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4578. {
  4579. // Query from cache
  4580. DEBUG_INFO("Authorize from cache.\n");
  4581. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4582. // Query from list
  4583. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4584. {
  4585. DEBUG_INFO("Authorize from list.\n");
  4586. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4587. }
  4588. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4589. {
  4590. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4591. {
  4592. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4593. }
  4594. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4595. {
  4596. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4597. }
  4598. if(!GetOcppConnStatus())
  4599. {
  4600. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4601. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4602. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4603. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4604. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4605. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4606. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4607. authorizeRetryTimes = 0;
  4608. return result;
  4609. }
  4610. }
  4611. else
  4612. {
  4613. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4614. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4615. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4616. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4617. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  4618. else
  4619. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4620. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4621. result = PASS;
  4622. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4623. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4624. authorizeRetryTimes = 0;
  4625. return result;
  4626. }
  4627. }
  4628. //initialize struct Authorize
  4629. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  4630. //get data from shared memory
  4631. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4632. random_uuid(guid);
  4633. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  4634. LWS_Send(message);
  4635. sprintf(tempdata, "Authorize,%d", gun_index);
  4636. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4637. {
  4638. result = PASS;
  4639. DEBUG_INFO("Authorize mapItem pass\n");
  4640. }
  4641. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4642. return result;
  4643. }
  4644. int sendBootNotificationRequest(void)
  4645. {
  4646. mtrace();
  4647. int result = FAIL;
  4648. char message[500]={0}, payload[700]={0};
  4649. char guid[37]={0};
  4650. char tempdata[65]={0};
  4651. // Fill BootNotification fields
  4652. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  4653. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4654. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4655. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4656. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4657. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4658. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4659. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4660. ShmOCPP16Data->ChargeBoxId
  4661. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4662. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4663. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4664. ,ShmOCPP16Data->BootNotification.CpFwVersion
  4665. ,ShmOCPP16Data->BootNotification.CpIccid
  4666. ,ShmOCPP16Data->BootNotification.CpImsi);
  4667. random_uuid(guid);
  4668. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4669. LWS_Send(message);
  4670. sprintf(tempdata, "BootNotification,0");
  4671. 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*/)
  4672. {
  4673. result = PASS;
  4674. }
  4675. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4676. strcpy(queuedata,message);
  4677. return result;
  4678. }
  4679. int sendDataTransferRequest(int gun_index)
  4680. {
  4681. mtrace();
  4682. char message[1000]={0};
  4683. char guid[37]={0};
  4684. char tempdata[65]={0};
  4685. int result = FAIL;
  4686. random_uuid(guid);
  4687. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4688. MESSAGE_TYPE_CALL,
  4689. guid,
  4690. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4691. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4692. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4693. LWS_Send(message);
  4694. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4695. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4696. {
  4697. result = PASS;
  4698. DEBUG_INFO("DataTransfer mapItem pass\n");
  4699. }
  4700. return result;
  4701. }
  4702. int sendDiagnosticsStatusNotificationRequest(char *status)
  4703. {
  4704. mtrace();
  4705. int result = FAIL;
  4706. char message[110]={0};
  4707. char guid[37]={0};
  4708. char tempdata[65]={0};
  4709. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4710. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4711. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4712. random_uuid(guid);
  4713. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4714. LWS_SendNow(message);
  4715. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4716. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4717. {
  4718. result = PASS;
  4719. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4720. }
  4721. //#ifdef SystemLogMessage
  4722. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4723. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4724. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4725. //#endif
  4726. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4727. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4728. //record status
  4729. if(strcmp(status,"Idle")==0)
  4730. {
  4731. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4732. }
  4733. else if(strcmp(status,"Uploaded")==0)
  4734. {
  4735. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4736. }
  4737. else if(strcmp(status,"UploadFailed")==0)
  4738. {
  4739. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4740. }
  4741. else if(strcmp(status,"Uploading")==0)
  4742. {
  4743. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4744. }
  4745. return result;
  4746. }
  4747. int sendFirmwareStatusNotificationRequest(char *status)
  4748. {
  4749. mtrace();
  4750. int result = FAIL;
  4751. char message[110]={0};
  4752. char guid[37]={0};
  4753. char tempdata[65]={0};
  4754. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4755. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4756. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4757. random_uuid(guid);
  4758. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4759. LWS_SendNow(message);
  4760. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4761. 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*/)
  4762. {
  4763. result = PASS;
  4764. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4765. }
  4766. //#ifdef SystemLogMessage
  4767. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4768. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4769. //#endif
  4770. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4771. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4772. //record status
  4773. if(strcmp(status,"Downloaded")==0)
  4774. {
  4775. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4776. }
  4777. else if(strcmp(status,"DownloadFailed")==0)
  4778. {
  4779. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4780. }
  4781. else if(strcmp(status,"Downloading")==0)
  4782. {
  4783. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4784. }
  4785. else if(strcmp(status,"Idle")==0)
  4786. {
  4787. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4788. }
  4789. else if(strcmp(status,"InstallationFailed")==0)
  4790. {
  4791. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4792. }
  4793. else if(strcmp(status,"Installing")==0)
  4794. {
  4795. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4796. }
  4797. else if(strcmp(status,"Installed")==0)
  4798. {
  4799. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4800. }
  4801. return result;
  4802. }
  4803. int sendHeartbeatRequest(int gun_index)
  4804. {
  4805. mtrace();
  4806. int result = FAIL;
  4807. char message[80]={0};
  4808. char guid[37]={0};
  4809. char tempdata[65]={0};
  4810. random_uuid(guid);
  4811. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4812. , MESSAGE_TYPE_CALL
  4813. , guid );
  4814. LWS_Send(message);
  4815. sprintf(tempdata, "Heartbeat,%d", 0);
  4816. 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*/)
  4817. {
  4818. result = PASS;
  4819. }
  4820. return result;
  4821. }
  4822. int sendStartTransactionRequest(int gun_index)
  4823. {
  4824. mtrace();
  4825. int result = FAIL;
  4826. char message[250]={0};
  4827. char guid[37]={0};
  4828. struct timeval tmnow;
  4829. struct tm *tm;
  4830. char buf[28];//, usec_buf[6];
  4831. char tempdata[65]={0};
  4832. int tempIndex = 0;
  4833. DEBUG_INFO("sendStartTransactionRequest...\n");
  4834. gettimeofday(&tmnow, NULL);
  4835. time_t t;
  4836. t = time(NULL);
  4837. /*UTC time and date*/
  4838. tm = gmtime(&t);
  4839. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4840. #if 0 // remove temporally
  4841. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4842. strcat(buf,".");
  4843. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4844. strcat(buf,usec_buf);
  4845. #endif
  4846. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4847. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4848. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4849. // clear StartTransaction Response
  4850. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4851. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4852. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4853. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4854. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4855. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4856. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4857. {
  4858. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4859. {
  4860. tempIndex = ((gun_index==2) ? 1: 0);
  4861. }
  4862. else
  4863. {
  4864. tempIndex = gun_index;
  4865. }
  4866. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4867. {
  4868. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4869. {
  4870. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4871. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4872. }
  4873. }
  4874. }
  4875. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4876. {
  4877. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4878. {
  4879. tempIndex = ((gun_index==2) ? 1: 0);
  4880. }
  4881. else
  4882. {
  4883. tempIndex = gun_index;
  4884. }
  4885. for (int index = 0; index < CCS_QUANTITY; index++)
  4886. {
  4887. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4888. {
  4889. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4890. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4891. }
  4892. }
  4893. }
  4894. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4895. {
  4896. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4897. {
  4898. tempIndex = ((gun_index==2) ? 1: 0);
  4899. }
  4900. else
  4901. {
  4902. tempIndex = gun_index;
  4903. }
  4904. for (int index = 0; index < GB_QUANTITY; index++)
  4905. {
  4906. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4907. {
  4908. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4909. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4910. }
  4911. }
  4912. }
  4913. else if(gunType[gun_index] == GUN_TYPE_DO)
  4914. {
  4915. tempIndex = gun_index;
  4916. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4917. {
  4918. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4919. {
  4920. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4921. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4922. }
  4923. }
  4924. }
  4925. else
  4926. {
  4927. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4928. {
  4929. tempIndex = 2;
  4930. }
  4931. else
  4932. {
  4933. tempIndex = gun_index;
  4934. }
  4935. for (int index = 0; index < AC_QUANTITY; index++)
  4936. {
  4937. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4938. {
  4939. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4940. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4941. }
  4942. }
  4943. }
  4944. random_uuid(guid);
  4945. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4946. {
  4947. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4948. , gun_index +1
  4949. , MESSAGE_TYPE_CALL
  4950. , guid
  4951. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4952. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4953. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4954. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4955. }
  4956. else
  4957. {
  4958. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4959. , gun_index +1
  4960. , MESSAGE_TYPE_CALL
  4961. , guid
  4962. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4963. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4964. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4965. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  4966. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4967. }
  4968. #if 1
  4969. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4970. 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*/)
  4971. {
  4972. result = PASS;
  4973. }
  4974. #endif
  4975. strcpy(queuedata, message);
  4976. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4977. OCPP_insert_transaction_msg(YES, queuedata);
  4978. return result;
  4979. }
  4980. int sendStatusNotificationRequest(int gun_index)
  4981. {
  4982. mtrace();
  4983. int result = FAIL;
  4984. char message[600]={0};
  4985. char guid[37];
  4986. int currentStatus = 0;
  4987. struct timeval tmnow;
  4988. struct tm *tm;
  4989. char buf[28];//, usec_buf[6];
  4990. char tempdata[65]={0};
  4991. int tempIndex = 0;
  4992. uint8_t isStateChanged = TRUE;
  4993. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4994. gettimeofday(&tmnow, NULL);
  4995. time_t t;
  4996. t = time(NULL);
  4997. /*UTC time and date*/
  4998. tm = gmtime(&t);
  4999. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5000. #if 0 // remove temporally
  5001. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5002. strcat(buf,".");
  5003. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5004. strcat(buf,usec_buf);
  5005. #endif
  5006. //printf("%s",buf);
  5007. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5008. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5009. // it's option
  5010. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5011. /*
  5012. enum _SYSTEM_STATUS
  5013. {
  5014. S_BOOTING = 0,
  5015. S_IDLE, = 1
  5016. S_AUTHORIZING, =2
  5017. S_REASSIGN_CHECK, =3
  5018. S_REASSIGN, =4
  5019. S_PRECHARGE, =5
  5020. S_PREPARING_FOR_EV, =6
  5021. S_PREPARING_FOR_EVSE, =7
  5022. S_CHARGING, =8
  5023. S_TERMINATING, =9
  5024. S_COMPLETE, =10
  5025. S_ALARM, =11
  5026. S_FAULT =12
  5027. }
  5028. */
  5029. //check Transaction active
  5030. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5031. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5032. {
  5033. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5034. {
  5035. tempIndex = ((gun_index==2) ? 1: 0);
  5036. }
  5037. else
  5038. {
  5039. tempIndex = gun_index;
  5040. }
  5041. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5042. {
  5043. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5044. {
  5045. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5046. {
  5047. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5048. {
  5049. currentStatus = Preparing; //OCPP Status: Preparing
  5050. }
  5051. else
  5052. {
  5053. currentStatus = Available; //OCPP Status: Available
  5054. }
  5055. }
  5056. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5057. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5058. ) //S_PRECHARGE
  5059. {
  5060. currentStatus = Preparing; //OCPP Status: Preparing
  5061. }
  5062. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5063. {
  5064. currentStatus = Charging; //OCPP Status: Charging
  5065. }
  5066. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5067. {
  5068. currentStatus = Finishing; //OCPP Status: Finishing
  5069. }
  5070. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5071. {
  5072. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5073. }
  5074. 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
  5075. {
  5076. currentStatus = Unavailable; //OCPP Status: Unavailable
  5077. }
  5078. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5079. {
  5080. currentStatus = Faulted; //OCPP Status: Faulted
  5081. }
  5082. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5083. {
  5084. currentStatus = Reserved; //OCPP Status: Reserved
  5085. }
  5086. } //end of the same index
  5087. }//end of for CHAdeMO_QUANTITY
  5088. }
  5089. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5090. {
  5091. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5092. {
  5093. tempIndex = ((gun_index==2) ? 1: 0);
  5094. }
  5095. else
  5096. {
  5097. tempIndex = gun_index;
  5098. }
  5099. for (int index = 0; index < CCS_QUANTITY; index++)
  5100. {
  5101. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5102. {
  5103. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5104. {
  5105. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5106. {
  5107. currentStatus = Preparing; //OCPP Status: Preparing
  5108. }
  5109. else
  5110. {
  5111. currentStatus = Available; //OCPP Status: Available
  5112. }
  5113. }
  5114. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5115. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5116. ) //S_PRECHARGE
  5117. {
  5118. currentStatus = Preparing; //OCPP Status: Preparing
  5119. }
  5120. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5121. {
  5122. currentStatus = Charging; //OCPP Status: Charging
  5123. }
  5124. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5125. {
  5126. currentStatus = Finishing; //OCPP Status: Finishing
  5127. }
  5128. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5129. {
  5130. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5131. }
  5132. 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
  5133. {
  5134. currentStatus = Unavailable; //OCPP Status : Unavailable
  5135. }
  5136. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5137. {
  5138. currentStatus = Faulted; //OCPP Status: Faulted
  5139. }
  5140. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5141. {
  5142. currentStatus = Reserved; //OCPP Status: Reserved
  5143. }
  5144. } //end of the same index
  5145. } // end of for CCS_QUANTITY
  5146. }
  5147. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5148. {
  5149. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5150. {
  5151. tempIndex = ((gun_index==2) ? 1: 0);
  5152. }
  5153. else
  5154. {
  5155. tempIndex = gun_index;
  5156. }
  5157. for (int index = 0; index < GB_QUANTITY; index++)
  5158. {
  5159. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5160. {
  5161. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5162. {
  5163. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5164. {
  5165. currentStatus = Preparing; //OCPP Status: Preparing
  5166. }
  5167. else
  5168. {
  5169. currentStatus = Available; //OCPP Status: Available
  5170. }
  5171. }
  5172. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5173. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5174. ) //S_PRECHARGE
  5175. {
  5176. currentStatus = Preparing; //OCPP Status: Preparing
  5177. }
  5178. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5179. {
  5180. currentStatus = Charging; //OCPP Status: Charging
  5181. }
  5182. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5183. {
  5184. currentStatus = Finishing; //OCPP Status: Finishing
  5185. }
  5186. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5187. {
  5188. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5189. }
  5190. 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
  5191. {
  5192. currentStatus = Unavailable; //OCPP Status: Unavailable
  5193. }
  5194. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5195. {
  5196. currentStatus = Faulted; //OCPP Status: Faulted
  5197. }
  5198. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5199. {
  5200. currentStatus = Reserved; //OCPP Status: Reserved
  5201. }
  5202. } //end of the same index
  5203. } // end of for GB_QUANTITY
  5204. }
  5205. else if(gunType[gun_index] == GUN_TYPE_DO)
  5206. {
  5207. tempIndex = gun_index;
  5208. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5209. {
  5210. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5211. {
  5212. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5213. {
  5214. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5215. {
  5216. currentStatus = Preparing; //OCPP Status: Preparing
  5217. }
  5218. else
  5219. {
  5220. currentStatus = Available; //OCPP Status: Available
  5221. }
  5222. }
  5223. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5224. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5225. ) //S_PRECHARGE
  5226. {
  5227. currentStatus = Preparing; //OCPP Status: Preparing
  5228. }
  5229. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5230. {
  5231. currentStatus = Charging; //OCPP Status: Charging
  5232. }
  5233. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5234. {
  5235. currentStatus = Finishing; //OCPP Status: Finishing
  5236. }
  5237. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5238. {
  5239. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5240. }
  5241. 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
  5242. {
  5243. currentStatus = Unavailable; //OCPP Status: Unavailable
  5244. }
  5245. 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
  5246. {
  5247. currentStatus = Faulted; //OCPP Status: Faulted
  5248. }
  5249. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5250. {
  5251. currentStatus = Reserved; //OCPP Status: Reserved
  5252. }
  5253. } //end of the same index
  5254. }
  5255. }
  5256. else
  5257. {
  5258. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5259. {
  5260. tempIndex = 2;
  5261. }
  5262. else
  5263. {
  5264. tempIndex = gun_index;
  5265. }
  5266. for (int index = 0; index < AC_QUANTITY; index++)
  5267. {
  5268. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5269. {
  5270. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5271. {
  5272. 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))
  5273. {
  5274. currentStatus = Preparing; //OCPP Status: Preparing
  5275. }
  5276. else
  5277. {
  5278. currentStatus = Available; //OCPP Status: Available
  5279. }
  5280. }
  5281. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5282. {
  5283. currentStatus = Preparing; //OCPP Status: Preparing
  5284. }
  5285. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5286. {
  5287. currentStatus = Charging; //OCPP Status: Charging
  5288. }
  5289. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5290. {
  5291. currentStatus = Finishing; //OCPP Status: Finishing
  5292. }
  5293. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5294. {
  5295. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5296. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5297. else
  5298. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5299. }
  5300. 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
  5301. {
  5302. currentStatus = Unavailable; //OCPP Status: Unavailable
  5303. }
  5304. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5305. {
  5306. currentStatus = Faulted; //OCPP Status: Faulted
  5307. }
  5308. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5309. {
  5310. currentStatus = Reserved; //OCPP Status: Reserved
  5311. }
  5312. }//end of the same index
  5313. }//end of for AC_QUANTITY
  5314. }
  5315. //it's option
  5316. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5317. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  5318. {
  5319. isStateChanged = FALSE;
  5320. }
  5321. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5322. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5323. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5324. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5325. random_uuid(guid);
  5326. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5327. , MESSAGE_TYPE_CALL
  5328. , guid
  5329. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5330. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5331. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5332. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5333. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5334. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5335. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5336. if((server_sign == TRUE) && isStateChanged)
  5337. {
  5338. LWS_Send(message);
  5339. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5340. 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*/)
  5341. {
  5342. //DEBUG_ERROR("statusNotification mapitem pass");
  5343. result = PASS;
  5344. }
  5345. }
  5346. else
  5347. {
  5348. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5349. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5350. result = PASS;
  5351. }
  5352. return result;
  5353. }
  5354. int sendStopTransactionRequest(int gun_index)
  5355. {
  5356. mtrace();
  5357. int result = FAIL;
  5358. //char message[1500]={0};
  5359. char guid[37]={0};
  5360. char tempdata[65]={0};
  5361. int tempIndex = 0;
  5362. char TempStopTransaction[256];
  5363. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5364. //int idx_sample=0;
  5365. DEBUG_INFO("sendStopTransactionRequest \n");
  5366. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5367. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5368. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5369. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5370. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5371. {
  5372. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5373. {
  5374. tempIndex = ((gun_index==2) ? 1: 0);
  5375. }
  5376. else
  5377. {
  5378. tempIndex = gun_index;
  5379. }
  5380. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5381. {
  5382. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5383. {
  5384. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5385. }
  5386. }// END OF CHAdeMO_QUANTITY
  5387. }
  5388. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5389. {
  5390. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5391. {
  5392. tempIndex = ((gun_index==2) ? 1: 0);
  5393. }
  5394. else
  5395. {
  5396. tempIndex = gun_index;
  5397. }
  5398. for (int index = 0; index < CCS_QUANTITY; index++)
  5399. {
  5400. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5401. {
  5402. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5403. }
  5404. }// END OF CCS_QUANTITY
  5405. }
  5406. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5407. {
  5408. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5409. {
  5410. tempIndex = ((gun_index==2) ? 1: 0);
  5411. }
  5412. else
  5413. {
  5414. tempIndex = gun_index;
  5415. }
  5416. for (int index = 0; index < GB_QUANTITY; index++)
  5417. {
  5418. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5419. {
  5420. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5421. }
  5422. }// END OF GB_QUANTITY
  5423. }
  5424. else if(gunType[gun_index] == GUN_TYPE_DO)
  5425. {
  5426. tempIndex = gun_index;
  5427. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5428. {
  5429. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5430. {
  5431. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5432. }
  5433. }// END OF GB_QUANTITY
  5434. }
  5435. else
  5436. {
  5437. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5438. {
  5439. tempIndex = 2;
  5440. }
  5441. else
  5442. {
  5443. tempIndex = gun_index;
  5444. }
  5445. for (int index = 0; index < AC_QUANTITY; index++)
  5446. {
  5447. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5448. {
  5449. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5450. }
  5451. }// END OF AC_QUANTITY
  5452. }
  5453. //====================================== Stop Transaction Time =====================================================
  5454. struct timeval tmnow;
  5455. struct tm *tm;
  5456. char buf[28];//, usec_buf[6];
  5457. gettimeofday(&tmnow, NULL);
  5458. time_t t;
  5459. t = time(NULL);
  5460. /*UTC time and date*/
  5461. tm = gmtime(&t);
  5462. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5463. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  5464. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  5465. random_uuid(guid);
  5466. /***********************************transactionData******************************************************/
  5467. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5468. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5469. //=================================
  5470. // Transaction_Begin
  5471. //=================================
  5472. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5473. {
  5474. //============================================ Energy.Active.Import.Interval ================================
  5475. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5476. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5477. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5478. 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*/]);
  5479. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5480. 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))
  5481. {
  5482. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5483. }
  5484. else
  5485. {
  5486. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5487. }
  5488. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5489. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5490. }
  5491. //=================================
  5492. // Transaction_End
  5493. //=================================
  5494. // ================================= Current.Import L1 ===============================================
  5495. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5496. {
  5497. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5498. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5499. {
  5500. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5501. {
  5502. tempIndex = ((gun_index==2) ? 1: 0);
  5503. }
  5504. else
  5505. {
  5506. tempIndex = gun_index;
  5507. }
  5508. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5509. {
  5510. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5511. {
  5512. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5513. }
  5514. }// End of for CHAdeMO_QUANTITY
  5515. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5516. }
  5517. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5518. {
  5519. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5520. {
  5521. tempIndex = ((gun_index==2) ? 1: 0);
  5522. }
  5523. else
  5524. {
  5525. tempIndex = gun_index;
  5526. }
  5527. for (int index = 0; index < CCS_QUANTITY; index++)
  5528. {
  5529. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5530. {
  5531. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5532. }
  5533. }// End of for CCS_QUANTITY
  5534. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5535. }
  5536. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5537. {
  5538. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5539. {
  5540. tempIndex = ((gun_index==2) ? 1: 0);
  5541. }
  5542. else
  5543. {
  5544. tempIndex = gun_index;
  5545. }
  5546. for (int index = 0; index < GB_QUANTITY; index++)
  5547. {
  5548. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5549. {
  5550. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5551. }
  5552. }// End of for GB_QUANTITY
  5553. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5554. }
  5555. else if(gunType[gun_index] == GUN_TYPE_DO)
  5556. {
  5557. tempIndex = gun_index;
  5558. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5559. {
  5560. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5561. {
  5562. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5563. }
  5564. }
  5565. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5566. }
  5567. else
  5568. {
  5569. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5570. {
  5571. tempIndex = 2;
  5572. }
  5573. else
  5574. {
  5575. tempIndex = gun_index;
  5576. }
  5577. for (int index = 0; index < AC_QUANTITY; index++)
  5578. {
  5579. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5580. {
  5581. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5582. }
  5583. }// End of for AC_QUANTITY
  5584. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5585. }
  5586. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5587. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5588. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5589. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5590. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5591. }
  5592. // ================================= Energy.Active.Import.Interval ==============================================
  5593. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5594. {
  5595. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5596. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5597. {
  5598. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5599. {
  5600. tempIndex = ((gun_index==2) ? 1: 0);
  5601. }
  5602. else
  5603. {
  5604. tempIndex = gun_index;
  5605. }
  5606. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5607. {
  5608. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5609. {
  5610. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5611. }
  5612. }// END OF CHAdeMO_QUANTITY
  5613. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5614. }
  5615. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5616. {
  5617. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5618. {
  5619. tempIndex = ((gun_index==2) ? 1: 0);
  5620. }
  5621. else
  5622. {
  5623. tempIndex = gun_index;
  5624. }
  5625. for (int index = 0; index < CCS_QUANTITY; index++)
  5626. {
  5627. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5628. {
  5629. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5630. }
  5631. }// END OF CCS_QUANTITY
  5632. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5633. }
  5634. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5635. {
  5636. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5637. {
  5638. tempIndex = ((gun_index==2) ? 1: 0);
  5639. }
  5640. else
  5641. {
  5642. tempIndex = gun_index;
  5643. }
  5644. for (int index = 0; index < GB_QUANTITY; index++)
  5645. {
  5646. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5647. {
  5648. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5649. }
  5650. }// END OF GB_QUANTITY
  5651. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5652. }
  5653. else if(gunType[gun_index] == GUN_TYPE_DO)
  5654. {
  5655. tempIndex = gun_index;
  5656. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5657. {
  5658. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5659. {
  5660. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5661. }
  5662. }
  5663. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5664. }
  5665. else
  5666. {
  5667. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5668. {
  5669. tempIndex = 2;
  5670. }
  5671. else
  5672. {
  5673. tempIndex = gun_index;
  5674. }
  5675. for (int index = 0; index < AC_QUANTITY; index++)
  5676. {
  5677. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5678. {
  5679. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5680. }
  5681. }// END OF AC_QUANTITY
  5682. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5683. }
  5684. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5685. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5686. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5687. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5688. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5689. }
  5690. //=================================== Power.Active.Import ==================================================
  5691. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5692. {
  5693. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5694. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5695. {
  5696. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5697. {
  5698. tempIndex = ((gun_index==2) ? 1: 0);
  5699. }
  5700. else
  5701. {
  5702. tempIndex = gun_index;
  5703. }
  5704. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5705. {
  5706. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5707. {
  5708. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5709. }
  5710. } // End for CHAdeMO_QUANTITY
  5711. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5712. }
  5713. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5714. {
  5715. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5716. {
  5717. tempIndex = ((gun_index==2) ? 1: 0);
  5718. }
  5719. else
  5720. {
  5721. tempIndex = gun_index;
  5722. }
  5723. for (int index = 0; index < CCS_QUANTITY; index++)
  5724. {
  5725. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5726. {
  5727. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5728. }
  5729. } // END for CCS_QUANTITY
  5730. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5731. }
  5732. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5733. {
  5734. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5735. {
  5736. tempIndex = ((gun_index==2) ? 1: 0);
  5737. }
  5738. else
  5739. {
  5740. tempIndex = gun_index;
  5741. }
  5742. for (int index = 0; index < GB_QUANTITY; index++)
  5743. {
  5744. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5745. {
  5746. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5747. }
  5748. }// END for GB_QUANTITY
  5749. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5750. }
  5751. else if(gunType[gun_index] == GUN_TYPE_DO)
  5752. {
  5753. tempIndex = gun_index;
  5754. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5755. {
  5756. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5757. {
  5758. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5759. }
  5760. }
  5761. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5762. }
  5763. else
  5764. {
  5765. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5766. {
  5767. tempIndex = 2;
  5768. }
  5769. else
  5770. {
  5771. tempIndex = gun_index;
  5772. }
  5773. for (int index = 0; index < AC_QUANTITY; index++)
  5774. {
  5775. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5776. {
  5777. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5778. }
  5779. } // END for AC_QUANTITY
  5780. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5781. }
  5782. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5783. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5784. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5785. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5786. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5787. }
  5788. //============================ Voltage L1 ====================================
  5789. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5790. {
  5791. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5792. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5793. {
  5794. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5795. {
  5796. tempIndex = ((gun_index==2) ? 1: 0);
  5797. }
  5798. else
  5799. {
  5800. tempIndex = gun_index;
  5801. }
  5802. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5803. {
  5804. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5805. {
  5806. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5807. }
  5808. } // END OF FOR CHAdeMO_QUANTITY
  5809. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5810. }
  5811. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5812. {
  5813. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5814. {
  5815. tempIndex = ((gun_index==2) ? 1: 0);
  5816. }
  5817. else
  5818. {
  5819. tempIndex = gun_index;
  5820. }
  5821. for (int index = 0; index < CCS_QUANTITY; index++)
  5822. {
  5823. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5824. {
  5825. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5826. }
  5827. } // END OF FOR CCS_QUANTITY
  5828. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5829. }
  5830. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5831. {
  5832. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5833. {
  5834. tempIndex = ((gun_index==2) ? 1: 0);
  5835. }
  5836. else
  5837. {
  5838. tempIndex = gun_index;
  5839. }
  5840. for (int index = 0; index < GB_QUANTITY; index++)
  5841. {
  5842. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5843. {
  5844. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5845. }
  5846. } // END OF FOR GB_QUANTITY
  5847. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5848. }
  5849. else if(gunType[gun_index] == GUN_TYPE_DO)
  5850. {
  5851. tempIndex = gun_index;
  5852. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5853. {
  5854. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5855. {
  5856. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5857. }
  5858. }
  5859. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5860. }
  5861. else
  5862. {
  5863. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5864. {
  5865. tempIndex = 2;
  5866. }
  5867. else
  5868. {
  5869. tempIndex = gun_index;
  5870. }
  5871. for (int index = 0; index < AC_QUANTITY; index++)
  5872. {
  5873. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5874. {
  5875. 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
  5876. }
  5877. } // END OF FOR AC_QUANTITY
  5878. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5879. }
  5880. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5881. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5882. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5883. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5884. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5885. }
  5886. //====================== End SoC ================================
  5887. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5888. {
  5889. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5890. 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))
  5891. {
  5892. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5893. {
  5894. tempIndex = ((gun_index==2) ? 1: 0);
  5895. }
  5896. else
  5897. {
  5898. tempIndex = gun_index;
  5899. }
  5900. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5901. {
  5902. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5903. {
  5904. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5905. {
  5906. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5907. }
  5908. }
  5909. }
  5910. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5911. {
  5912. for (int index = 0; index < CCS_QUANTITY; index++)
  5913. {
  5914. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5915. {
  5916. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5917. }
  5918. }
  5919. }
  5920. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5921. {
  5922. for (int index = 0; index < GB_QUANTITY; index++)
  5923. {
  5924. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5925. {
  5926. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5927. }
  5928. }
  5929. }
  5930. else if(gunType[gun_index] == GUN_TYPE_DO)
  5931. {
  5932. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5933. {
  5934. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5935. {
  5936. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5937. }
  5938. }
  5939. }
  5940. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5941. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5942. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5943. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5944. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5945. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5946. } // END FOR DC CASE
  5947. }
  5948. // ================================= Current.Import L2 ===============================================
  5949. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5950. {
  5951. // AC 3 phse L2 current
  5952. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5953. {
  5954. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5955. {
  5956. tempIndex = 2;
  5957. }
  5958. else
  5959. {
  5960. tempIndex = gun_index;
  5961. }
  5962. for (int index = 0; index < AC_QUANTITY; index++)
  5963. {
  5964. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5965. {
  5966. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5967. }
  5968. }// End of for AC_QUANTITY
  5969. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5970. }
  5971. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5972. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5973. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5974. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5975. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5976. }
  5977. // ================================= Current.Import L3 ===============================================
  5978. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5979. {
  5980. // AC 3 phse L3 current
  5981. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5982. {
  5983. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5984. {
  5985. tempIndex = 2;
  5986. }
  5987. else
  5988. {
  5989. tempIndex = gun_index;
  5990. }
  5991. for (int index = 0; index < AC_QUANTITY; index++)
  5992. {
  5993. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5994. {
  5995. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5996. }
  5997. }// End of for AC_QUANTITY
  5998. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5999. }
  6000. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6001. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6002. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6003. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6004. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6005. }
  6006. //============================ Voltage L2 ====================================
  6007. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6008. {
  6009. // AC 3 phse L2 voltage
  6010. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6011. {
  6012. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6013. {
  6014. tempIndex = 2;
  6015. }
  6016. else
  6017. {
  6018. tempIndex = gun_index;
  6019. }
  6020. for (int index = 0; index < AC_QUANTITY; index++)
  6021. {
  6022. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6023. {
  6024. 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
  6025. }
  6026. } // END OF FOR AC_QUANTITY
  6027. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6028. }
  6029. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6030. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6031. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6032. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6033. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6034. }
  6035. //============================ Voltage L3 ====================================
  6036. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6037. {
  6038. // AC 3 phse L3 voltage
  6039. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6040. {
  6041. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6042. {
  6043. tempIndex = 2;
  6044. }
  6045. else
  6046. {
  6047. tempIndex = gun_index;
  6048. }
  6049. for (int index = 0; index < AC_QUANTITY; index++)
  6050. {
  6051. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6052. {
  6053. 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
  6054. }
  6055. } // END OF FOR AC_QUANTITY
  6056. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6057. }
  6058. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6059. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6060. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6062. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6063. }
  6064. //====================== Start SoC ================================
  6065. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6066. {
  6067. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6068. 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))
  6069. {
  6070. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6071. {
  6072. tempIndex = ((gun_index==2) ? 1: 0);
  6073. }
  6074. else
  6075. {
  6076. tempIndex = gun_index;
  6077. }
  6078. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6079. {
  6080. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6081. {
  6082. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6083. {
  6084. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6085. }
  6086. }
  6087. }
  6088. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6089. {
  6090. for (int index = 0; index < CCS_QUANTITY; index++)
  6091. {
  6092. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6093. {
  6094. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6095. }
  6096. }
  6097. }
  6098. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6099. {
  6100. for (int index = 0; index < GB_QUANTITY; index++)
  6101. {
  6102. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6103. {
  6104. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6105. }
  6106. }
  6107. }
  6108. else if(gunType[gun_index] == GUN_TYPE_DO)
  6109. {
  6110. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6111. {
  6112. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6113. {
  6114. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6115. }
  6116. }
  6117. }
  6118. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6119. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6120. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6121. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6122. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6123. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6124. } // END FOR DC CASE
  6125. }
  6126. //================================================ Message create ====================================================
  6127. json_object *StopTransaction = json_object_new_object();
  6128. json_object *transactionDatas = json_object_new_array();
  6129. json_object *sampledValues = json_object_new_array();
  6130. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6131. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6132. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6133. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6134. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6135. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6136. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6137. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6138. {
  6139. json_object *transactionData = json_object_new_object();
  6140. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6141. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6142. {
  6143. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6144. {
  6145. json_object *sampledValue = json_object_new_object();
  6146. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6147. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6148. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6149. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6150. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6151. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6152. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6153. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6154. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6155. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6156. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6157. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6158. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6159. json_object_array_add(sampledValues, sampledValue);
  6160. }
  6161. }
  6162. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6163. json_object_array_add(transactionDatas, transactionData);
  6164. }
  6165. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6166. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6167. ,MESSAGE_TYPE_CALL
  6168. ,guid
  6169. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6170. json_object_put(StopTransaction);
  6171. #if 1 // for TempStopTransaction
  6172. //Delete TempStopTransaction
  6173. if((access(TempStopTransaction,F_OK))!=-1)
  6174. {
  6175. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6176. }
  6177. #endif
  6178. #if 1
  6179. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6180. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6181. {
  6182. result = PASS;
  6183. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6184. }
  6185. #endif
  6186. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6187. OCPP_insert_transaction_msg(NO, queuedata);
  6188. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6189. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6190. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6191. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6192. {
  6193. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6194. }
  6195. //for test
  6196. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6197. return result;
  6198. }
  6199. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6200. {
  6201. mtrace();
  6202. int result = FAIL;
  6203. char guid[37]={0};
  6204. char tempdata[65]={0};
  6205. int tempIndex = 0;
  6206. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6207. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6208. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6209. //set value
  6210. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6211. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6212. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6213. -1);
  6214. random_uuid(guid);
  6215. //UTC Date time
  6216. struct timeval tmnow;
  6217. struct tm *tm;
  6218. char buf[28];//, usec_buf[6];
  6219. gettimeofday(&tmnow, NULL);
  6220. time_t t;
  6221. t = time(NULL);
  6222. /*UTC time and date*/
  6223. tm = gmtime(&t);
  6224. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6225. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6226. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6227. //********************************(1)Current.Import L1************************************************/
  6228. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6229. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6230. (dataType == ReadingContext_Trigger))
  6231. {
  6232. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6233. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6234. {
  6235. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6236. {
  6237. tempIndex = ((gun_index==2) ? 1: 0);
  6238. }
  6239. else
  6240. {
  6241. tempIndex = gun_index;
  6242. }
  6243. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6244. {
  6245. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6246. {
  6247. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6248. }
  6249. }
  6250. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6251. }
  6252. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6253. {
  6254. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6255. {
  6256. tempIndex = ((gun_index==2) ? 1: 0);
  6257. }
  6258. else
  6259. {
  6260. tempIndex = gun_index;
  6261. }
  6262. for (int index = 0; index < CCS_QUANTITY; index++)
  6263. {
  6264. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6265. {
  6266. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6267. }
  6268. }
  6269. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6270. }
  6271. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6272. {
  6273. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6274. {
  6275. tempIndex = ((gun_index==2) ? 1: 0);
  6276. }
  6277. else
  6278. {
  6279. tempIndex = gun_index;
  6280. }
  6281. for (int index = 0; index < GB_QUANTITY; index++)
  6282. {
  6283. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6284. {
  6285. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6286. }
  6287. }
  6288. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6289. }
  6290. else if(gunType[gun_index] == GUN_TYPE_DO)
  6291. {
  6292. tempIndex = gun_index;
  6293. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6294. {
  6295. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6296. {
  6297. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6298. }
  6299. }
  6300. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6301. }
  6302. else
  6303. {
  6304. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6305. {
  6306. tempIndex = 2;
  6307. }
  6308. else
  6309. {
  6310. tempIndex = gun_index;
  6311. }
  6312. for (int index = 0; index < AC_QUANTITY; index++)
  6313. {
  6314. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6315. {
  6316. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6317. }
  6318. }
  6319. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6320. }
  6321. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6322. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6323. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6324. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6325. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6326. }
  6327. //********************************(2)Energy.Active.Import.Register ************************************************/
  6328. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6329. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6330. (dataType == ReadingContext_Trigger))
  6331. {
  6332. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6333. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6334. {
  6335. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6336. {
  6337. tempIndex = ((gun_index==2) ? 1: 0);
  6338. }
  6339. else
  6340. {
  6341. tempIndex = gun_index;
  6342. }
  6343. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6344. {
  6345. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6346. {
  6347. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6348. }
  6349. }
  6350. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6351. }
  6352. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6353. {
  6354. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6355. {
  6356. tempIndex = ((gun_index==2) ? 1: 0);
  6357. }
  6358. else
  6359. {
  6360. tempIndex = gun_index;
  6361. }
  6362. for (int index = 0; index < CCS_QUANTITY; index++)
  6363. {
  6364. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6365. {
  6366. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6367. }
  6368. }
  6369. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6370. }
  6371. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6372. {
  6373. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6374. {
  6375. tempIndex = ((gun_index==2) ? 1: 0);
  6376. }
  6377. else
  6378. {
  6379. tempIndex = gun_index;
  6380. }
  6381. for (int index = 0; index < GB_QUANTITY; index++)
  6382. {
  6383. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6384. {
  6385. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6386. }
  6387. }
  6388. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6389. }
  6390. else if(gunType[gun_index] == GUN_TYPE_DO)
  6391. {
  6392. tempIndex = gun_index;
  6393. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6394. {
  6395. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6396. {
  6397. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6398. }
  6399. }
  6400. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6401. }
  6402. else
  6403. {
  6404. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6405. {
  6406. tempIndex = 2;
  6407. }
  6408. else
  6409. {
  6410. tempIndex = gun_index;
  6411. }
  6412. for (int index = 0; index < AC_QUANTITY; index++)
  6413. {
  6414. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6415. {
  6416. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6417. }
  6418. }
  6419. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6420. }
  6421. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6422. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6423. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6424. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6425. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6426. }
  6427. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6428. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6429. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6430. (dataType == ReadingContext_Trigger))
  6431. {
  6432. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6433. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6434. {
  6435. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6436. {
  6437. tempIndex = ((gun_index==2) ? 1: 0);
  6438. }
  6439. else
  6440. {
  6441. tempIndex = gun_index;
  6442. }
  6443. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6444. {
  6445. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6446. {
  6447. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6448. }
  6449. } // END OF FOR CHAdeMO_QUANTITY
  6450. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6451. }
  6452. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6453. {
  6454. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6455. {
  6456. tempIndex = ((gun_index==2) ? 1: 0);
  6457. }
  6458. else
  6459. {
  6460. tempIndex = gun_index;
  6461. }
  6462. for (int index = 0; index < CCS_QUANTITY; index++)
  6463. {
  6464. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6465. {
  6466. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6467. }
  6468. } // END OF CCS_QUANTITY
  6469. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6470. }
  6471. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6472. {
  6473. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6474. {
  6475. tempIndex = ((gun_index==2) ? 1: 0);
  6476. }
  6477. else
  6478. {
  6479. tempIndex = gun_index;
  6480. }
  6481. for (int index = 0; index < GB_QUANTITY; index++)
  6482. {
  6483. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6484. {
  6485. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6486. }
  6487. } // END OF GB_QUANTITY
  6488. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6489. }
  6490. else if(gunType[gun_index] == GUN_TYPE_DO)
  6491. {
  6492. tempIndex = gun_index;
  6493. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6494. {
  6495. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6496. {
  6497. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6498. }
  6499. }
  6500. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6501. }
  6502. else
  6503. {
  6504. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6505. {
  6506. tempIndex = 2;
  6507. }
  6508. else
  6509. {
  6510. tempIndex = gun_index;
  6511. }
  6512. for (int index = 0; index < AC_QUANTITY; index++)
  6513. {
  6514. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6515. {
  6516. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6517. }
  6518. }
  6519. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6520. }
  6521. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6522. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6523. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6524. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6525. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6526. }
  6527. //********************************(4)Power.Active.Import************************************************/
  6528. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6529. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6530. (dataType == ReadingContext_Trigger))
  6531. {
  6532. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6533. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6534. {
  6535. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6536. {
  6537. tempIndex = ((gun_index==2) ? 1: 0);
  6538. }
  6539. else
  6540. {
  6541. tempIndex = gun_index;
  6542. }
  6543. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6544. {
  6545. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6546. {
  6547. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6548. }
  6549. } // END OF FOR
  6550. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6551. }
  6552. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6553. {
  6554. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6555. {
  6556. tempIndex = ((gun_index==2) ? 1: 0);
  6557. }
  6558. else
  6559. {
  6560. tempIndex = gun_index;
  6561. }
  6562. for (int index = 0; index < CCS_QUANTITY; index++)
  6563. {
  6564. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6565. {
  6566. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6567. }
  6568. }
  6569. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6570. }
  6571. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6572. {
  6573. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6574. {
  6575. tempIndex = ((gun_index==2) ? 1: 0);
  6576. }
  6577. else
  6578. {
  6579. tempIndex = gun_index;
  6580. }
  6581. for (int index = 0; index < GB_QUANTITY; index++)
  6582. {
  6583. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6584. {
  6585. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6586. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6587. }
  6588. }
  6589. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6590. }
  6591. else if(gunType[gun_index] == GUN_TYPE_DO)
  6592. {
  6593. tempIndex = gun_index;
  6594. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6595. {
  6596. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6597. {
  6598. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6599. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6600. }
  6601. }
  6602. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6603. }
  6604. else
  6605. {
  6606. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6607. {
  6608. tempIndex = 2;
  6609. }
  6610. else
  6611. {
  6612. tempIndex = gun_index;
  6613. }
  6614. for (int index = 0; index < AC_QUANTITY; index++)
  6615. {
  6616. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6617. {
  6618. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6619. }
  6620. }
  6621. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6622. }
  6623. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6624. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6625. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6626. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6627. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6628. }
  6629. //***********************************************(5)VOLTAGE L1******************************************************/
  6630. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6631. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6632. (dataType == ReadingContext_Trigger))
  6633. {
  6634. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6635. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6636. {
  6637. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6638. {
  6639. tempIndex = ((gun_index==2) ? 1: 0);
  6640. }
  6641. else
  6642. {
  6643. tempIndex = gun_index;
  6644. }
  6645. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6646. {
  6647. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6648. {
  6649. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6650. }
  6651. }
  6652. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6653. }
  6654. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6655. {
  6656. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6657. {
  6658. tempIndex = ((gun_index==2) ? 1: 0);
  6659. }
  6660. else
  6661. {
  6662. tempIndex = gun_index;
  6663. }
  6664. for (int index = 0; index < CCS_QUANTITY; index++)
  6665. {
  6666. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6667. {
  6668. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6669. }
  6670. }
  6671. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6672. }
  6673. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6674. {
  6675. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6676. {
  6677. tempIndex = ((gun_index==2) ? 1: 0);
  6678. }
  6679. else
  6680. {
  6681. tempIndex = gun_index;
  6682. }
  6683. for (int index = 0; index < GB_QUANTITY; index++)
  6684. {
  6685. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6686. {
  6687. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6688. }
  6689. }
  6690. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6691. }
  6692. else if(gunType[gun_index] == GUN_TYPE_DO)
  6693. {
  6694. tempIndex = gun_index;
  6695. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6696. {
  6697. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6698. {
  6699. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6700. }
  6701. }
  6702. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6703. }
  6704. else
  6705. {
  6706. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6707. {
  6708. tempIndex = 2;
  6709. }
  6710. else
  6711. {
  6712. tempIndex = gun_index;
  6713. }
  6714. for (int index = 0; index < AC_QUANTITY; index++)
  6715. {
  6716. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6717. {
  6718. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6719. }
  6720. }
  6721. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6722. }
  6723. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6724. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6725. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6726. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6727. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6728. }
  6729. //***********************************************(6)SOC******************************************************/
  6730. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6731. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6732. (dataType == ReadingContext_Trigger))
  6733. {
  6734. 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))
  6735. {
  6736. //idx_sample=5;
  6737. //sampledValue = NULL;
  6738. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6739. {
  6740. tempIndex = ((gun_index==2) ? 1: 0);
  6741. }
  6742. else
  6743. {
  6744. tempIndex = gun_index;
  6745. }
  6746. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6747. {
  6748. //tempIndex = ((gun_index==2) ? 1: 0);
  6749. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6750. {
  6751. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6752. {
  6753. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6754. }
  6755. }
  6756. }
  6757. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6758. {
  6759. //tempIndex = ((gun_index==2) ? 1: 0);
  6760. for (int index = 0; index < CCS_QUANTITY; index++)
  6761. {
  6762. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6763. {
  6764. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6765. }
  6766. }
  6767. }
  6768. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6769. {
  6770. //tempIndex = ((gun_index==2) ? 1: 0);
  6771. for (int index = 0; index < GB_QUANTITY; index++)
  6772. {
  6773. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6774. {
  6775. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6776. }
  6777. }
  6778. }
  6779. else if(gunType[gun_index] == GUN_TYPE_DO)
  6780. {
  6781. //tempIndex = ((gun_index==2) ? 1: 0);
  6782. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6783. {
  6784. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6785. {
  6786. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6787. }
  6788. }
  6789. }
  6790. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6791. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6792. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6793. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6794. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6795. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6796. }
  6797. }
  6798. //********************************(7)Current.Import L2************************************************/
  6799. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6800. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6801. (dataType == ReadingContext_Trigger))
  6802. {
  6803. // Only for AC 3 phase
  6804. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6805. {
  6806. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6807. {
  6808. tempIndex = 2;
  6809. }
  6810. else
  6811. {
  6812. tempIndex = gun_index;
  6813. }
  6814. for (int index = 0; index < AC_QUANTITY; index++)
  6815. {
  6816. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6817. {
  6818. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6819. }
  6820. }
  6821. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6822. }
  6823. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6824. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6825. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6826. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6827. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6828. }
  6829. //********************************(8)Current.Import L3************************************************/
  6830. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6831. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6832. (dataType == ReadingContext_Trigger))
  6833. {
  6834. // Only for AC 3 phase
  6835. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6836. {
  6837. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6838. {
  6839. tempIndex = 2;
  6840. }
  6841. else
  6842. {
  6843. tempIndex = gun_index;
  6844. }
  6845. for (int index = 0; index < AC_QUANTITY; index++)
  6846. {
  6847. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6848. {
  6849. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6850. }
  6851. }
  6852. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6853. }
  6854. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6855. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6856. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6857. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6858. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6859. }
  6860. //***********************************************(9)VOLTAGE L2******************************************************/
  6861. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6862. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6863. (dataType == ReadingContext_Trigger))
  6864. {
  6865. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6866. {
  6867. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6868. {
  6869. tempIndex = 2;
  6870. }
  6871. else
  6872. {
  6873. tempIndex = gun_index;
  6874. }
  6875. for (int index = 0; index < AC_QUANTITY; index++)
  6876. {
  6877. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6878. {
  6879. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6880. }
  6881. }
  6882. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6883. }
  6884. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6885. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6886. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6887. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6888. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6889. }
  6890. //***********************************************(10)VOLTAGE L3******************************************************/
  6891. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6892. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6893. (dataType == ReadingContext_Trigger))
  6894. {
  6895. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6896. {
  6897. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6898. {
  6899. tempIndex = 2;
  6900. }
  6901. else
  6902. {
  6903. tempIndex = gun_index;
  6904. }
  6905. for (int index = 0; index < AC_QUANTITY; index++)
  6906. {
  6907. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6908. {
  6909. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6910. }
  6911. }
  6912. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6913. }
  6914. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6915. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6916. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6917. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6918. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6919. }
  6920. //***********************************************(11)Current.Offered******************************************************/
  6921. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6922. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6923. (dataType == ReadingContext_Trigger))
  6924. {
  6925. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6926. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6927. {
  6928. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6929. {
  6930. tempIndex = ((gun_index==2) ? 1: 0);
  6931. }
  6932. else
  6933. {
  6934. tempIndex = gun_index;
  6935. }
  6936. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6937. {
  6938. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6939. {
  6940. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  6941. }
  6942. } // END OF FOR CHAdeMO_QUANTITY
  6943. }
  6944. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6945. {
  6946. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6947. {
  6948. tempIndex = ((gun_index==2) ? 1: 0);
  6949. }
  6950. else
  6951. {
  6952. tempIndex = gun_index;
  6953. }
  6954. for (int index = 0; index < CCS_QUANTITY; index++)
  6955. {
  6956. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6957. {
  6958. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  6959. }
  6960. } // END OF CCS_QUANTITY
  6961. }
  6962. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6963. {
  6964. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6965. {
  6966. tempIndex = ((gun_index==2) ? 1: 0);
  6967. }
  6968. else
  6969. {
  6970. tempIndex = gun_index;
  6971. }
  6972. for (int index = 0; index < GB_QUANTITY; index++)
  6973. {
  6974. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6975. {
  6976. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  6977. }
  6978. } // END OF GB_QUANTITY
  6979. }
  6980. else if(gunType[gun_index] == GUN_TYPE_DO)
  6981. {
  6982. tempIndex = gun_index;
  6983. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6984. {
  6985. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6986. {
  6987. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  6988. }
  6989. }
  6990. }
  6991. else
  6992. {
  6993. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6994. {
  6995. tempIndex = 2;
  6996. }
  6997. else
  6998. {
  6999. tempIndex = gun_index;
  7000. }
  7001. for (int index = 0; index < AC_QUANTITY; index++)
  7002. {
  7003. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7004. {
  7005. uint16_t currentOffer;
  7006. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7007. {
  7008. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7009. }
  7010. else
  7011. {
  7012. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7013. }
  7014. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7015. }
  7016. }
  7017. }
  7018. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7019. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7020. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7021. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7022. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7023. }
  7024. //***********************************************(12)Power.Offered******************************************************/
  7025. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7026. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7027. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7028. {
  7029. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7030. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7031. {
  7032. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7033. {
  7034. tempIndex = ((gun_index==2) ? 1: 0);
  7035. }
  7036. else
  7037. {
  7038. tempIndex = gun_index;
  7039. }
  7040. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7041. {
  7042. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7043. {
  7044. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7045. }
  7046. } // END OF FOR CHAdeMO_QUANTITY
  7047. }
  7048. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7049. {
  7050. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7051. {
  7052. tempIndex = ((gun_index==2) ? 1: 0);
  7053. }
  7054. else
  7055. {
  7056. tempIndex = gun_index;
  7057. }
  7058. for (int index = 0; index < CCS_QUANTITY; index++)
  7059. {
  7060. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7061. {
  7062. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7063. }
  7064. } // END OF CCS_QUANTITY
  7065. }
  7066. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7067. {
  7068. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7069. {
  7070. tempIndex = ((gun_index==2) ? 1: 0);
  7071. }
  7072. else
  7073. {
  7074. tempIndex = gun_index;
  7075. }
  7076. for (int index = 0; index < GB_QUANTITY; index++)
  7077. {
  7078. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7079. {
  7080. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7081. }
  7082. } // END OF GB_QUANTITY
  7083. }
  7084. else if(gunType[gun_index] == GUN_TYPE_DO)
  7085. {
  7086. tempIndex = gun_index;
  7087. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7088. {
  7089. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7090. {
  7091. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7092. }
  7093. }
  7094. }
  7095. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7096. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7097. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7098. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7099. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7100. }
  7101. // Message create ====================================================================================================
  7102. if(TRUE)
  7103. {
  7104. json_object *MeterValueReq = json_object_new_object();
  7105. json_object *MeterValues = json_object_new_array();
  7106. json_object *sampledValues = json_object_new_array();
  7107. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7108. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7109. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7110. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7111. {
  7112. json_object *MeterValue = json_object_new_object();
  7113. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7114. {
  7115. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7116. {
  7117. json_object *sampledValue = json_object_new_object();
  7118. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7119. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7120. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7121. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7122. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7123. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7124. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7125. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7126. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7127. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7128. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7129. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7130. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7131. json_object_array_add(sampledValues, sampledValue);
  7132. }
  7133. }
  7134. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7135. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7136. json_object_array_add(MeterValues, MeterValue);
  7137. }
  7138. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7139. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7140. ,gun_index + 1
  7141. ,MESSAGE_TYPE_CALL
  7142. ,guid
  7143. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7144. json_object_put(MeterValueReq);
  7145. }
  7146. // Put request guid to hash map
  7147. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7148. 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*/)
  7149. {
  7150. result = PASS;
  7151. //DEBUG_INFO("MeterValues mapitem pass\n");
  7152. }
  7153. if((dataType != ReadingContext_Trigger) &&
  7154. (dataType != ReadingContext_Sample_Clock) &&
  7155. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7156. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7157. else
  7158. {
  7159. if(FirstHeartBeat)
  7160. LWS_Send(queuedata +2);
  7161. }
  7162. return result;
  7163. }
  7164. int sendLogStatusNotificationRequest(char *status)
  7165. {
  7166. mtrace();
  7167. int result = PASS;
  7168. char message[4096]={0};
  7169. char guid[37]={0};
  7170. char tempdata[128]={0};
  7171. json_object *LogStatusNotification = json_object_new_object();
  7172. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7173. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7174. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7175. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7176. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7177. random_uuid(guid);
  7178. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7179. json_object_put(LogStatusNotification);
  7180. LWS_Send(message);
  7181. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7182. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7183. {
  7184. result = PASS;
  7185. }
  7186. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7187. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7188. return result;
  7189. }
  7190. int sendSecurityEventNotificationRequest()
  7191. {
  7192. mtrace();
  7193. int result = PASS;
  7194. char message[4096]={0};
  7195. char guid[37]={0};
  7196. char tempdata[128]={0};
  7197. json_object *SecurityEventNotification = json_object_new_object();
  7198. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7199. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7200. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7201. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7202. random_uuid(guid);
  7203. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7204. json_object_put(SecurityEventNotification);
  7205. LWS_Send(message);
  7206. sprintf(tempdata, "SecurityEventNotification,0");
  7207. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7208. {
  7209. result = PASS;
  7210. }
  7211. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7212. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7213. return result;
  7214. }
  7215. int sendSignCertificateRequest()
  7216. {
  7217. mtrace();
  7218. int result = PASS;
  7219. char message[4096]={0};
  7220. char guid[37]={0};
  7221. char tempdata[128]={0};
  7222. json_object *SignCertificate = json_object_new_object();
  7223. DEBUG_INFO("sendSignCertificateRequest...\n");
  7224. // Read csr file content
  7225. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7226. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7227. char *line = NULL;
  7228. size_t len = 0;
  7229. while(getline(&line, &len, fp) != -1)
  7230. {
  7231. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7232. {
  7233. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7234. }
  7235. }
  7236. fclose(fp);
  7237. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7238. random_uuid(guid);
  7239. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7240. json_object_put(SignCertificate);
  7241. LWS_Send(message);
  7242. sprintf(tempdata, "SignCertificate,0");
  7243. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7244. {
  7245. result = PASS;
  7246. }
  7247. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7248. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7249. return result;
  7250. }
  7251. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7252. {
  7253. mtrace();
  7254. int result = PASS;
  7255. char message[110]={0};
  7256. char guid[37]={0};
  7257. char tempdata[65]={0};
  7258. json_object *FirmwareStatusNotification = json_object_new_object();
  7259. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7260. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7261. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7262. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7263. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7264. random_uuid(guid);
  7265. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7266. json_object_put(FirmwareStatusNotification);
  7267. LWS_Send(message);
  7268. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7269. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7270. {
  7271. result = PASS;
  7272. }
  7273. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7274. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7275. return result;
  7276. }
  7277. //==========================================
  7278. // send confirm routine
  7279. //==========================================
  7280. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7281. {
  7282. mtrace();
  7283. int result = FAIL;
  7284. char message[100]={0};
  7285. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7286. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7287. LWS_Send(message);
  7288. result = TRUE;
  7289. return result;
  7290. }
  7291. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7292. {
  7293. mtrace();
  7294. int result = FAIL;
  7295. char message[100]={0};
  7296. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7297. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7298. LWS_Send(message);
  7299. result = TRUE;
  7300. return result;
  7301. }
  7302. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7303. {
  7304. mtrace();
  7305. int result = FAIL;
  7306. char message[100]={0};
  7307. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7308. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7309. LWS_Send(message);
  7310. result = TRUE;
  7311. return result;
  7312. }
  7313. int sendClearCacheConfirmation(char *uuid,char *payload)
  7314. {
  7315. mtrace();
  7316. int result = FAIL;
  7317. char message[500]={0};
  7318. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7319. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7320. LWS_Send(message);
  7321. return result;
  7322. }
  7323. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7324. {
  7325. mtrace();
  7326. int result = FAIL;
  7327. char message[500]={0};
  7328. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7329. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7330. LWS_Send(message);
  7331. return result;
  7332. }
  7333. int sendDataTransferConfirmation(char *uuid,char *payload)
  7334. {
  7335. mtrace();
  7336. char statusStr[20]={0};
  7337. char dataStr[10]={0};
  7338. char sstr[20]={0};
  7339. int c = 0;
  7340. char *loc;
  7341. int result = FAIL;
  7342. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7343. /**********************status**************************/
  7344. loc = strstr(payload, "status");
  7345. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7346. c = 0;
  7347. while (loc[3+strlen("status")+c] != '\"')
  7348. {
  7349. sstr[c] = loc[3+strlen("status")+c];
  7350. c++;
  7351. }
  7352. sstr[c] = '\0';
  7353. strcpy(statusStr, sstr);
  7354. /**********************data**************************/
  7355. loc = strstr(payload, "data");
  7356. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7357. c = 0;
  7358. while (loc[3+strlen("data")+c] != '\"')
  7359. {
  7360. sstr[c] = loc[3+strlen("data")+c];
  7361. c++;
  7362. }
  7363. sstr[c] = '\0';
  7364. strcpy(dataStr, sstr);
  7365. return result;
  7366. }
  7367. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7368. {
  7369. mtrace();
  7370. int result = FAIL;
  7371. char message[1000]={0};
  7372. int CompositeScheduleIndex = 0;
  7373. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7374. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7375. if(nPeriod == 0)
  7376. {
  7377. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7378. {
  7379. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7380. ,MESSAGE_TYPE_CALLRESULT
  7381. ,uuid
  7382. ,payload
  7383. ,connectorIdInt);
  7384. }
  7385. else
  7386. {
  7387. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7388. ,MESSAGE_TYPE_CALLRESULT
  7389. ,uuid
  7390. ,payload
  7391. ,connectorIdInt
  7392. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7393. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7394. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7395. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7396. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7397. }
  7398. }
  7399. else
  7400. {
  7401. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7402. ,MESSAGE_TYPE_CALLRESULT
  7403. ,uuid
  7404. ,payload
  7405. ,connectorIdInt
  7406. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7407. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7408. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7409. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7410. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7411. {
  7412. if (idx_sample == 0)
  7413. {
  7414. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7415. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7416. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7417. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7418. }
  7419. else
  7420. {
  7421. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7422. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7423. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7424. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7425. }
  7426. }
  7427. sprintf(message + strlen(message), "]}}]");
  7428. }
  7429. LWS_Send(message);
  7430. result = TRUE;
  7431. return result;
  7432. }
  7433. int sendGetConfigurationConfirmation(char *uuid)
  7434. {
  7435. mtrace();
  7436. int result = FAIL;
  7437. int MaxKeySupported = 0;
  7438. int sentConfigurationNumber= 0;
  7439. int sentunConfigurationNumber= 0;
  7440. char message[1024*10]={0};
  7441. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7442. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7443. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7444. ,MESSAGE_TYPE_CALLRESULT
  7445. ,uuid );
  7446. //configuration key
  7447. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7448. {
  7449. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7450. {
  7451. if (sentConfigurationNumber == 0)
  7452. {
  7453. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7454. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7455. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7456. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7457. }
  7458. else
  7459. {
  7460. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7461. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7462. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7463. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7464. }
  7465. sentConfigurationNumber = sentConfigurationNumber + 1;
  7466. }
  7467. }
  7468. sprintf(message + strlen(message), "]");
  7469. if(UnknownKeynum != 0)
  7470. {
  7471. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7472. //unkown key
  7473. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7474. {
  7475. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7476. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7477. if(sentunConfigurationNumber == 0)
  7478. {
  7479. sprintf(message + strlen(message), "\"%s\""
  7480. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7481. }
  7482. else
  7483. {
  7484. sprintf(message + strlen(message), ",\"%s\""
  7485. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7486. }
  7487. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7488. }
  7489. sprintf(message + strlen(message), "]");
  7490. }
  7491. sprintf(message + strlen(message), "}]");
  7492. LWS_Send(message);
  7493. return result;
  7494. }
  7495. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7496. {
  7497. mtrace();
  7498. int result = FAIL;
  7499. char message[400]={0};
  7500. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7501. if(strcmp(payload,"")==0)
  7502. {
  7503. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7504. }
  7505. else
  7506. {
  7507. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7508. }
  7509. LWS_Send(message);
  7510. result = TRUE;
  7511. return result;
  7512. }
  7513. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7514. {
  7515. mtrace();
  7516. int result = FAIL;
  7517. char message[80]={0};
  7518. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7519. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  7520. LWS_Send(message);
  7521. result = TRUE;
  7522. return result;
  7523. }
  7524. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7525. {
  7526. mtrace();
  7527. int result = FAIL;
  7528. char message[80]={0};
  7529. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7530. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7531. LWS_Send(message);
  7532. result = TRUE;
  7533. return result;
  7534. }
  7535. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7536. {
  7537. mtrace();
  7538. int result = FAIL;
  7539. char message[80]={0};
  7540. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7541. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7542. LWS_Send(message);
  7543. result = TRUE;
  7544. return result;
  7545. }
  7546. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7547. {
  7548. mtrace();
  7549. int result = FAIL;
  7550. char message[80]={0};
  7551. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7552. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7553. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7554. LWS_Send(message);
  7555. result = TRUE;
  7556. return result;
  7557. }
  7558. int sendResetConfirmation(char *uuid,char *payload)
  7559. {
  7560. mtrace();
  7561. int result = FAIL;
  7562. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7563. char message[80]={0};
  7564. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  7565. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7566. LWS_Send(message);
  7567. result = TRUE;
  7568. return result;
  7569. }
  7570. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7571. {
  7572. mtrace();
  7573. int result = FAIL;
  7574. char message[500]={0};
  7575. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7576. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7577. LWS_Send(message);
  7578. result = TRUE;
  7579. return result;
  7580. }
  7581. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7582. {
  7583. mtrace();
  7584. int result = FAIL;
  7585. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7586. char message[80]={0};
  7587. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7588. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7589. LWS_Send(message);
  7590. result = TRUE;
  7591. return result;
  7592. }
  7593. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7594. {
  7595. mtrace();
  7596. int result = FAIL;
  7597. char message[80]={0};
  7598. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7599. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7600. LWS_Send(message);
  7601. result = TRUE;
  7602. return result;
  7603. }
  7604. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7605. {
  7606. mtrace();
  7607. int result = FAIL;
  7608. char message[80]={0};
  7609. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7610. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7611. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7612. LWS_Send(message);
  7613. result = TRUE;
  7614. return result;
  7615. }
  7616. int sendUpdateFirmwareConfirmation(char *uuid)
  7617. {
  7618. mtrace();
  7619. int result = FAIL;
  7620. char message[60]={0};
  7621. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7622. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7623. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7624. LWS_Send(message);
  7625. result = TRUE;
  7626. return result;
  7627. }
  7628. int sendCertificateSignedConfirmation(char *uuid)
  7629. {
  7630. mtrace();
  7631. int result = PASS;
  7632. char message[4096]={0};
  7633. json_object *CertificateSigned = json_object_new_object();
  7634. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7635. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  7636. sprintf(message,"[%d,\"%s\",%s]"
  7637. ,MESSAGE_TYPE_CALLRESULT
  7638. ,uuid
  7639. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7640. json_object_put(CertificateSigned);
  7641. LWS_Send(message);
  7642. return result;
  7643. }
  7644. int sendDeleteCertificateConfirmation(char *uuid)
  7645. {
  7646. mtrace();
  7647. int result = PASS;
  7648. char message[4096]={0};
  7649. json_object *DeleteCertificate = json_object_new_object();
  7650. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7651. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  7652. sprintf(message,"[%d,\"%s\",%s]"
  7653. ,MESSAGE_TYPE_CALLRESULT
  7654. ,uuid
  7655. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7656. json_object_put(DeleteCertificate);
  7657. LWS_Send(message);
  7658. return result;
  7659. }
  7660. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7661. {
  7662. mtrace();
  7663. int result = PASS;
  7664. char message[4096]={0};
  7665. json_object *ExtendedTriggerMessage = json_object_new_object();
  7666. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7667. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  7668. sprintf(message,"[%d,\"%s\",%s]"
  7669. ,MESSAGE_TYPE_CALLRESULT
  7670. ,uuid
  7671. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7672. json_object_put(ExtendedTriggerMessage);
  7673. LWS_Send(message);
  7674. return result;
  7675. }
  7676. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7677. {
  7678. mtrace();
  7679. int result = PASS;
  7680. char message[4096]={0};
  7681. json_object *GetInstalledCertificateIds = json_object_new_object();
  7682. json_object *certificateHashDataDatas = json_object_new_array();
  7683. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7684. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  7685. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7686. {
  7687. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7688. {
  7689. json_object *certificateHashData = json_object_new_object();
  7690. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7691. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7692. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7693. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7694. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7695. }
  7696. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7697. }
  7698. else
  7699. {
  7700. json_object_put(certificateHashDataDatas);
  7701. }
  7702. sprintf(message,"[%d,\"%s\",%s]"
  7703. ,MESSAGE_TYPE_CALLRESULT
  7704. ,uuid
  7705. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7706. json_object_put(GetInstalledCertificateIds);
  7707. LWS_Send(message);
  7708. return result;
  7709. }
  7710. int sendGetLogConfirmation(char *uuid)
  7711. {
  7712. mtrace();
  7713. int result = PASS;
  7714. char message[4096]={0};
  7715. json_object *GetLog = json_object_new_object();
  7716. DEBUG_INFO("sendGetLogConfirmation...\n");
  7717. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  7718. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  7719. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  7720. sprintf(message,"[%d,\"%s\",%s]"
  7721. ,MESSAGE_TYPE_CALLRESULT
  7722. ,uuid
  7723. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7724. json_object_put(GetLog);
  7725. LWS_Send(message);
  7726. return result;
  7727. }
  7728. int sendInstallCertificateConfirmation(char *uuid)
  7729. {
  7730. mtrace();
  7731. int result = PASS;
  7732. char message[4096]={0};
  7733. json_object *InstallCertificate = json_object_new_object();
  7734. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7735. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  7736. sprintf(message,"[%d,\"%s\",%s]"
  7737. ,MESSAGE_TYPE_CALLRESULT
  7738. ,uuid
  7739. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7740. json_object_put(InstallCertificate);
  7741. LWS_Send(message);
  7742. return result;
  7743. }
  7744. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7745. {
  7746. mtrace();
  7747. int result = PASS;
  7748. char message[4096]={0};
  7749. json_object *SignedUpdateFirmware = json_object_new_object();
  7750. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7751. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  7752. sprintf(message,"[%d,\"%s\",%s]"
  7753. ,MESSAGE_TYPE_CALLRESULT
  7754. ,uuid
  7755. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7756. json_object_put(SignedUpdateFirmware);
  7757. LWS_Send(message);
  7758. return result;
  7759. }
  7760. int sendUnknownConfirmation(char *uuid)
  7761. {
  7762. mtrace();
  7763. int result = PASS;
  7764. char message[256]={0};
  7765. DEBUG_INFO("sendUnknownConfirmation...\n");
  7766. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7767. LWS_Send(message);
  7768. return result;
  7769. }
  7770. //==========================================
  7771. // Handle server request routine Start
  7772. //==========================================
  7773. int handleCancelReservationRequest(char *uuid, char *payload)
  7774. {
  7775. mtrace();
  7776. int result = FAIL;
  7777. int gunNO = 0;
  7778. int reservationIdInt = -1;
  7779. char comfirmstr[20];
  7780. DEBUG_INFO("handleCancelReservationRequest...\n");
  7781. json_object *CancelReservation;
  7782. CancelReservation = json_tokener_parse(payload);
  7783. if(!is_error(CancelReservation))
  7784. {
  7785. // Required data
  7786. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7787. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7788. }
  7789. json_object_put(CancelReservation);
  7790. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7791. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7792. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7793. if(reservationIdInt != -1)
  7794. {
  7795. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7796. //check Transaction active
  7797. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7798. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7799. {
  7800. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7801. {
  7802. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7803. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7804. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7805. {
  7806. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7807. }
  7808. else
  7809. {
  7810. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7811. }
  7812. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7813. goto end;
  7814. }
  7815. }
  7816. for (int index = 0; index < CCS_QUANTITY; index++)
  7817. {
  7818. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7819. {
  7820. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7821. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7822. if(gunType[2] == GUN_TYPE_CCS)
  7823. {
  7824. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7825. }
  7826. else
  7827. {
  7828. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7829. }
  7830. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7831. goto end;
  7832. }
  7833. }
  7834. for (int index = 0; index < GB_QUANTITY; index++)
  7835. {
  7836. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7837. {
  7838. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7839. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7840. if(gunType[2] == GUN_TYPE_GBT)
  7841. {
  7842. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7843. }
  7844. else
  7845. {
  7846. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7847. }
  7848. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7849. goto end;
  7850. }
  7851. }
  7852. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7853. {
  7854. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7855. {
  7856. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7857. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7858. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7859. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7860. goto end;
  7861. }
  7862. }
  7863. for (int index = 0; index < AC_QUANTITY; index++)
  7864. {
  7865. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7866. {
  7867. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7868. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7869. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7870. {
  7871. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7872. }
  7873. else
  7874. {
  7875. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7876. }
  7877. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7878. goto end;
  7879. }
  7880. }
  7881. }
  7882. //The reservationId does NOT match the reservationId
  7883. sendCancelReservationConfirmation(uuid, comfirmstr);
  7884. end:
  7885. // Fill in ocpp packet uuid
  7886. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  7887. return result;
  7888. }
  7889. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7890. {
  7891. mtrace();
  7892. int result = FAIL;
  7893. int gunIndex = -1;
  7894. char typeStr[16]={0};
  7895. char comfirmstr[20];
  7896. int specificId = FALSE;
  7897. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7898. json_object *ChangeAvailability;
  7899. ChangeAvailability = json_tokener_parse(payload);
  7900. if(!is_error(ChangeAvailability))
  7901. {
  7902. // Required data
  7903. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7904. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7905. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7906. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7907. }
  7908. json_object_put(ChangeAvailability);
  7909. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7910. {
  7911. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7912. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7913. }
  7914. else if(gunIndex == 0)
  7915. {
  7916. for(int i=0; i < gunTotalNumber; i++)
  7917. {
  7918. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  7919. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  7920. }
  7921. }
  7922. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7923. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7924. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7925. {
  7926. specificId = TRUE;
  7927. }
  7928. if(specificId == FALSE)
  7929. goto end;
  7930. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7931. {
  7932. //----------------------gunIndex is 0 ------------------------------------------------//
  7933. if(gunIndex == 0)
  7934. {
  7935. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7936. {
  7937. for(int i=0; i < gunTotalNumber; i++)
  7938. {
  7939. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7940. {
  7941. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7942. {
  7943. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7944. {
  7945. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7946. goto end;
  7947. }
  7948. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7949. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7950. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7951. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7952. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7953. {
  7954. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7955. goto end;
  7956. }
  7957. }
  7958. }//END FOR CHAdeMO_QUANTITY
  7959. for (int index = 0; index < CCS_QUANTITY; index++)
  7960. {
  7961. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7962. {
  7963. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7964. {
  7965. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7966. goto end;
  7967. }
  7968. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7969. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7970. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7971. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7972. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7973. {
  7974. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7975. goto end;
  7976. }
  7977. }
  7978. }//END FOR CCS_QUANTITY
  7979. for (int index = 0; index < GB_QUANTITY; index++)
  7980. {
  7981. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7982. {
  7983. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7984. {
  7985. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7986. goto end;
  7987. }
  7988. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7989. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7990. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7991. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7992. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7993. {
  7994. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7995. goto end;
  7996. }
  7997. }
  7998. }// END FOR GB_QUANTITY
  7999. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8000. {
  8001. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8002. {
  8003. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8004. {
  8005. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8006. goto end;
  8007. }
  8008. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8009. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8010. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8011. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8012. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8013. {
  8014. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8015. goto end;
  8016. }
  8017. }
  8018. }// END FOR GENERAL_GUN_QUANTITY
  8019. for (int index = 0; index < AC_QUANTITY; index++)
  8020. {
  8021. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8022. {
  8023. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8024. {
  8025. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8026. goto end;
  8027. }
  8028. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8029. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8030. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8031. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8032. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8033. {
  8034. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8035. goto end;
  8036. }
  8037. }
  8038. }//END FOR AC_QUANTITY
  8039. }// END FOR gunTotalNumber
  8040. }
  8041. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8042. {
  8043. for(int i=0; i < gunTotalNumber; i++)
  8044. {
  8045. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8046. {
  8047. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8048. goto end;
  8049. }
  8050. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8051. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8052. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8053. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8054. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8055. {
  8056. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8057. goto end;
  8058. }
  8059. }
  8060. }
  8061. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8062. goto end;
  8063. }
  8064. //----------------------gunIndex is not 0 ------------------------------------------------//
  8065. //check Transaction active
  8066. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8067. {
  8068. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8069. {
  8070. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8071. {
  8072. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8073. goto end;
  8074. }
  8075. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8076. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8077. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8078. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8079. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8080. {
  8081. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8082. goto end;
  8083. }
  8084. else
  8085. {
  8086. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8087. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8088. goto end;
  8089. }
  8090. }
  8091. }//END FOR CHAdeMO_QUANTITY
  8092. for (int index = 0; index < CCS_QUANTITY; index++)
  8093. {
  8094. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8095. {
  8096. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8097. {
  8098. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8099. goto end;
  8100. }
  8101. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8102. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8103. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8104. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8105. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8106. {
  8107. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8108. goto end;
  8109. }
  8110. else
  8111. {
  8112. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8113. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8114. goto end;
  8115. }
  8116. }
  8117. }//END FOR CCS_QUANTITY
  8118. for (int index = 0; index < GB_QUANTITY; index++)
  8119. {
  8120. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8121. {
  8122. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8123. {
  8124. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8125. goto end;
  8126. }
  8127. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8128. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8129. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8130. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8131. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8132. {
  8133. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8134. goto end;
  8135. }
  8136. else
  8137. {
  8138. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8139. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8140. goto end;
  8141. }
  8142. }
  8143. }// END FOR GB_QUANTITY
  8144. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8145. {
  8146. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8147. {
  8148. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8149. {
  8150. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8151. goto end;
  8152. }
  8153. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8154. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8155. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8156. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8157. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8158. {
  8159. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8160. goto end;
  8161. }
  8162. else
  8163. {
  8164. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8165. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8166. goto end;
  8167. }
  8168. }
  8169. }// END FOR GENERAL_GUN_QUANTITY
  8170. for (int index = 0; index < AC_QUANTITY; index++)
  8171. {
  8172. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8173. {
  8174. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8175. {
  8176. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8177. goto end;
  8178. }
  8179. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8180. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8181. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8182. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8183. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8184. {
  8185. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8186. goto end;
  8187. }
  8188. else
  8189. {
  8190. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8191. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8192. goto end;
  8193. }
  8194. }
  8195. }//END FOR AC_QUANTITY
  8196. }//END FOR AvailabilityTypeStr[Inoperative]
  8197. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8198. {
  8199. //----------------------gunIndex is 0 ------------------------------------------------//
  8200. if(gunIndex == 0)
  8201. {
  8202. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8203. {
  8204. for(int i=0; i < gunTotalNumber; i++)
  8205. {
  8206. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8207. {
  8208. 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
  8209. {
  8210. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8211. goto end;
  8212. }
  8213. }//END FOR CHAdeMO_QUANTITY
  8214. for (int index = 0; index < CCS_QUANTITY; index++)
  8215. {
  8216. 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
  8217. {
  8218. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8219. goto end;
  8220. }
  8221. }//END FOR CCS_QUANTITY
  8222. for (int index = 0; index < GB_QUANTITY; index++)
  8223. {
  8224. 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
  8225. {
  8226. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8227. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8228. goto end;
  8229. }
  8230. }// END FOR GB_QUANTITY
  8231. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8232. {
  8233. 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
  8234. {
  8235. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8236. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8237. goto end;
  8238. }
  8239. }// END FOR GENERAL_GUN_QUANTITY
  8240. for (int index = 0; index < AC_QUANTITY; index++)
  8241. {
  8242. 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
  8243. {
  8244. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8245. goto end;
  8246. }
  8247. }//END FOR CHAdeMO_QUANTITY
  8248. }// END FOR gunTotalNumber
  8249. }
  8250. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8251. {
  8252. for(int i=0; i < gunTotalNumber; i++)
  8253. {
  8254. for (int index = 0; index < AC_QUANTITY; index++)
  8255. {
  8256. 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
  8257. {
  8258. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8259. goto end;
  8260. }
  8261. }//END FOR CHAdeMO_QUANTITY
  8262. } // END FOR gunTotalNumber
  8263. }
  8264. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8265. goto end;
  8266. }
  8267. //----------------------gunIndex is not 0 ------------------------------------------------//
  8268. //check Transaction active
  8269. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8270. {
  8271. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8272. {
  8273. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8274. goto end;
  8275. }
  8276. }//END FOR CHAdeMO_QUANTITY
  8277. for (int index = 0; index < CCS_QUANTITY; index++)
  8278. {
  8279. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8280. {
  8281. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8282. goto end;
  8283. }
  8284. }//END FOR CCS_QUANTITY
  8285. for (int index = 0; index < GB_QUANTITY; index++)
  8286. {
  8287. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8288. {
  8289. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8290. goto end;
  8291. }
  8292. }// END FOR GB_QUANTITY
  8293. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8294. {
  8295. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8296. {
  8297. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8298. goto end;
  8299. }
  8300. }// END FOR GENERAL_GUN_QUANTITY
  8301. for (int index = 0; index < AC_QUANTITY; index++)
  8302. {
  8303. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8304. {
  8305. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8306. goto end;
  8307. }
  8308. }//END FOR AC_QUANTITY
  8309. }//END FOR AvailabilityTypeStr[Operative]
  8310. end:
  8311. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8312. {
  8313. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8314. }
  8315. else
  8316. {
  8317. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8318. }
  8319. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8320. {
  8321. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8322. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8323. }
  8324. else if(gunIndex == 0)
  8325. {
  8326. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8327. {
  8328. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8329. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8330. }
  8331. }
  8332. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8333. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8334. return result;
  8335. }
  8336. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8337. {
  8338. mtrace();
  8339. int valueInvalid = NO;
  8340. int result = FAIL;
  8341. char keystr[40]={0};
  8342. char valuestr[501]={0}; //value should be limited in 500 bytes
  8343. char comfirmstr[20]={0};
  8344. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8345. json_object *ChangeConfiguration;
  8346. ChangeConfiguration = json_tokener_parse(payload);
  8347. if(!is_error(ChangeConfiguration))
  8348. {
  8349. // Required data
  8350. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8351. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8352. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8353. {
  8354. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8355. }
  8356. else
  8357. {
  8358. valueInvalid = YES;
  8359. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8360. }
  8361. }
  8362. json_object_put(ChangeConfiguration);
  8363. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  8364. {
  8365. DEBUG_ERROR("Payload is null or value is invalid.\n");
  8366. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8367. }
  8368. else
  8369. {
  8370. int status = setKeyValue(keystr, valuestr);
  8371. switch(status)
  8372. {
  8373. case ConfigurationStatus_Accepted:
  8374. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8375. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8376. StoreConfigurationTable();
  8377. break;
  8378. case RebootRequired:
  8379. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8380. StoreConfigurationTable();
  8381. break;
  8382. case NotSupported:
  8383. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8384. break;
  8385. case ConfigurationStatus_Rejected:
  8386. default:
  8387. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8388. break;
  8389. }
  8390. }
  8391. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8392. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8393. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8394. {
  8395. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8396. SetOcppConnStatus(FALSE);
  8397. }
  8398. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8399. {
  8400. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8401. }
  8402. return result;
  8403. }
  8404. int handleClearCacheRequest(char *uuid, char *payload)
  8405. {
  8406. mtrace();
  8407. int result = FAIL;
  8408. char comfirmstr[20];
  8409. char rmFileCmd[100]={0};
  8410. struct stat stats;
  8411. DEBUG_INFO("handleClearCacheRequest...\n");
  8412. stat("/Storage/OCPP", &stats);
  8413. // Check for directory existence
  8414. if (S_ISDIR(stats.st_mode) == 1)
  8415. {}
  8416. else
  8417. {
  8418. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8419. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  8420. system(rmFileCmd);
  8421. }
  8422. if(OCPP_cleanLocalCache())
  8423. {
  8424. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8425. }
  8426. else
  8427. {
  8428. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8429. }
  8430. sendClearCacheConfirmation(uuid, comfirmstr);
  8431. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8432. return result;
  8433. }
  8434. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8435. {
  8436. mtrace();
  8437. int result = FAIL;
  8438. int resultRename;
  8439. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8440. char chargingProfilePurposeStr[26]={0};
  8441. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8442. char tempchargingProfilePurposeStr[26]={0};
  8443. char str[100]={0};
  8444. char fname[200]={0};
  8445. char comfirmstr[20]={0};
  8446. char word[1600]={0};
  8447. int clearflag = FALSE;
  8448. int chargingProfileIdIsNULL = FALSE;
  8449. int connectorIsNULL = FALSE;
  8450. int chargingProfilePurposeIsNULL = FALSE;
  8451. int stackLevelIsNULL = FALSE;
  8452. //int GotoEnd = FALSE;
  8453. FILE *fptr1, *fptr2;
  8454. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  8455. int n_chargingProfile=0;
  8456. int isEmptyFile = FALSE;
  8457. char sLineWord[1600]={0};
  8458. char chargingProfiles[10][100]={0};
  8459. int ChargeProfileCount = 0;
  8460. int ch;
  8461. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8462. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8463. json_object *ClearChargingProfile;
  8464. ClearChargingProfile = json_tokener_parse(payload);
  8465. if(!is_error(ClearChargingProfile))
  8466. {
  8467. // Optional data
  8468. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8469. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8470. else
  8471. chargingProfileIdIsNULL = TRUE;
  8472. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8473. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8474. else
  8475. connectorIsNULL = TRUE;
  8476. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8477. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8478. else
  8479. chargingProfilePurposeIsNULL = TRUE;
  8480. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8481. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8482. else
  8483. stackLevelIsNULL = TRUE;
  8484. }
  8485. json_object_put(ClearChargingProfile);
  8486. if(connectorIsNULL == FALSE)
  8487. {
  8488. switch(connectorIdInt)
  8489. {
  8490. case 0:
  8491. if(chargingProfilePurposeIsNULL == TRUE)
  8492. {
  8493. int l = 0;
  8494. strcpy(fname, ChargePointMaxProfile_JSON);
  8495. if((access(fname,F_OK))!=-1)
  8496. {
  8497. strcpy(chargingProfiles[l], fname);
  8498. l = l + 1;
  8499. }
  8500. strcpy(fname, TxDefaultProfile_0_JSON);
  8501. if((access(fname,F_OK))!=-1)
  8502. {
  8503. strcpy(chargingProfiles[l], fname);
  8504. l = l + 1;
  8505. }
  8506. ChargeProfileCount = l;
  8507. }
  8508. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8509. {
  8510. strcpy(fname, ChargePointMaxProfile_JSON);
  8511. if((access(fname,F_OK))!=-1)
  8512. {
  8513. strcpy(chargingProfiles[0], fname);
  8514. ChargeProfileCount = 1;
  8515. }
  8516. }
  8517. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8518. {
  8519. strcpy(fname, TxDefaultProfile_0_JSON);
  8520. if((access(fname,F_OK))!=-1)
  8521. {
  8522. strcpy(chargingProfiles[0], fname);
  8523. ChargeProfileCount = 1;
  8524. }
  8525. }
  8526. break;
  8527. default:
  8528. if(chargingProfilePurposeIsNULL == TRUE)
  8529. {
  8530. int m = 0;
  8531. memset(fname, 0, ARRAY_SIZE(fname));
  8532. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8533. if((access(fname,F_OK))!=-1)
  8534. {
  8535. strcpy(chargingProfiles[m], fname);
  8536. m = m + 1;
  8537. }
  8538. memset(fname, 0, ARRAY_SIZE(fname));
  8539. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8540. if((access(fname,F_OK))!=-1)
  8541. {
  8542. strcpy(chargingProfiles[m], fname);
  8543. m = m + 1;
  8544. }
  8545. ChargeProfileCount = m;
  8546. }
  8547. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8548. {
  8549. //strcpy(fname, TxDefaultProfile_1_JSON);
  8550. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8551. if((access(fname,F_OK))!=-1)
  8552. {
  8553. strcpy(chargingProfiles[0], fname);
  8554. ChargeProfileCount = 1;
  8555. }
  8556. }
  8557. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8558. {
  8559. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8560. if((access(fname,F_OK))!=-1)
  8561. {
  8562. strcpy(chargingProfiles[0], fname);
  8563. ChargeProfileCount = 1;
  8564. }
  8565. //strcpy(fname, TxProfile_1_JSON);
  8566. }
  8567. //strcpy(fname, ChargePointMaxProfile_JSON );
  8568. break;
  8569. }
  8570. }
  8571. else // Check all Charging Profiles
  8572. {
  8573. int i = 0;
  8574. char fnametemp[200]={0};
  8575. ChargeProfileCount = 0;
  8576. //Check ChargePointMaxProfile.json exit
  8577. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8578. {
  8579. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  8580. i = i + 1;
  8581. }
  8582. //Check TxDefaultProfile_0.json exit
  8583. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8584. {
  8585. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  8586. i = i + 1;
  8587. }
  8588. //Check TxDefaultProfile_%d.json
  8589. for(int j=1; j <= gunTotalNumber; j++)
  8590. {
  8591. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8592. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8593. if((access(fnametemp,F_OK))!=-1)
  8594. {
  8595. strcpy(chargingProfiles[i], fnametemp);
  8596. i = i + 1;
  8597. }
  8598. }
  8599. //Check TxProfile_%d.json
  8600. for(int j=1; j <= gunTotalNumber; j++)
  8601. {
  8602. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8603. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8604. if((access(fnametemp,F_OK))!=-1)
  8605. {
  8606. strcpy(chargingProfiles[i], fnametemp);
  8607. i = i + 1;
  8608. }
  8609. }
  8610. ChargeProfileCount = i;
  8611. }// End connectorIsNULL is TRUE
  8612. if(ChargeProfileCount == 0)
  8613. {
  8614. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8615. goto end;
  8616. }
  8617. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8618. {
  8619. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8620. goto end;
  8621. }
  8622. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8623. {
  8624. memset(str, 0, ARRAY_SIZE(str));
  8625. // clear temp file
  8626. sprintf(str,"rm -f %s",temp);
  8627. system(str);
  8628. for(int k=0; k < ChargeProfileCount; k++)
  8629. {
  8630. memset(str, 0, ARRAY_SIZE(str));
  8631. //clear file in C
  8632. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8633. system(str);
  8634. }
  8635. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8636. goto end;
  8637. }
  8638. else if(connectorIsNULL == TRUE)
  8639. {
  8640. for(int k=0; k < ChargeProfileCount; k++)
  8641. {
  8642. fptr1 = fopen(chargingProfiles[k], "r");
  8643. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  8644. //Check Charging Profile Count
  8645. while(fscanf(fptr1, "%s", word) != EOF)
  8646. {
  8647. //DEBUG_INFO("word=%s\n",word);
  8648. if(strstr(word, "chargingProfileId")!= NULL)
  8649. {
  8650. //DEBUG_INFO("test chargingProfileId \n");
  8651. n_chargingProfile = n_chargingProfile + 1;
  8652. //DEBUG_INFO("chargingProfileId Found\n");
  8653. }
  8654. }
  8655. rewind(fptr1);
  8656. //search Charging Profile Element
  8657. //int i= 0;
  8658. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8659. {
  8660. json_object *tmpProfilee;
  8661. tmpProfilee = json_tokener_parse(sLineWord);
  8662. if(!is_error(tmpProfilee))
  8663. {
  8664. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8665. {
  8666. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8667. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8668. }
  8669. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8670. {
  8671. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8672. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8673. }
  8674. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8675. {
  8676. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8677. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8678. }
  8679. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8680. {
  8681. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8682. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8683. }
  8684. }
  8685. json_object_put(tmpProfilee);
  8686. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8687. {
  8688. //------- not write to fptr2-------//
  8689. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8690. //clearflag = TRUE;
  8691. }
  8692. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8693. {
  8694. //------- not write to fptr2-------//
  8695. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8696. }
  8697. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8698. {
  8699. //------- not write to fptr2-------//
  8700. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8701. }
  8702. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8703. {
  8704. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8705. }
  8706. else
  8707. {
  8708. fprintf(fptr2, sLineWord);//writing data into file
  8709. }
  8710. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8711. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8712. if(clearflag == TRUE)
  8713. {
  8714. fclose(fptr1);
  8715. fclose(fptr2);
  8716. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8717. system(str);
  8718. // clear temp file
  8719. sprintf(str,"rm -f %s",temp);
  8720. system(str);
  8721. }
  8722. else
  8723. {
  8724. fclose(fptr1);
  8725. fclose(fptr2);
  8726. memset(str, 0, ARRAY_SIZE(str));
  8727. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8728. system(str);
  8729. resultRename = rename(temp, chargingProfiles[k]);
  8730. if(resultRename == 0)
  8731. {
  8732. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8733. }
  8734. else
  8735. {
  8736. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8737. }
  8738. if(comfirmstr[0]== 0)
  8739. {
  8740. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8741. }
  8742. //Check chargingProfile is empty file
  8743. /*------ Read the file ----------------*/
  8744. fptr1=fopen(chargingProfiles[k],"r");
  8745. ch=fgetc(fptr1);
  8746. rewind(fptr1);
  8747. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8748. if(ch!=EOF)
  8749. {
  8750. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8751. {
  8752. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8753. if(sLineWord[0]=='\0')
  8754. {
  8755. isEmptyFile = TRUE;
  8756. break;
  8757. }
  8758. else
  8759. {
  8760. isEmptyFile = FALSE;
  8761. break;
  8762. }
  8763. }
  8764. }
  8765. else
  8766. isEmptyFile = TRUE;
  8767. fclose(fptr1);
  8768. if(isEmptyFile == TRUE)
  8769. {
  8770. memset(str, 0, ARRAY_SIZE(str));
  8771. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8772. system(str);
  8773. }
  8774. }
  8775. }// End of while(int k=0; k < ChargePointCount; k++)
  8776. }
  8777. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8778. {
  8779. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8780. for(int k=0; k < ChargeProfileCount; k++)
  8781. {
  8782. fptr1 = fopen(chargingProfiles[k], "r");
  8783. fptr2 = fopen(temp, "w+");
  8784. //Check Charging Profile Count
  8785. while(fscanf(fptr1, "%s", word) != EOF)
  8786. {
  8787. //DEBUG_INFO("word=%s\n",word);
  8788. if(strstr(word, "chargingProfileId")!= NULL)
  8789. {
  8790. n_chargingProfile = n_chargingProfile + 1;
  8791. }
  8792. }
  8793. rewind(fptr1);
  8794. //search Charging Profile Element
  8795. //int i= 0;
  8796. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8797. {
  8798. json_object *tmpProfilee;
  8799. tmpProfilee = json_tokener_parse(sLineWord);
  8800. if(!is_error(tmpProfilee))
  8801. {
  8802. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8803. {
  8804. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8805. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8806. }
  8807. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8808. {
  8809. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8810. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8811. }
  8812. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8813. {
  8814. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8815. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8816. }
  8817. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8818. {
  8819. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8820. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8821. }
  8822. }
  8823. json_object_put(tmpProfilee);
  8824. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8825. {
  8826. //------- not write to fptr2-------//
  8827. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8828. //clearflag = TRUE;
  8829. }
  8830. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8831. {
  8832. //------- not write to fptr2-------//
  8833. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8834. }
  8835. else if(stackLevelIsNULL == TRUE)
  8836. {
  8837. //Clear Whole File
  8838. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8839. clearflag = TRUE;
  8840. break;
  8841. }
  8842. else
  8843. {
  8844. fprintf(fptr2, sLineWord);//writing data into file
  8845. }
  8846. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8847. }
  8848. if(clearflag == TRUE)
  8849. {
  8850. fclose(fptr1);
  8851. fclose(fptr2);
  8852. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8853. system(str);
  8854. // clear temp file
  8855. sprintf(str,"rm -f %s",temp);
  8856. system(str);
  8857. }
  8858. else
  8859. {
  8860. fclose(fptr1);
  8861. fclose(fptr2);
  8862. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8863. system(str);
  8864. resultRename = rename(temp, chargingProfiles[k]);
  8865. if(resultRename == 0)
  8866. {
  8867. DEBUG_INFO("File ChargingProfile renamed successfully");
  8868. }
  8869. else
  8870. {
  8871. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8872. }
  8873. if(comfirmstr[0]== 0)
  8874. {
  8875. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8876. }
  8877. //Check chargingProfile is empty file
  8878. /*------ Read the file ----------------*/
  8879. fptr1=fopen(chargingProfiles[k],"r");
  8880. ch=fgetc(fptr1);
  8881. rewind(fptr1);
  8882. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8883. if(ch!=EOF)
  8884. {
  8885. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8886. {
  8887. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8888. if(sLineWord[0]=='\0')
  8889. {
  8890. isEmptyFile = TRUE;
  8891. break;
  8892. }
  8893. else
  8894. {
  8895. isEmptyFile = FALSE;
  8896. break;
  8897. }
  8898. }
  8899. }
  8900. else
  8901. isEmptyFile = TRUE;
  8902. fclose(fptr1);
  8903. if(isEmptyFile == TRUE)
  8904. {
  8905. memset(str, 0, ARRAY_SIZE(str));
  8906. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8907. system(str);
  8908. }
  8909. /*------- End of reading ---------------*/
  8910. }
  8911. } // while(int k=0; k < ChargeProfileCount; k++)
  8912. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8913. end:
  8914. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8915. {
  8916. if(connectorIdInt == 0)
  8917. {
  8918. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8919. {
  8920. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  8921. }
  8922. }
  8923. else
  8924. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  8925. }
  8926. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8927. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8928. return result;
  8929. }
  8930. void createFirmwareVersionByDataTransfer(void)
  8931. {
  8932. json_object *FirmwareDataTransfer = json_object_new_object();
  8933. // AC & DC model
  8934. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8935. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8936. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8937. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8938. // DC model
  8939. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8940. {
  8941. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8942. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8943. (gunType[3] != GUN_TYPE_UNKNOWN))
  8944. {
  8945. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8946. }
  8947. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8948. {
  8949. // DS DM DW
  8950. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8951. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8952. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8953. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8954. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8955. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8956. }
  8957. else
  8958. {
  8959. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8960. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8961. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8962. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8963. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8964. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8965. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8966. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8967. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8968. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8969. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8970. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8971. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8972. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8973. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8974. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8975. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8976. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8977. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8978. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8979. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8980. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8981. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8982. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8983. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8984. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8985. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8986. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8987. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8988. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8989. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8990. }
  8991. }
  8992. // 4G model
  8993. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8994. {
  8995. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8996. }
  8997. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8998. json_object_put(FirmwareDataTransfer);
  8999. }
  9000. int handleDataTransferRequest(char *uuid, char *payload)
  9001. {
  9002. mtrace();
  9003. json_object *response = json_object_new_object();
  9004. int result = FAIL;
  9005. char tempvendorId[255]={0};
  9006. char tempmessageId[50]={0};
  9007. char tempdata[512]={0};
  9008. char message[2048]={0};
  9009. DEBUG_INFO("handleDataTransferRequest...\n");
  9010. if((uuid != NULL) && (payload != NULL))
  9011. {
  9012. json_object *DataTransfer;
  9013. DataTransfer = json_tokener_parse(payload);
  9014. if(!is_error(DataTransfer))
  9015. {
  9016. // Required data
  9017. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9018. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9019. // Optional data
  9020. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9021. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9022. if(json_object_object_get(DataTransfer, "data") != NULL)
  9023. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9024. result = PASS;
  9025. }
  9026. json_object_put(DataTransfer);
  9027. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9028. {
  9029. // Send all moudle firmware version on EVSE
  9030. createFirmwareVersionByDataTransfer();
  9031. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9032. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9033. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9034. json_object_put(response);
  9035. }
  9036. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9037. {
  9038. system("/usr/bin/run_tmate_restart.sh &");
  9039. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9040. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9041. json_object_put(response);
  9042. }
  9043. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9044. {
  9045. json_object *data;
  9046. data = json_tokener_parse(tempdata);
  9047. if(!is_error(data))
  9048. {
  9049. 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))
  9050. {
  9051. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9052. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9053. if(json_object_object_get(data, "SOC") != NULL)
  9054. {
  9055. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9056. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9057. }
  9058. if(json_object_object_get(data, "Energy") != NULL)
  9059. {
  9060. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9061. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9062. }
  9063. if(json_object_object_get(data, "Duration") != NULL)
  9064. {
  9065. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9066. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9067. }
  9068. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9069. }
  9070. else
  9071. {
  9072. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9073. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9074. }
  9075. }
  9076. else
  9077. {
  9078. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9079. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9080. }
  9081. json_object_put(data);
  9082. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9083. json_object_put(response);
  9084. }
  9085. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9086. {
  9087. json_object *data;
  9088. data = json_tokener_parse(tempdata);
  9089. if(!is_error(data))
  9090. {
  9091. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9092. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9093. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9094. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9095. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9096. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9097. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9098. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9099. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9100. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9101. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9102. }
  9103. else
  9104. {
  9105. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9106. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9107. }
  9108. json_object_put(data);
  9109. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9110. json_object_put(response);
  9111. }
  9112. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9113. {
  9114. json_object *data;
  9115. data = json_tokener_parse(tempdata);
  9116. if(!is_error(data))
  9117. {
  9118. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9119. if(json_object_object_get(data, "idToken") != NULL)
  9120. {
  9121. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9122. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9123. }
  9124. if(json_object_object_get(data, "price") != NULL)
  9125. {
  9126. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9127. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9128. }
  9129. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9130. }
  9131. else
  9132. {
  9133. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9134. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9135. }
  9136. json_object_put(data);
  9137. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9138. json_object_put(response);
  9139. }
  9140. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9141. {
  9142. json_object *data;
  9143. data = json_tokener_parse(tempdata);
  9144. if(!is_error(data))
  9145. {
  9146. if(json_object_object_get(data, "txId") != NULL)
  9147. {
  9148. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9149. for(int idx = 0;idx<gunTotalNumber;idx++)
  9150. {
  9151. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9152. {
  9153. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9154. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9155. if(json_object_object_get(data, "description") != NULL)
  9156. {
  9157. // California pricing V1.0
  9158. DEBUG_INFO("California pricing V1.0\n");
  9159. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9160. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9161. }
  9162. else
  9163. {
  9164. // California pricing V1.1
  9165. DEBUG_INFO("California pricing V1.1\n");
  9166. if(json_object_object_get(data, "timestamp") != NULL)
  9167. {
  9168. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9169. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9170. }
  9171. if(json_object_object_get(data, "meterValue") != NULL)
  9172. {
  9173. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9174. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9175. }
  9176. if(json_object_object_get(data, "cost") != NULL)
  9177. {
  9178. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9179. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9180. }
  9181. if(json_object_object_get(data, "state") != NULL)
  9182. {
  9183. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9184. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9185. }
  9186. if(json_object_object_get(data, "chargingPrice") != NULL)
  9187. {
  9188. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9189. {
  9190. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9191. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9192. }
  9193. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9194. {
  9195. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9196. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9197. }
  9198. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9199. {
  9200. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9201. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9202. }
  9203. }
  9204. if(json_object_object_get(data, "idlePrice") != NULL)
  9205. {
  9206. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9207. {
  9208. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9209. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9210. }
  9211. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9212. {
  9213. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9214. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9215. }
  9216. }
  9217. if(json_object_object_get(data, "nextPeriod") != NULL)
  9218. {
  9219. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9220. {
  9221. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9222. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9223. }
  9224. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9225. {
  9226. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9227. {
  9228. 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")));
  9229. 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"));
  9230. }
  9231. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9232. {
  9233. 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")));
  9234. 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"));
  9235. }
  9236. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9237. {
  9238. 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")));
  9239. 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"));
  9240. }
  9241. }
  9242. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9243. {
  9244. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9245. {
  9246. 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")));
  9247. 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"));
  9248. }
  9249. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9250. {
  9251. 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")));
  9252. 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"));
  9253. }
  9254. }
  9255. }
  9256. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9257. {
  9258. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9259. {
  9260. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9261. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9262. }
  9263. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9264. {
  9265. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9266. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9267. }
  9268. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9269. {
  9270. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9271. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9272. }
  9273. }
  9274. }
  9275. }
  9276. }
  9277. }
  9278. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9279. }
  9280. else
  9281. {
  9282. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9283. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9284. }
  9285. json_object_put(data);
  9286. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9287. json_object_put(response);
  9288. }
  9289. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9290. {
  9291. json_object *data;
  9292. data = json_tokener_parse(tempdata);
  9293. if(!is_error(data))
  9294. {
  9295. if(json_object_object_get(data, "txId") != NULL)
  9296. {
  9297. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9298. for(int idx = 0;idx<gunTotalNumber;idx++)
  9299. {
  9300. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9301. {
  9302. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9303. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9304. if(json_object_object_get(data, "description") != NULL)
  9305. {
  9306. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9307. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9308. }
  9309. }
  9310. }
  9311. }
  9312. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9313. }
  9314. else
  9315. {
  9316. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9317. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9318. }
  9319. json_object_put(data);
  9320. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9321. json_object_put(response);
  9322. }
  9323. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9324. {
  9325. json_object *data;
  9326. data = json_tokener_parse(tempdata);
  9327. if(!is_error(data))
  9328. {
  9329. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9330. if(json_object_object_get(data, "Content_Type") != NULL)
  9331. {
  9332. 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))
  9333. {
  9334. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9335. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9336. {
  9337. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9338. }
  9339. }
  9340. else
  9341. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9342. }
  9343. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9344. }
  9345. else
  9346. {
  9347. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9348. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9349. }
  9350. json_object_put(data);
  9351. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9352. json_object_put(response);
  9353. }
  9354. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  9355. {
  9356. json_object *data;
  9357. data = json_tokener_parse(tempdata);
  9358. if(!is_error(data))
  9359. {
  9360. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9361. if(json_object_object_get(data, "Page_Index") != NULL)
  9362. {
  9363. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9364. }
  9365. if(json_object_object_get(data, "Duration") != NULL)
  9366. {
  9367. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9368. }
  9369. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  9370. }
  9371. else
  9372. {
  9373. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9374. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9375. }
  9376. json_object_put(data);
  9377. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9378. json_object_put(response);
  9379. }
  9380. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9381. {
  9382. json_object *data;
  9383. data = json_tokener_parse(tempdata);
  9384. if(!is_error(data))
  9385. {
  9386. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9387. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9388. {
  9389. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9390. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9391. else
  9392. {
  9393. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9394. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9395. }
  9396. }
  9397. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9398. {
  9399. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9400. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9401. else
  9402. {
  9403. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9404. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9405. }
  9406. }
  9407. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9408. {
  9409. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9410. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9411. else
  9412. {
  9413. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9414. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9415. }
  9416. }
  9417. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9418. {
  9419. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9420. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9421. else
  9422. {
  9423. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9424. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9425. }
  9426. }
  9427. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9428. {
  9429. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9430. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9431. else
  9432. {
  9433. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9434. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9435. }
  9436. }
  9437. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9438. {
  9439. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9440. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9441. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9442. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9443. else
  9444. {
  9445. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9446. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9447. }
  9448. }
  9449. if(json_object_object_get(data, "isAuthentication") != NULL)
  9450. {
  9451. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9452. {
  9453. case 0:
  9454. case 1:
  9455. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9456. break;
  9457. default:
  9458. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9459. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9460. break;
  9461. }
  9462. }
  9463. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9464. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9465. }
  9466. else
  9467. {
  9468. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9469. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9470. }
  9471. json_object_put(data);
  9472. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9473. json_object_put(response);
  9474. }
  9475. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  9476. {
  9477. json_object *data;
  9478. data = json_tokener_parse(tempdata);
  9479. if(!is_error(data))
  9480. {
  9481. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9482. {
  9483. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  9484. {
  9485. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9486. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9487. }
  9488. else
  9489. {
  9490. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9491. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  9492. }
  9493. }
  9494. else
  9495. {
  9496. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9497. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9498. }
  9499. }
  9500. else
  9501. {
  9502. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9503. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9504. }
  9505. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9506. json_object_put(response);
  9507. }
  9508. else
  9509. {
  9510. // Can not find valid message id
  9511. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9512. }
  9513. }
  9514. else
  9515. {
  9516. // Payload is null
  9517. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9518. }
  9519. LWS_Send(message);
  9520. return result;
  9521. }
  9522. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9523. {
  9524. mtrace();
  9525. int result = FAIL;
  9526. int connectorIdInt, durationInt;
  9527. char chargingRateUnitStr[4]={0};
  9528. char comfirmstr[20];
  9529. int confirmPeriods = 0;
  9530. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9531. json_object *GetCompositeSchedule;
  9532. GetCompositeSchedule = json_tokener_parse(payload);
  9533. if(!is_error(GetCompositeSchedule))
  9534. {
  9535. // Required data
  9536. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9537. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9538. else
  9539. connectorIdInt = -1;
  9540. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9541. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9542. else
  9543. durationInt = 86400;
  9544. // Optional data
  9545. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9546. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9547. }
  9548. json_object_put(GetCompositeSchedule);
  9549. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9550. if((connectorIdInt == 0) ||
  9551. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9552. {
  9553. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9554. struct StructChargingProfile tmpProfile[1];
  9555. if(strstr(chargingRateUnitStr, "W") != NULL)
  9556. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9557. else
  9558. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9559. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9560. {
  9561. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9562. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9563. }
  9564. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9565. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9566. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9567. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9568. {
  9569. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9570. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9571. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9572. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9573. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9574. {
  9575. confirmPeriods = idx;
  9576. break;
  9577. }
  9578. }
  9579. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9580. {
  9581. confirmPeriods += 1;
  9582. }
  9583. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9584. }
  9585. else
  9586. {
  9587. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9588. }
  9589. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9590. return result;
  9591. }
  9592. int handleGetConfigurationRequest(char *uuid, char *payload)
  9593. {
  9594. mtrace();
  9595. int result = FAIL;
  9596. int MaxKeySupported = 0;
  9597. int n_keys = 0;
  9598. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9599. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9600. json_object *GetConfiguration;
  9601. GetConfiguration = json_tokener_parse(payload);
  9602. if(!is_error(GetConfiguration))
  9603. {
  9604. // Optional data
  9605. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9606. {
  9607. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9608. {
  9609. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9610. n_keys = idx + 1;
  9611. }
  9612. }
  9613. }
  9614. json_object_put(GetConfiguration);
  9615. UnknownKeynum = 0;
  9616. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9617. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9618. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9619. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9620. if(n_keys != 0)
  9621. {
  9622. for(int i=0;i<n_keys;i++)
  9623. {
  9624. getKeyValue(requestKey[i]);
  9625. }
  9626. }
  9627. else
  9628. {
  9629. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9630. getKeyValue("");
  9631. }
  9632. processUnkownKey();
  9633. sendGetConfigurationConfirmation(uuid);
  9634. return result;
  9635. }
  9636. static char fnamePlusPath[100]={0};
  9637. static char fnamePWithNoPath[60]={0};
  9638. void checkUploadLog(void)
  9639. {
  9640. FILE *fp;
  9641. /* Open the command for reading. */
  9642. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9643. if (fp == NULL) {
  9644. DEBUG_WARN("Failed to run command\n" );
  9645. exit(1);
  9646. }
  9647. int ftppathlen = 0;
  9648. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9649. int i = 0;
  9650. /* Read the output a line at a time - output it. */
  9651. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9652. if(i==0)
  9653. {
  9654. ftppathlen = strlen(fnamePlusPath);
  9655. DEBUG_INFO("%s\n", fnamePlusPath);
  9656. fnamePlusPath[ftppathlen]='\0';
  9657. break;
  9658. }
  9659. i= i+1;
  9660. }
  9661. /* close */
  9662. pclose(fp);
  9663. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9664. {
  9665. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9666. {
  9667. fnamePlusPath[k]='\0';
  9668. }
  9669. }
  9670. i=1;
  9671. //char fname[60]={0};
  9672. while(i < ftppathlen)
  9673. {
  9674. int len=ftppathlen-i;
  9675. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9676. {
  9677. DEBUG_INFO("compare '/' all right\n");
  9678. break;
  9679. }
  9680. i=i+1;
  9681. }
  9682. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9683. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9684. fnamePWithNoPath[i+1] = '\0';
  9685. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9686. {
  9687. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9688. {
  9689. fnamePWithNoPath[j]='\0';
  9690. }
  9691. }
  9692. FILE* fp1 = fopen(fnamePlusPath, "r");
  9693. if (fp1)
  9694. {
  9695. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9696. // file exists
  9697. fclose(fp1);
  9698. }
  9699. else
  9700. {
  9701. // file doesn't exist
  9702. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9703. }
  9704. }
  9705. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9706. {
  9707. mtrace();
  9708. int result = FAIL;
  9709. time_t CurrentTime;
  9710. struct tm *tm;
  9711. pthread_t th_Status;
  9712. CurrentTime = time(NULL);
  9713. tm = localtime(&CurrentTime);
  9714. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  9715. 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);
  9716. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9717. if(!interLock.isGetDiagnosticGoing)
  9718. {
  9719. interLock.isGetDiagnosticGoing = 1;
  9720. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9721. sleep(1);
  9722. }
  9723. else
  9724. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9725. return result;
  9726. }
  9727. void* GetDiagnosticsProcess(void* data)
  9728. {
  9729. pthread_detach(pthread_self());
  9730. mtrace();
  9731. int retriesInt=0, retryIntervalInt=0;
  9732. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9733. 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};
  9734. int port=0;
  9735. int isSuccess = FALSE;
  9736. char cmdBuf[2048];
  9737. struct tm *tmNow;
  9738. time_t CurrentTime;
  9739. struct tm tmStart;
  9740. struct tm tmStop;
  9741. CurrentTime = time(NULL);
  9742. tmNow=localtime(&CurrentTime);
  9743. uint16_t targetYear, targetMonth;
  9744. json_object *GetDiagnostics;
  9745. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9746. GetDiagnostics = json_tokener_parse(data);
  9747. if(!is_error(GetDiagnostics))
  9748. {
  9749. // Required data
  9750. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9751. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9752. // Optional data
  9753. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9754. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9755. else
  9756. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9757. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9758. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9759. else
  9760. retryIntervalInt = 30;
  9761. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9762. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9763. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9764. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9765. }
  9766. json_object_put(GetDiagnostics);
  9767. // Pack log to compress file
  9768. 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) &&
  9769. (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))
  9770. {
  9771. // Pack system log
  9772. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9773. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9774. targetYear = tmStart.tm_year;
  9775. targetMonth = tmStart.tm_mon;
  9776. do
  9777. {
  9778. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9779. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9780. if(targetMonth+1>=13)
  9781. {
  9782. targetYear += 1;
  9783. targetMonth = 1;
  9784. }
  9785. else
  9786. {
  9787. targetMonth += 1;
  9788. }
  9789. }while((targetYear < (tmNow->tm_year+1900)) ||
  9790. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9791. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9792. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9793. system(cmdBuf);
  9794. // Pack charging & event log
  9795. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9796. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9797. targetYear = tmStart.tm_year;
  9798. targetMonth = tmStart.tm_mon;
  9799. do
  9800. {
  9801. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9802. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9803. if(targetMonth+1>=13)
  9804. {
  9805. targetYear += 1;
  9806. targetMonth = 1;
  9807. }
  9808. else
  9809. {
  9810. targetMonth += 1;
  9811. }
  9812. }while((targetYear < (tmNow->tm_year+1900)) ||
  9813. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9814. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9815. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9816. system(cmdBuf);
  9817. // Combine log file
  9818. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9819. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9820. }
  9821. else
  9822. {
  9823. system("exec /root/logPackTools 'log' 6");
  9824. }
  9825. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9826. system(cmdBuf);
  9827. checkUploadLog();
  9828. //****************location*******************/
  9829. if(strcmp(locationstr,"")==0)
  9830. {
  9831. DEBUG_INFO("location is <Empty>!\n");
  9832. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9833. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9834. goto end;
  9835. }
  9836. memset(protocol, 0, ARRAY_SIZE(protocol));
  9837. memset(user, 0, ARRAY_SIZE(user) );
  9838. memset(password, 0, ARRAY_SIZE(password));
  9839. memset(host, 0, ARRAY_SIZE(host));
  9840. memset(path, 0, ARRAY_SIZE(path));
  9841. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9842. memset(host1, 0, ARRAY_SIZE(host1));
  9843. memset(path1, 0, ARRAY_SIZE(path1));
  9844. /*location: ftp://user:password@host:port/path*/
  9845. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9846. if((access(fnamePlusPath,F_OK))!=-1)
  9847. {
  9848. DEBUG_INFO("fnamePlusPath exist.\n");
  9849. }
  9850. else
  9851. {
  9852. DEBUG_INFO("fnamePlusPath not exist!\n");
  9853. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9854. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9855. goto end;
  9856. }
  9857. if(strchr(locationstr,'@')==NULL)
  9858. {
  9859. sscanf(locationstr,
  9860. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9861. protocol, host, &port, path);
  9862. strcpy(user,"anonymous");
  9863. strcpy(password,"");
  9864. }
  9865. else
  9866. {
  9867. //DEBUG_INFO("pch=%s\n", pch);
  9868. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9869. protocol, user, password, host, &port, path);
  9870. }
  9871. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9872. {
  9873. DEBUG_INFO("protocol is not ftp/http ! \n");
  9874. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9875. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9876. goto end;
  9877. }
  9878. if(strncmp(locationstr,"http", 4) == 0)
  9879. {
  9880. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9881. sprintf(ftppath,"/%s", path);
  9882. do
  9883. {
  9884. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9885. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9886. sleep(3);
  9887. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9888. if(!isSuccess)
  9889. {
  9890. DEBUG_INFO("Diagnostics fail.\n");
  9891. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9892. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9893. sleep(retryIntervalInt);
  9894. }
  9895. else
  9896. {
  9897. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9898. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9899. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9900. }
  9901. retriesInt--;
  9902. }while((isSuccess == 0)&&(retriesInt >= 0));
  9903. }
  9904. else
  9905. {
  9906. sscanf(host,"%[^/]%s",host1, path1);
  9907. if(strlen(path) > 0)
  9908. sprintf(ftppath,"/%s", path);
  9909. else
  9910. sprintf(ftppath,"/%s", path1);
  9911. int ftppathlen=strlen(ftppath);
  9912. int i=1;
  9913. char filenametemp[50];
  9914. while(i < ftppathlen)
  9915. {
  9916. int len=ftppathlen-i;
  9917. if(ftppath[len]== 47) // '/' ascll code: 47
  9918. {
  9919. DEBUG_INFO("find '/' all right\n");
  9920. break;
  9921. }
  9922. i=i+1;
  9923. }
  9924. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9925. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9926. filenametemp[i+1] = 0;
  9927. if(port == 0)
  9928. port = 21;
  9929. do
  9930. {
  9931. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9932. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9933. sleep(3);
  9934. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9935. if(!isSuccess)
  9936. {
  9937. DEBUG_INFO("Diagnostics fail.\n");
  9938. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9939. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9940. sleep(retryIntervalInt);
  9941. }
  9942. else
  9943. {
  9944. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9945. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9946. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9947. }
  9948. retriesInt--;
  9949. }while((!isSuccess)&&(retriesInt >= 0));
  9950. }
  9951. end:
  9952. system("rm -f /mnt/*");
  9953. sleep(5);
  9954. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9955. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9956. interLock.isGetDiagnosticGoing = 0;
  9957. pthread_exit(NULL);
  9958. }
  9959. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9960. {
  9961. mtrace();
  9962. int result = FAIL;
  9963. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9964. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9965. {
  9966. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9967. locallistVersion = -1;
  9968. }
  9969. else
  9970. {
  9971. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9972. OCPP_getListVerion();
  9973. }
  9974. //from db.OCPP_getListVerion
  9975. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9976. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  9977. sendGetLocalListVersionConfirmation(uuid,"");
  9978. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  9979. return result;
  9980. }
  9981. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  9982. {
  9983. mtrace();
  9984. int result = FAIL;
  9985. int connectorIdInt=-1;
  9986. int tempIndex = 0;
  9987. int connectorIdIsNULL, chargingProfileIsNULL;
  9988. char comfirmstr[20]={0};
  9989. char cmdBuf[512];
  9990. json_object *RemoteStartTransaction;
  9991. FILE *fp;
  9992. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9993. if(server_pending == TRUE)
  9994. {
  9995. return 0;
  9996. }
  9997. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9998. RemoteStartTransaction = json_tokener_parse(payload);
  9999. if(!is_error(RemoteStartTransaction))
  10000. {
  10001. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10002. {
  10003. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10004. }
  10005. else
  10006. {
  10007. connectorIdIsNULL = TRUE;
  10008. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10009. {
  10010. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10011. {
  10012. connectorIdIsNULL = FALSE;
  10013. connectorIdInt = (gun_index+1);
  10014. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10015. break;
  10016. }
  10017. }
  10018. }
  10019. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10020. {
  10021. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10022. // Required data
  10023. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10024. // Optional data
  10025. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10026. {
  10027. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10028. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10029. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10030. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10031. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10032. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10033. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10034. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10035. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10036. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10037. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10038. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10039. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10040. {
  10041. 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")));
  10042. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10043. 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"));
  10044. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10045. 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"));
  10046. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10047. 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")));
  10048. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10049. {
  10050. 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++)
  10051. {
  10052. 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"));
  10053. 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"));
  10054. 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)
  10055. 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"));
  10056. }
  10057. }
  10058. }
  10059. }
  10060. else
  10061. {
  10062. chargingProfileIsNULL = TRUE;
  10063. }
  10064. }
  10065. }
  10066. else
  10067. {
  10068. connectorIdIsNULL = TRUE;
  10069. }
  10070. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10071. {
  10072. DEBUG_WARN("Connector id is NULL\n.");
  10073. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10074. goto end;
  10075. }
  10076. /*
  10077. enum _SYSTEM_STATUS
  10078. {
  10079. S_BOOTING = 0,
  10080. S_IDLE, = 1
  10081. S_AUTHORIZING, = 2
  10082. S_REASSIGN_CHECK, = 3
  10083. S_REASSIGN, = 4
  10084. S_PRECHARGE, = 5
  10085. S_PREPARING_FOR_EV, = 6
  10086. S_PREPARING_FOR_EVSE, = 7
  10087. S_CHARGING, = 8
  10088. S_TERMINATING, = 9
  10089. S_COMPLETE, = 10
  10090. S_ALARM, = 11
  10091. S_FAULT = 12
  10092. }
  10093. */
  10094. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10095. {
  10096. //check Transaction active
  10097. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10098. {
  10099. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10100. {
  10101. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10102. }
  10103. else
  10104. {
  10105. tempIndex = connectorIdInt -1;
  10106. }
  10107. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10108. {
  10109. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10110. {
  10111. 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))
  10112. {
  10113. //Reserved
  10114. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10115. }
  10116. 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))
  10117. {
  10118. //Reserved
  10119. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10120. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10121. goto end;
  10122. }
  10123. else
  10124. {
  10125. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10126. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10127. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10128. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10129. {
  10130. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10131. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10132. goto end;
  10133. }
  10134. }//END FOR ELSE
  10135. }
  10136. }// END FOR CHAdeMO_QUANTITY
  10137. }
  10138. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10139. {
  10140. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10141. {
  10142. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10143. }
  10144. else
  10145. {
  10146. tempIndex = connectorIdInt -1;
  10147. }
  10148. for (int index = 0; index < CCS_QUANTITY; index++)
  10149. {
  10150. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10151. {
  10152. 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))
  10153. {
  10154. //Reserved
  10155. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10156. }
  10157. 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))
  10158. {
  10159. //Reserved
  10160. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10161. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10162. goto end;
  10163. }
  10164. else
  10165. {
  10166. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10167. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10168. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10169. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10170. {
  10171. DEBUG_WARN("CCS connector not allow start\n.");
  10172. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10173. goto end;
  10174. }
  10175. }// END FOR ELSE
  10176. }
  10177. }// END FOR CCS_QUANTITY
  10178. }
  10179. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10180. {
  10181. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10182. {
  10183. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10184. }
  10185. else
  10186. {
  10187. tempIndex = connectorIdInt -1;
  10188. }
  10189. for (int index = 0; index < GB_QUANTITY; index++)
  10190. {
  10191. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10192. {
  10193. 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))
  10194. {
  10195. //Reserved
  10196. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10197. }
  10198. 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))
  10199. {
  10200. //Reserved
  10201. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10202. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10203. goto end;
  10204. }
  10205. else
  10206. {
  10207. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10208. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10209. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10210. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10211. {
  10212. DEBUG_WARN("GB connector not allow start\n.");
  10213. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10214. goto end;
  10215. }
  10216. }// END FOR ELSE
  10217. }
  10218. } // END FOR GB_QUANTITY
  10219. }
  10220. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10221. {
  10222. tempIndex = connectorIdInt -1;
  10223. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10224. {
  10225. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10226. {
  10227. 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))
  10228. {
  10229. //Reserved
  10230. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10231. }
  10232. 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))
  10233. {
  10234. //Reserved
  10235. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10236. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10237. goto end;
  10238. }
  10239. else
  10240. {
  10241. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10242. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10243. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10244. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10245. {
  10246. DEBUG_WARN("GB connector not allow start\n.");
  10247. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10248. goto end;
  10249. }
  10250. }// END FOR ELSE
  10251. }
  10252. } // END FOR GB_QUANTITY
  10253. }
  10254. else
  10255. {
  10256. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10257. {
  10258. tempIndex = 2;
  10259. }
  10260. else
  10261. {
  10262. tempIndex = connectorIdInt -1;
  10263. }
  10264. for (int index = 0; index < AC_QUANTITY; index++)
  10265. {
  10266. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10267. {
  10268. 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))
  10269. {
  10270. //Reserved
  10271. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10272. }
  10273. 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))
  10274. {
  10275. //Reserved
  10276. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10277. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10278. goto end;
  10279. }
  10280. else
  10281. {
  10282. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10283. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10284. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10285. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10286. {
  10287. DEBUG_WARN("AC connector not allow start\n.");
  10288. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10289. goto end;
  10290. }
  10291. }//END FOR ELSE
  10292. }
  10293. }// END FOR AC_QUANTITY
  10294. }
  10295. if(chargingProfileIsNULL == FALSE)
  10296. {
  10297. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10298. {
  10299. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10300. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10301. //memset idTag
  10302. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10303. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10304. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10305. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10306. // Save profile to file
  10307. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10308. system(cmdBuf);
  10309. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10310. fp = fopen(cmdBuf, "w");
  10311. 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));
  10312. fclose(fp);
  10313. }
  10314. else
  10315. {
  10316. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10317. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10318. }
  10319. }
  10320. else
  10321. {
  10322. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10323. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10324. //memset idTag
  10325. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10326. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10327. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10328. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10329. }
  10330. }
  10331. else
  10332. {
  10333. DEBUG_WARN("Connector id over\n.");
  10334. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10335. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10336. }
  10337. end:
  10338. json_object_put(RemoteStartTransaction);
  10339. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10340. {
  10341. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10342. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10343. }
  10344. //OCPP send RemoteStartConfirmation by first.
  10345. sendRemoteStartConfirmation(uuid, comfirmstr);
  10346. return result;
  10347. }
  10348. int handleRemoteStartRequest(char *uuid, char *payload)
  10349. {
  10350. mtrace();
  10351. int result = PASS;
  10352. int connectorIdInt=-1;
  10353. int tempIndex = 0;
  10354. char comfirmstr[20]={0};
  10355. char cmdBuf[512];
  10356. json_object *RemoteStartTransaction;
  10357. FILE *fp;
  10358. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10359. if(server_pending == TRUE)
  10360. {
  10361. result = FAIL;
  10362. }
  10363. RemoteStartTransaction = json_tokener_parse(payload);
  10364. if(!is_error(RemoteStartTransaction))
  10365. {
  10366. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10367. {
  10368. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10369. }
  10370. else
  10371. {
  10372. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10373. {
  10374. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10375. {
  10376. connectorIdInt = (gun_index+1);
  10377. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10378. break;
  10379. }
  10380. }
  10381. }
  10382. if(connectorIdInt == 0)
  10383. {
  10384. DEBUG_WARN("Connector id shall not equal 0.\n");
  10385. result = FAIL;
  10386. }
  10387. else if(connectorIdInt == -1)
  10388. {
  10389. DEBUG_INFO("Connector id does not specific.\n");
  10390. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10391. {
  10392. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10393. // Required data
  10394. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10395. // Optional data
  10396. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10397. {
  10398. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10399. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10400. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10401. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10402. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10403. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10404. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10405. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10406. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10407. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10408. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10409. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10410. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10411. {
  10412. 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")));
  10413. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10414. 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"));
  10415. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10416. 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"));
  10417. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10418. 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")));
  10419. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10420. {
  10421. 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++)
  10422. {
  10423. 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"));
  10424. 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"));
  10425. 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)
  10426. 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"));
  10427. }
  10428. }
  10429. }
  10430. }
  10431. else
  10432. {
  10433. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10434. }
  10435. }
  10436. }
  10437. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10438. {
  10439. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10440. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10441. // Required data
  10442. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10443. // Optional data
  10444. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10445. {
  10446. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10447. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10448. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10449. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10450. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10451. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10452. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10453. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10454. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10455. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10456. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10457. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10458. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10459. {
  10460. 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")));
  10461. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10462. 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"));
  10463. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10464. 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"));
  10465. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10466. 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")));
  10467. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10468. {
  10469. 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++)
  10470. {
  10471. 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"));
  10472. 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"));
  10473. 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)
  10474. 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"));
  10475. }
  10476. }
  10477. }
  10478. }
  10479. else
  10480. {
  10481. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10482. }
  10483. }
  10484. else
  10485. {
  10486. DEBUG_WARN("Connector id is over maximun value.\n");
  10487. result = FAIL;
  10488. }
  10489. }
  10490. if(result == PASS)
  10491. {
  10492. if(connectorIdInt > 0)
  10493. {
  10494. //check Transaction active
  10495. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10496. {
  10497. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10498. {
  10499. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10500. }
  10501. else
  10502. {
  10503. tempIndex = connectorIdInt -1;
  10504. }
  10505. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10506. {
  10507. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10508. {
  10509. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10510. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10511. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10512. {
  10513. //Reserved
  10514. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10515. }
  10516. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10517. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10518. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10519. {
  10520. //Reserved
  10521. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10522. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10523. goto end;
  10524. }
  10525. else
  10526. {
  10527. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10528. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10529. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10530. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10531. {
  10532. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10533. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10534. goto end;
  10535. }
  10536. }//END FOR ELSE
  10537. }
  10538. }// END FOR CHAdeMO_QUANTITY
  10539. }
  10540. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10541. {
  10542. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10543. {
  10544. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10545. }
  10546. else
  10547. {
  10548. tempIndex = connectorIdInt -1;
  10549. }
  10550. for (int index = 0; index < CCS_QUANTITY; index++)
  10551. {
  10552. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10553. {
  10554. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10555. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10556. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10557. {
  10558. //Reserved
  10559. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10560. }
  10561. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10562. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10563. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10564. {
  10565. //Reserved
  10566. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10567. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10568. goto end;
  10569. }
  10570. else
  10571. {
  10572. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10573. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10574. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10575. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10576. {
  10577. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10578. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10579. goto end;
  10580. }
  10581. }// END FOR ELSE
  10582. }
  10583. }// END FOR CCS_QUANTITY
  10584. }
  10585. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10586. {
  10587. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10588. {
  10589. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10590. }
  10591. else
  10592. {
  10593. tempIndex = connectorIdInt -1;
  10594. }
  10595. for (int index = 0; index < GB_QUANTITY; index++)
  10596. {
  10597. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10598. {
  10599. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10600. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10601. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10602. {
  10603. //Reserved
  10604. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10605. }
  10606. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10607. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10608. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10609. {
  10610. //Reserved
  10611. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10612. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10613. goto end;
  10614. }
  10615. else
  10616. {
  10617. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10618. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10619. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10620. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10621. {
  10622. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10623. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10624. goto end;
  10625. }
  10626. }// END FOR ELSE
  10627. }
  10628. } // END FOR GB_QUANTITY
  10629. }
  10630. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10631. {
  10632. tempIndex = connectorIdInt -1;
  10633. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10634. {
  10635. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10636. {
  10637. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10638. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10639. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10640. {
  10641. //Reserved
  10642. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10643. }
  10644. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10645. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10646. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10647. {
  10648. //Reserved
  10649. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10650. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10651. goto end;
  10652. }
  10653. else
  10654. {
  10655. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10656. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10657. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10658. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10659. {
  10660. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10661. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10662. goto end;
  10663. }
  10664. }// END FOR ELSE
  10665. }
  10666. } // END FOR GB_QUANTITY
  10667. }
  10668. else
  10669. {
  10670. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10671. {
  10672. tempIndex = 2;
  10673. }
  10674. else
  10675. {
  10676. tempIndex = connectorIdInt -1;
  10677. }
  10678. for (int index = 0; index < AC_QUANTITY; index++)
  10679. {
  10680. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10681. {
  10682. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10683. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10684. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10685. {
  10686. //Reserved
  10687. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10688. }
  10689. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10690. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10691. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10692. {
  10693. //Reserved
  10694. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10695. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10696. goto end;
  10697. }
  10698. else
  10699. {
  10700. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10701. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10702. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10703. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10704. {
  10705. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10706. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10707. goto end;
  10708. }
  10709. }//END FOR ELSE
  10710. }
  10711. }// END FOR AC_QUANTITY
  10712. }
  10713. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10714. {
  10715. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10716. {
  10717. // Save profile to file
  10718. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10719. system(cmdBuf);
  10720. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10721. fp = fopen(cmdBuf, "w");
  10722. 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));
  10723. fclose(fp);
  10724. }
  10725. else
  10726. {
  10727. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10728. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10729. goto end;
  10730. }
  10731. }
  10732. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10733. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10734. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10735. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10736. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10737. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10738. }
  10739. else
  10740. {
  10741. uint8_t isHasIdleConnector = FALSE;
  10742. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10743. {
  10744. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10745. {
  10746. isHasIdleConnector = TRUE;
  10747. break;
  10748. }
  10749. }
  10750. if(isHasIdleConnector == TRUE)
  10751. {
  10752. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10753. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10754. {
  10755. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10756. {
  10757. // Save profile to file
  10758. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  10759. system(cmdBuf);
  10760. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  10761. fp = fopen(cmdBuf, "w");
  10762. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10763. fclose(fp);
  10764. refreshStartTimer(&clientTime.RemoteStartWait);
  10765. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  10766. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10767. }
  10768. else
  10769. {
  10770. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10771. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10772. }
  10773. }
  10774. }
  10775. else
  10776. {
  10777. DEBUG_INFO("There is not any connector is idle.\n");
  10778. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10779. }
  10780. }
  10781. }
  10782. else
  10783. {
  10784. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10785. }
  10786. end:
  10787. json_object_put(RemoteStartTransaction);
  10788. sendRemoteStartConfirmation(uuid, comfirmstr);
  10789. return result;
  10790. }
  10791. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10792. {
  10793. mtrace();
  10794. int result = FAIL;
  10795. int match = FALSE;
  10796. int GunNO = 0;
  10797. int tempIndex = 0;
  10798. int transactionIdInt=0;
  10799. int transactionIdIsNULL= TRUE;
  10800. char comfirmstr[20];
  10801. json_object *RemoteStopTransaction;
  10802. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10803. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10804. if(server_pending == TRUE)
  10805. {
  10806. return 0;
  10807. }
  10808. RemoteStopTransaction = json_tokener_parse(payload);
  10809. if(!is_error(RemoteStopTransaction))
  10810. {
  10811. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10812. {
  10813. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10814. transactionIdIsNULL = FALSE;
  10815. }
  10816. }
  10817. json_object_put(RemoteStopTransaction);
  10818. if(transactionIdIsNULL == FALSE)
  10819. {
  10820. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10821. {
  10822. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10823. {
  10824. //check Transaction active
  10825. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10826. {
  10827. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10828. {
  10829. tempIndex = ((gun_index==2) ? 1: 0);
  10830. }
  10831. else
  10832. {
  10833. tempIndex = gun_index;
  10834. }
  10835. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10836. {
  10837. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10838. {
  10839. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10840. {
  10841. match = TRUE;
  10842. GunNO = gun_index;
  10843. }
  10844. }
  10845. }// END FOR CHAdeMO_QUANTITY
  10846. }
  10847. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10848. {
  10849. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10850. {
  10851. tempIndex = ((gun_index==2) ? 1: 0);
  10852. }
  10853. else
  10854. {
  10855. tempIndex = gun_index;
  10856. }
  10857. for (int index = 0; index < CCS_QUANTITY; index++)
  10858. {
  10859. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10860. {
  10861. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10862. {
  10863. match = TRUE;
  10864. GunNO = gun_index;
  10865. }
  10866. }
  10867. }// END FOR CCS_QUANTITY
  10868. }
  10869. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10870. {
  10871. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10872. {
  10873. tempIndex = ((gun_index==2) ? 1: 0);
  10874. }
  10875. else
  10876. {
  10877. tempIndex = gun_index;
  10878. }
  10879. for (int index = 0; index < GB_QUANTITY; index++)
  10880. {
  10881. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10882. {
  10883. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10884. {
  10885. match = TRUE;
  10886. GunNO = gun_index;
  10887. }
  10888. }
  10889. }// END FOR GB_QUANTITY
  10890. }
  10891. else if(gunType[gun_index] == GUN_TYPE_DO)
  10892. {
  10893. tempIndex = gun_index;
  10894. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10895. {
  10896. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10897. {
  10898. 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
  10899. {
  10900. match = TRUE;
  10901. GunNO = gun_index;
  10902. }
  10903. }
  10904. }// END FOR GB_QUANTITY
  10905. }
  10906. else
  10907. {
  10908. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10909. {
  10910. tempIndex = 2;
  10911. }
  10912. else
  10913. {
  10914. tempIndex = gun_index;
  10915. }
  10916. for (int index = 0; index < AC_QUANTITY; index++)
  10917. {
  10918. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10919. {
  10920. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10921. {
  10922. match = TRUE;
  10923. GunNO = gun_index;
  10924. }
  10925. }
  10926. }// END FOR CHAdeMO_QUANTITY
  10927. } // END FOR AC ELSE
  10928. }// CHECK IF ResponseTransactionId == transactionIdInt
  10929. }//END FOR
  10930. if( match == TRUE)
  10931. {
  10932. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  10933. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10934. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  10935. }
  10936. else
  10937. {
  10938. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10939. }
  10940. }
  10941. else
  10942. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10943. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  10944. return result;
  10945. }
  10946. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  10947. {
  10948. mtrace();
  10949. int result = FAIL;
  10950. int connectorIdInt=0, reservationIdInt=0;
  10951. int tempIndex = 0;
  10952. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  10953. char comfirmstr[20]={0};
  10954. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  10955. int c = 0;
  10956. char *loc;
  10957. //char *ptr;
  10958. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  10959. strcpy(sstrtemp, stringtrimspace(payload));
  10960. //***(1)connectorId ****/
  10961. c=0;
  10962. loc = strstr(sstrtemp, "connectorId");
  10963. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10964. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  10965. {
  10966. sstr[c] = loc[strlen("connectorId")+2+c];
  10967. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10968. c++;
  10969. }
  10970. sstr[c] = '\0';
  10971. connectorIdInt = atoi(sstr);
  10972. //***(2)expiryDate ****/
  10973. loc = strstr(sstrtemp, "expiryDate");
  10974. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10975. c = 0;
  10976. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  10977. {
  10978. sstr[c] = loc[3+strlen("expiryDate")+c];
  10979. c++;
  10980. }
  10981. sstr[c] = '\0';
  10982. strcpy(expiryDatestr, sstr);
  10983. //***(3)idTag ****/
  10984. loc = strstr(sstrtemp, "idTag");
  10985. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10986. c = 0;
  10987. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  10988. {
  10989. sstr[c] = loc[3+strlen("idTag")+c];
  10990. c++;
  10991. }
  10992. sstr[c] = '\0';
  10993. strcpy(idTagstr, sstr);
  10994. //***(4)parentIdTag ****/
  10995. loc = strstr(sstrtemp, "parentIdTag");
  10996. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10997. c = 0;
  10998. if(loc == NULL)
  10999. {
  11000. strcpy(parentIdTagstr, "");
  11001. }
  11002. else
  11003. {
  11004. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11005. {
  11006. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11007. c++;
  11008. }
  11009. sstr[c] = '\0';
  11010. strcpy(parentIdTagstr, sstr);
  11011. }
  11012. //***(5)reservationId ****/
  11013. c=0;
  11014. loc = strstr(sstrtemp, "reservationId");
  11015. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11016. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11017. {
  11018. sstr[c] = loc[strlen("reservationId")+2+c];
  11019. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11020. c++;
  11021. }
  11022. sstr[c] = '\0';
  11023. reservationIdInt = atoi(sstr);
  11024. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11025. /*
  11026. enum SYSTEM_STATUS
  11027. {
  11028. SYS_MODE_BOOTING = 0,
  11029. SYS_MODE_IDLE = 1,
  11030. SYS_MODE_AUTHORIZING = 2,
  11031. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11032. SYS_MODE_REASSIGN = 4,
  11033. SYS_MODE_PREPARING = 5,
  11034. SYS_MODE_PREPARE_FOR_EV = 6,
  11035. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11036. SYS_MODE_CHARGING = 8,
  11037. SYS_MODE_TERMINATING = 9,
  11038. SYS_MODE_COMPLETE = 10,
  11039. SYS_MODE_ALARM = 11,
  11040. SYS_MODE_FAULT = 12,
  11041. SYS_MODE_RESERVATION = 13,
  11042. SYS_MODE_BOOKING = 14,
  11043. SYS_MODE_MAINTAIN = 15,
  11044. SYS_MODE_DEBUG = 16,
  11045. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11046. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11047. SYS_MODE_UPDATE = 19
  11048. };
  11049. */
  11050. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11051. {
  11052. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11053. goto end;
  11054. }
  11055. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11056. {
  11057. //check Transaction active
  11058. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11059. {
  11060. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11061. {
  11062. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11063. }
  11064. else
  11065. {
  11066. tempIndex = connectorIdInt -1;
  11067. }
  11068. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11069. {
  11070. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11071. {
  11072. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11073. {
  11074. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11075. {
  11076. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11077. {
  11078. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11079. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11080. }
  11081. 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'))
  11082. {
  11083. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11084. }
  11085. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11086. {
  11087. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11088. }
  11089. else
  11090. {
  11091. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11092. }
  11093. }
  11094. 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
  11095. {
  11096. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11097. }
  11098. }
  11099. else
  11100. {
  11101. //replace reservation
  11102. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11103. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11104. }
  11105. }
  11106. } // END FOR CHAdeMO_QUANTITY
  11107. }
  11108. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11109. {
  11110. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11111. {
  11112. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11113. }
  11114. else
  11115. {
  11116. tempIndex = connectorIdInt -1;
  11117. }
  11118. for (int index = 0; index < CCS_QUANTITY; index++)
  11119. {
  11120. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11121. {
  11122. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11123. {
  11124. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11125. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11126. {
  11127. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11128. {
  11129. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11130. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11131. }
  11132. 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'))
  11133. {
  11134. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11135. }
  11136. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11137. {
  11138. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11139. }
  11140. else
  11141. {
  11142. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11143. }
  11144. }
  11145. 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
  11146. {
  11147. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11148. }
  11149. }
  11150. else
  11151. {
  11152. //replace reservation
  11153. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11154. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11155. }
  11156. }
  11157. } // END FOR CCS_QUANTITY
  11158. }
  11159. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11160. {
  11161. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11162. {
  11163. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11164. }
  11165. else
  11166. {
  11167. tempIndex = connectorIdInt -1;
  11168. }
  11169. for (int index = 0; index < GB_QUANTITY; index++)
  11170. {
  11171. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11172. {
  11173. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11174. {
  11175. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11176. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11177. {
  11178. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11179. {
  11180. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11181. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11182. }
  11183. 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'))
  11184. {
  11185. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11186. }
  11187. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11188. {
  11189. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11190. }
  11191. else
  11192. {
  11193. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11194. }
  11195. }
  11196. 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
  11197. {
  11198. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11199. }
  11200. }
  11201. else
  11202. {
  11203. //replace reservation
  11204. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11205. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11206. }
  11207. }
  11208. }// END FOR GB_QUANTITY
  11209. }
  11210. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11211. {
  11212. tempIndex = connectorIdInt -1;
  11213. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11214. {
  11215. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11216. {
  11217. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11218. {
  11219. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11220. 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
  11221. {
  11222. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11223. {
  11224. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11225. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11226. }
  11227. 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'))
  11228. {
  11229. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11230. }
  11231. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11232. {
  11233. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11234. }
  11235. else
  11236. {
  11237. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11238. }
  11239. }
  11240. 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
  11241. {
  11242. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11243. }
  11244. }
  11245. else
  11246. {
  11247. //replace reservation
  11248. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11249. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11250. }
  11251. }
  11252. }// END FOR GB_QUANTITY
  11253. }
  11254. else
  11255. {
  11256. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11257. {
  11258. tempIndex = 2;
  11259. }
  11260. else
  11261. {
  11262. tempIndex = (connectorIdInt -1);
  11263. }
  11264. for (int index = 0; index < AC_QUANTITY; index++)
  11265. {
  11266. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11267. {
  11268. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11269. {
  11270. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11271. {
  11272. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11273. {
  11274. 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))
  11275. {
  11276. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11277. }
  11278. else
  11279. {
  11280. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11281. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11282. }
  11283. }
  11284. 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'))
  11285. {
  11286. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11287. }
  11288. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11289. {
  11290. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11291. }
  11292. else
  11293. {
  11294. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11295. }
  11296. }
  11297. 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
  11298. {
  11299. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11300. }
  11301. }
  11302. else
  11303. {
  11304. //replace reservation
  11305. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11306. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11307. }
  11308. }
  11309. } // END FOR AC_QUANTITY
  11310. }
  11311. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11312. }
  11313. else if(connectorIdInt == 0)
  11314. {
  11315. //check Transaction active
  11316. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11317. {
  11318. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11319. {
  11320. 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'))
  11321. {
  11322. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11323. goto end;
  11324. }
  11325. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11326. {
  11327. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11328. goto end;
  11329. }
  11330. 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
  11331. {
  11332. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11333. goto end;
  11334. }
  11335. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11336. {
  11337. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11338. goto end;
  11339. }
  11340. }
  11341. }// END FOR CHAdeMO_QUANTITY
  11342. for (int index = 0; index < CCS_QUANTITY; index++)
  11343. {
  11344. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11345. {
  11346. 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'))
  11347. {
  11348. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11349. goto end;
  11350. }
  11351. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11352. {
  11353. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11354. goto end;
  11355. }
  11356. 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
  11357. {
  11358. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11359. goto end;
  11360. }
  11361. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11362. {
  11363. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11364. goto end;
  11365. }
  11366. }
  11367. } // END FOR CCS_QUANTITY
  11368. for (int index = 0; index < GB_QUANTITY; index++)
  11369. {
  11370. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11371. {
  11372. 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'))
  11373. {
  11374. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11375. goto end;
  11376. }
  11377. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11378. {
  11379. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11380. goto end;
  11381. }
  11382. 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
  11383. {
  11384. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11385. goto end;
  11386. }
  11387. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11388. {
  11389. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11390. goto end;
  11391. }
  11392. }
  11393. } // END FOR GB_QUANTITY
  11394. for (int index = 0; index < AC_QUANTITY; index++)
  11395. {
  11396. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11397. {
  11398. 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'))
  11399. {
  11400. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11401. goto end;
  11402. }
  11403. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11404. {
  11405. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11406. goto end;
  11407. }
  11408. 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
  11409. {
  11410. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11411. goto end;
  11412. }
  11413. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11414. {
  11415. 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))
  11416. {
  11417. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11418. goto end;
  11419. }
  11420. }
  11421. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11422. {
  11423. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11424. goto end;
  11425. }
  11426. }
  11427. }// END FOR AC_QUANTITY
  11428. //The connectorId is 0
  11429. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  11430. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11431. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11432. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  11433. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11434. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  11435. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11436. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  11437. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  11438. result = TRUE;
  11439. return result;
  11440. }
  11441. else
  11442. {
  11443. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11444. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11445. }
  11446. if(strcmp(comfirmstr,"Accepted") == 0)
  11447. {
  11448. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11449. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11450. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11451. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11452. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11453. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  11454. result = TRUE;
  11455. return result;
  11456. }
  11457. end:
  11458. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11459. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11460. return result;
  11461. }
  11462. int handleResetRequest(char *uuid, char *payload)
  11463. {
  11464. mtrace();
  11465. int result = FAIL;
  11466. char sstr[10]={0},sstrtemp[30]={ 0 };
  11467. char typestr[10]={0};
  11468. char comfirmstr[20]={0};
  11469. int c = 0;
  11470. char *loc;
  11471. DEBUG_INFO("handleResetRequest...\n");
  11472. strcpy(sstrtemp, stringtrimspace(payload));
  11473. loc = strstr(sstrtemp, "type");
  11474. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11475. c = 0;
  11476. while (loc[3+strlen("type")+c] != '\"')
  11477. {
  11478. sstr[c] = loc[3+strlen("type")+c];
  11479. c++;
  11480. }
  11481. sstr[c] = '\0';
  11482. strcpy(typestr,sstr);
  11483. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11484. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11485. {
  11486. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11487. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  11488. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11489. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11490. }
  11491. else
  11492. {
  11493. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11494. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11495. result = PASS;
  11496. }
  11497. sendResetConfirmation(uuid, comfirmstr);
  11498. return result;
  11499. }
  11500. int handleSendLocalListRequest(char *uuid, char *payload)
  11501. {
  11502. mtrace();
  11503. int result = FAIL;
  11504. char comfirmstr[20];
  11505. int checkState_Faulted = FALSE;
  11506. json_object *SendLocalList;
  11507. DEBUG_INFO("handleSendLocalListRequest...\n");
  11508. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11509. {
  11510. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11511. goto end;
  11512. }
  11513. //check Charge Point state
  11514. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11515. {
  11516. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11517. {
  11518. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11519. }
  11520. }
  11521. for (int index = 0; index < CCS_QUANTITY; index++)
  11522. {
  11523. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11524. {
  11525. checkState_Faulted = TRUE; //OCPP Status
  11526. }
  11527. }
  11528. for (int index = 0; index < GB_QUANTITY; index++)
  11529. {
  11530. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11531. {
  11532. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11533. }
  11534. }
  11535. //check Charge Point state
  11536. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11537. {
  11538. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11539. {
  11540. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11541. }
  11542. }
  11543. //check Charge Point state
  11544. for (int index = 0; index < AC_QUANTITY; index++)
  11545. {
  11546. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11547. {
  11548. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11549. }
  11550. }
  11551. if(checkState_Faulted == TRUE)
  11552. {
  11553. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11554. goto end;
  11555. }
  11556. // Parsing payload
  11557. SendLocalList = json_tokener_parse(payload);
  11558. if(!is_error(SendLocalList))
  11559. {
  11560. // Required data
  11561. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11562. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11563. // Optional data
  11564. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11565. {
  11566. //Check UpdateType
  11567. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11568. {
  11569. //Local list full update
  11570. DEBUG_INFO("Local list full update.\n");
  11571. OCPP_getListVerion();
  11572. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11573. {
  11574. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11575. goto end;
  11576. }
  11577. OCPP_cleanLocalList();
  11578. }
  11579. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11580. {
  11581. //Local list different update
  11582. DEBUG_INFO("Local list different update.\n");
  11583. OCPP_getListVerion();
  11584. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11585. {
  11586. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11587. goto end;
  11588. }
  11589. }
  11590. else
  11591. {
  11592. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11593. goto end;
  11594. }
  11595. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11596. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11597. {
  11598. 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")));
  11599. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11600. {
  11601. 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")));
  11602. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11603. 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")));
  11604. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11605. 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")));
  11606. }
  11607. // Add to db
  11608. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11609. {
  11610. //Local list full update
  11611. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11612. idx,
  11613. ShmOCPP16Data->SendLocalList.ListVersion,
  11614. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11615. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11616. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11617. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11618. // update list
  11619. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11620. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11621. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11622. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11623. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11624. }
  11625. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11626. {
  11627. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11628. idx,
  11629. ShmOCPP16Data->SendLocalList.ListVersion,
  11630. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11631. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11632. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11633. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11634. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11635. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11636. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11637. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11638. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11639. }
  11640. }
  11641. }
  11642. else
  11643. {
  11644. //Check UpdateType
  11645. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11646. {
  11647. //Local list full update
  11648. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11649. OCPP_cleanLocalList();
  11650. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11651. goto end;
  11652. }
  11653. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11654. {
  11655. //Local list different update
  11656. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11657. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11658. goto end;
  11659. }
  11660. }
  11661. result = PASS;
  11662. }
  11663. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11664. end:
  11665. json_object_put(SendLocalList);
  11666. sendSendLocalListConfirmation(uuid, comfirmstr);
  11667. return result;
  11668. }
  11669. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11670. {
  11671. mtrace();
  11672. int result = FAIL;
  11673. struct StructSetChargingProfile SetProfileReq = {0};
  11674. int tempchargingProfileIdInt;
  11675. int chargingSchedulePeriodCount = 0;
  11676. char comfirmstr[20]={0};
  11677. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  11678. char rmFileCmd[128]={0};
  11679. int profileQuantity = 0;
  11680. json_object *SetChargingProfile;
  11681. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11682. SetChargingProfile = json_tokener_parse(payload);
  11683. if(!is_error(SetChargingProfile))
  11684. {
  11685. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11686. {
  11687. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11688. }
  11689. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11690. {
  11691. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11692. {
  11693. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11694. }
  11695. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11696. {
  11697. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11698. }
  11699. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11700. {
  11701. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11702. }
  11703. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11704. {
  11705. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11706. }
  11707. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11708. {
  11709. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11710. }
  11711. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11712. {
  11713. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11714. }
  11715. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11716. {
  11717. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11718. }
  11719. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11720. {
  11721. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11722. }
  11723. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11724. {
  11725. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11726. {
  11727. 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")));
  11728. }
  11729. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11730. {
  11731. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11732. }
  11733. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11734. {
  11735. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11736. }
  11737. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11738. {
  11739. 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")));
  11740. }
  11741. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11742. {
  11743. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11744. if(chargingSchedulePeriodCount <= 10)
  11745. {
  11746. 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++)
  11747. {
  11748. 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)
  11749. {
  11750. 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"));
  11751. }
  11752. 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)
  11753. {
  11754. 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"));
  11755. }
  11756. 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)
  11757. {
  11758. 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"));
  11759. }
  11760. }
  11761. }
  11762. }
  11763. }
  11764. }
  11765. }
  11766. // Profile periods quantity check
  11767. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11768. {
  11769. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11770. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11771. goto end;
  11772. }
  11773. // Check invalid limit
  11774. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11775. {
  11776. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11777. {
  11778. 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)))) ||
  11779. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11780. {
  11781. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11782. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11783. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11784. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11785. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11786. goto end;
  11787. }
  11788. }
  11789. }
  11790. else
  11791. {
  11792. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11793. {
  11794. 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))
  11795. {
  11796. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11797. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11798. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11799. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11800. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11801. goto end;
  11802. }
  11803. }
  11804. }
  11805. // Profile purpose info check
  11806. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11807. {
  11808. FILE *fp;
  11809. char dataLine[4096]={0};
  11810. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11811. if(SetProfileReq.ConnectorId != 0)
  11812. {
  11813. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11814. DEBUG_WARN("Profile connector id is not 0.\n");
  11815. goto end;
  11816. }
  11817. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11818. if (!fp)
  11819. {
  11820. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11821. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11822. }
  11823. else
  11824. {
  11825. while(fscanf(fp, "%s", dataLine) != EOF)
  11826. {
  11827. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11828. {
  11829. profileQuantity += 1;
  11830. }
  11831. }
  11832. }
  11833. fclose(fp);
  11834. }
  11835. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11836. {
  11837. FILE *fp;
  11838. char dataLine[4096]={0};
  11839. char filename[128]={0};
  11840. int tmpProfileQuantity;
  11841. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11842. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11843. {
  11844. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11845. DEBUG_WARN("Profile connector id is over max gun number.\n");
  11846. goto end;
  11847. }
  11848. if(SetProfileReq.ConnectorId == 0)
  11849. {
  11850. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  11851. {
  11852. tmpProfileQuantity = 0;
  11853. memset(filename, 0, ARRAY_SIZE(filename));
  11854. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  11855. fp = fopen(filename, "r");
  11856. if (!fp)
  11857. {
  11858. DEBUG_INFO("%s does not create.\n", filename);
  11859. fp = fopen(filename, "w+");
  11860. }
  11861. else
  11862. {
  11863. while(fscanf(fp, "%s", dataLine) != EOF)
  11864. {
  11865. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11866. {
  11867. tmpProfileQuantity += 1;
  11868. }
  11869. }
  11870. }
  11871. fclose(fp);
  11872. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  11873. }
  11874. }
  11875. else
  11876. {
  11877. memset(filename, 0, ARRAY_SIZE(filename));
  11878. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11879. fp = fopen(filename, "r");
  11880. if (!fp)
  11881. {
  11882. DEBUG_INFO("%s does not create.\n", filename);
  11883. fp = fopen(filename, "w+");
  11884. }
  11885. else
  11886. {
  11887. while(fscanf(fp, "%s", dataLine) != EOF)
  11888. {
  11889. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11890. {
  11891. profileQuantity += 1;
  11892. }
  11893. }
  11894. }
  11895. fclose(fp);
  11896. }
  11897. }
  11898. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11899. {
  11900. int isMatchTransactiodId= FALSE;
  11901. FILE *fp;
  11902. char dataLine[4096]={0};
  11903. char filename[128]={0};
  11904. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  11905. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  11906. if(SetProfileReq.ConnectorId == 0)
  11907. {
  11908. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11909. DEBUG_WARN("Profile connector id is 0.\n");
  11910. goto end;
  11911. }
  11912. int tempIndex = 0;
  11913. //check Transaction active
  11914. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  11915. {
  11916. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11917. {
  11918. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11919. }
  11920. else
  11921. {
  11922. tempIndex = SetProfileReq.ConnectorId -1;
  11923. }
  11924. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11925. {
  11926. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11927. {
  11928. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11929. {
  11930. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11931. {
  11932. isMatchTransactiodId = TRUE;
  11933. break;
  11934. }
  11935. }
  11936. }
  11937. }
  11938. }
  11939. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  11940. {
  11941. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11942. {
  11943. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11944. }
  11945. else
  11946. {
  11947. tempIndex = SetProfileReq.ConnectorId -1;
  11948. }
  11949. for (int index = 0; index < CCS_QUANTITY; index++)
  11950. {
  11951. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11952. {
  11953. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  11954. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11955. {
  11956. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11957. {
  11958. isMatchTransactiodId = TRUE;
  11959. break;
  11960. }
  11961. }
  11962. }
  11963. }
  11964. }
  11965. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  11966. {
  11967. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11968. {
  11969. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11970. }
  11971. else
  11972. {
  11973. tempIndex = SetProfileReq.ConnectorId -1;
  11974. }
  11975. for (int index = 0; index < GB_QUANTITY; index++)
  11976. {
  11977. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11978. {
  11979. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11980. {
  11981. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11982. {
  11983. isMatchTransactiodId = TRUE;
  11984. break;
  11985. }
  11986. }
  11987. }
  11988. }
  11989. }
  11990. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  11991. {
  11992. tempIndex = SetProfileReq.ConnectorId -1;
  11993. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11994. {
  11995. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11996. {
  11997. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  11998. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11999. {
  12000. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12001. {
  12002. isMatchTransactiodId = TRUE;
  12003. break;
  12004. }
  12005. }
  12006. }
  12007. }
  12008. }
  12009. else
  12010. {
  12011. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12012. {
  12013. tempIndex = 2;
  12014. }
  12015. else
  12016. {
  12017. tempIndex = (SetProfileReq.ConnectorId -1);
  12018. }
  12019. for (int index = 0; index < AC_QUANTITY; index++)
  12020. {
  12021. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12022. {
  12023. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12024. {
  12025. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12026. {
  12027. isMatchTransactiodId = TRUE;
  12028. break;
  12029. }
  12030. }
  12031. }
  12032. }
  12033. }
  12034. //check Transaction active
  12035. if(isMatchTransactiodId == FALSE)
  12036. {
  12037. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12038. DEBUG_WARN("Tx profile transaction id is not match.\n");
  12039. goto end;
  12040. }
  12041. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12042. {
  12043. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12044. DEBUG_WARN("Connector id is over max gun number.\n");
  12045. goto end;
  12046. }
  12047. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12048. fp = fopen(filename, "r");
  12049. if (!fp)
  12050. {
  12051. DEBUG_INFO("%s does not create.\n", filename);
  12052. fp = fopen(filename, "w+");
  12053. }
  12054. else
  12055. {
  12056. //Check Charging Profile Count
  12057. while(fscanf(fp, "%s", dataLine) != EOF)
  12058. {
  12059. //DEBUG_INFO("word=%s\n",word);
  12060. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12061. {
  12062. profileQuantity += 1;
  12063. }
  12064. }
  12065. }
  12066. fclose(fp);
  12067. }
  12068. // Check ChargeProfileMaxStackLevel
  12069. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12070. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12071. {
  12072. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12073. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12074. goto end;
  12075. }
  12076. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12077. {
  12078. FILE *fp;
  12079. char dataLine[4096]={0};
  12080. char fnametemp[128]={0};
  12081. int tmpProfileQuantity;
  12082. //Check ChargePointMaxProfile.json exit
  12083. profileQuantity = 0;
  12084. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12085. {
  12086. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  12087. //Check Charging Profile Count
  12088. tmpProfileQuantity = 0;
  12089. while(fscanf(fp, "%s", dataLine) != EOF)
  12090. {
  12091. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12092. {
  12093. profileQuantity += 1;
  12094. tmpProfileQuantity += 1;
  12095. }
  12096. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12097. }
  12098. fclose(fp);
  12099. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12100. }
  12101. //Check TxDefaultProfile_%d.json
  12102. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12103. {
  12104. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12105. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12106. if((access(fnametemp,F_OK))!=-1)
  12107. {
  12108. fp = fopen(fnametemp, "r");
  12109. //Check Charging Profile Count
  12110. tmpProfileQuantity = 0;
  12111. while(fscanf(fp, "%s", dataLine) != EOF)
  12112. {
  12113. //DEBUG_INFO("word=%s\n",word);
  12114. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12115. {
  12116. profileQuantity += 1;
  12117. tmpProfileQuantity += 1;
  12118. }
  12119. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12120. }
  12121. fclose(fp);
  12122. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12123. }
  12124. }
  12125. //Check TxProfile_%d.json
  12126. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12127. {
  12128. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12129. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  12130. if((access(fnametemp,F_OK))!=-1)
  12131. {
  12132. fp = fopen(fnametemp, "r");
  12133. //Check Charging Profile Count
  12134. tmpProfileQuantity = 0;
  12135. while(fscanf(fp, "%s", dataLine) != EOF)
  12136. {
  12137. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12138. {
  12139. profileQuantity += 1;
  12140. tmpProfileQuantity += 1;
  12141. }
  12142. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12143. }
  12144. fclose(fp);
  12145. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12146. }
  12147. }
  12148. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12149. if(profileQuantity > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12150. {
  12151. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12152. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12153. goto end;
  12154. }
  12155. }
  12156. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12157. //**********************************Write to File********************************************************/
  12158. {
  12159. FILE *infile;
  12160. FILE *outfile;
  12161. char dataLine[4096]={0};
  12162. char filename[128]={0};
  12163. int chkChar=0;
  12164. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12165. {
  12166. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12167. {
  12168. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12169. }
  12170. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12171. {
  12172. if(SetProfileReq.ConnectorId==0)
  12173. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12174. else
  12175. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12176. }
  12177. else
  12178. {
  12179. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12180. }
  12181. infile = fopen (filename, "r");
  12182. outfile = fopen (tempfile, "w");
  12183. chkChar = fgetc(infile);
  12184. rewind(infile);
  12185. if(chkChar == EOF)
  12186. {
  12187. // Profile is empty
  12188. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12189. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12190. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12191. fclose(infile);
  12192. fclose(outfile);
  12193. sprintf(rmFileCmd,"rm -f %s",filename);
  12194. system(rmFileCmd);
  12195. rename(tempfile, filename);
  12196. }
  12197. else
  12198. {
  12199. // Profile is not empty
  12200. int ChargingProfileAdded = FALSE;
  12201. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12202. {
  12203. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12204. json_object *tmpChargingProfile;
  12205. tmpChargingProfile = json_tokener_parse(dataLine);
  12206. if(!is_error(SetChargingProfile))
  12207. {
  12208. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12209. {
  12210. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12211. {
  12212. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12213. }
  12214. }
  12215. }
  12216. json_object_put(tmpChargingProfile);
  12217. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12218. {
  12219. if(ChargingProfileAdded == FALSE)
  12220. {
  12221. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12222. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12223. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12224. ChargingProfileAdded = TRUE;
  12225. }
  12226. }
  12227. else
  12228. {
  12229. fprintf(outfile,"%s\n",dataLine);
  12230. if(ChargingProfileAdded == FALSE)
  12231. {
  12232. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12233. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12234. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12235. ChargingProfileAdded = TRUE;
  12236. }
  12237. }
  12238. } // end of while loop
  12239. fclose(infile);
  12240. fclose(outfile);
  12241. sprintf(rmFileCmd,"rm -f %s",filename);
  12242. system(rmFileCmd);
  12243. rename(tempfile, filename);
  12244. }
  12245. }
  12246. sleep(1);
  12247. result = TRUE;
  12248. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12249. }
  12250. end:
  12251. json_object_put(SetChargingProfile);
  12252. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12253. {
  12254. if(SetProfileReq.ConnectorId == 0)
  12255. {
  12256. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12257. {
  12258. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  12259. }
  12260. }
  12261. else
  12262. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12263. }
  12264. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12265. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12266. return result;
  12267. }
  12268. int handleTriggerMessageRequest(char *uuid, char *payload)
  12269. {
  12270. mtrace();
  12271. int result = FAIL;
  12272. int connectorIdIsNULL = FALSE;
  12273. int connectorIdInt =0;
  12274. char sstr[40]={0},sstrtemp[100]={ 0 };
  12275. char requestedMessagestr[40]={0};
  12276. char comfirmstr[20]={0};
  12277. int c = 0;
  12278. char *loc;
  12279. DEBUG_INFO("handleTriggerMessageRequest\n");
  12280. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12281. strcpy(sstrtemp, stringtrimspace(payload));
  12282. c = 0;
  12283. loc = strstr(sstrtemp, "requestedMessage");
  12284. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12285. {
  12286. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12287. c++;
  12288. }
  12289. sstr[c] = '\0';
  12290. strcpy(requestedMessagestr, sstr);
  12291. c = 0;
  12292. loc = strstr(sstrtemp, "connectorId");
  12293. if(loc == NULL)
  12294. {
  12295. connectorIdIsNULL = TRUE;
  12296. }
  12297. else
  12298. {
  12299. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12300. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12301. {
  12302. sstr[c] = loc[strlen("connectorId")+2+c];
  12303. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12304. c++;
  12305. }
  12306. sstr[c] = '\0';
  12307. connectorIdInt = atoi(sstr);
  12308. }
  12309. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12310. {
  12311. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12312. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12313. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12314. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12315. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12316. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12317. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12318. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12319. {
  12320. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12321. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12322. return TRUE;
  12323. }
  12324. else
  12325. {
  12326. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12327. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12328. }
  12329. }
  12330. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12331. {
  12332. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12333. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12334. return TRUE;
  12335. }
  12336. //==========================
  12337. // Trigger message
  12338. //==========================
  12339. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12340. {
  12341. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12342. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12343. {
  12344. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12345. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12346. }
  12347. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12348. }
  12349. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12350. {
  12351. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  12352. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12353. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12354. }
  12355. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12356. {
  12357. //sendBootNotificationRequest();
  12358. server_sign = FALSE;
  12359. }
  12360. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12361. {
  12362. refreshStartTimer(&clientTime.Heartbeat);
  12363. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  12364. }
  12365. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12366. {
  12367. if(connectorIdIsNULL == FALSE)
  12368. {
  12369. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12370. {
  12371. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12372. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12373. }
  12374. }
  12375. else
  12376. {
  12377. for(int idx=0;idx< gunTotalNumber;idx++)
  12378. {
  12379. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12380. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12381. }
  12382. }
  12383. }
  12384. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12385. {
  12386. if(connectorIdIsNULL == FALSE)
  12387. {
  12388. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  12389. {
  12390. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12391. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  12392. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12393. }
  12394. }
  12395. else
  12396. {
  12397. for(int idx=0;idx< gunTotalNumber;idx++)
  12398. {
  12399. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  12400. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12401. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12402. }
  12403. }
  12404. }
  12405. return result;
  12406. }
  12407. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12408. {
  12409. mtrace();
  12410. int result = FAIL;
  12411. int connectorIdInt =0;
  12412. char comfirmstr[20]={0};
  12413. int tempIndex = 0;
  12414. json_object *UnlockConnector;
  12415. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12416. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12417. UnlockConnector = json_tokener_parse(payload);
  12418. if(!is_error(UnlockConnector))
  12419. {
  12420. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12421. {
  12422. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12423. }
  12424. }
  12425. json_object_put(UnlockConnector);
  12426. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12427. if(gunTotalNumber == 0)
  12428. {
  12429. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12430. goto end;
  12431. }
  12432. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12433. {
  12434. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12435. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12436. goto end;
  12437. }
  12438. else
  12439. {
  12440. //check Transaction active
  12441. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12442. {
  12443. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12444. {
  12445. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12446. }
  12447. else
  12448. {
  12449. tempIndex = connectorIdInt -1;
  12450. }
  12451. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12452. {
  12453. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12454. {
  12455. //stop Transaction
  12456. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12457. }
  12458. }
  12459. }
  12460. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12461. {
  12462. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12463. {
  12464. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12465. }
  12466. else
  12467. {
  12468. tempIndex = connectorIdInt -1;
  12469. }
  12470. for (int index = 0; index < CCS_QUANTITY; index++)
  12471. {
  12472. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12473. {
  12474. //stop Transaction
  12475. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12476. }
  12477. }
  12478. }
  12479. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12480. {
  12481. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12482. {
  12483. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12484. }
  12485. else
  12486. {
  12487. tempIndex = connectorIdInt -1;
  12488. }
  12489. for (int index = 0; index < GB_QUANTITY; index++)
  12490. {
  12491. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12492. {
  12493. //stop Transaction
  12494. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12495. }
  12496. }
  12497. }
  12498. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12499. {
  12500. tempIndex = connectorIdInt -1;
  12501. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12502. {
  12503. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12504. {
  12505. //stop Transaction
  12506. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12507. }
  12508. }
  12509. }
  12510. else
  12511. {
  12512. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12513. {
  12514. tempIndex = 2;
  12515. }
  12516. else
  12517. {
  12518. tempIndex = connectorIdInt-1;
  12519. }
  12520. for (int index = 0; index < AC_QUANTITY; index++)
  12521. {
  12522. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12523. {
  12524. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12525. }
  12526. }
  12527. }
  12528. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12529. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  12530. result = TRUE;
  12531. return result;
  12532. }
  12533. end:
  12534. //json_object_put(obj); --- remove temporally
  12535. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12536. return result;
  12537. }
  12538. static char UpdateFirmwarepayloadData[300]={0};
  12539. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12540. {
  12541. mtrace();
  12542. int result = FAIL;
  12543. pthread_t t;
  12544. sendUpdateFirmwareConfirmation(uuid);
  12545. memset(UpdateFirmwarepayloadData, 0, 300);
  12546. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12547. if(!interLock.isUpdateFirmwareGoing)
  12548. {
  12549. interLock.isUpdateFirmwareGoing = 1;
  12550. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12551. sleep(1);
  12552. }
  12553. else
  12554. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12555. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  12556. return result;
  12557. }
  12558. void *UpdateFirmwareProcess(void *data)
  12559. {
  12560. pthread_detach(pthread_self());
  12561. mtrace();
  12562. int retriesInt =0, retryIntervalInt=0;
  12563. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  12564. int port=0;
  12565. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  12566. int isSuccess = 0;
  12567. char ftpbuf[1024];
  12568. char temp[1024];
  12569. char * pch;
  12570. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12571. json_object *UpdateFirmware;
  12572. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12573. if(!is_error(UpdateFirmware))
  12574. {
  12575. // Required data
  12576. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12577. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12578. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12579. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12580. // Optional data
  12581. if(json_object_object_get(UpdateFirmware, "retries"))
  12582. {
  12583. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12584. }
  12585. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12586. {
  12587. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12588. }
  12589. }
  12590. json_object_put(UpdateFirmware);
  12591. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12592. memset(path, 0, ARRAY_SIZE(path));
  12593. // Wait retrieveData
  12594. if(strlen(retrieveDatestr) > 10)
  12595. {
  12596. do
  12597. {
  12598. sleep(1);
  12599. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12600. }
  12601. // Ready to download
  12602. system("rm -f /mnt/*");
  12603. if(strncmp(locationstr,"http", 4) == 0)
  12604. {
  12605. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12606. sprintf(ftppath,"/%s", path);
  12607. DEBUG_INFO("locationstr: %s\n", locationstr);
  12608. DEBUG_INFO("protocol: %s\n",protocol);
  12609. DEBUG_INFO("host: %s\n",host);
  12610. DEBUG_INFO("path: %s\n",path);
  12611. DEBUG_INFO("ftppath: %s\n",ftppath);
  12612. int ftppathlen=strlen(ftppath);
  12613. int i=1;
  12614. char filenametemp[50];
  12615. while(i < ftppathlen)
  12616. {
  12617. int len=ftppathlen-i;
  12618. if(ftppath[len]== 47) // '/' ascll code: 47
  12619. {
  12620. DEBUG_INFO("compare '/' all right\n");
  12621. break;
  12622. }
  12623. i=i+1;
  12624. }
  12625. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12626. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12627. filenametemp[i+1] = 0;
  12628. do
  12629. {
  12630. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12631. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12632. sleep(1);
  12633. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12634. if(!isSuccess)
  12635. {
  12636. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12637. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12638. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12639. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12640. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12641. }
  12642. else
  12643. {
  12644. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12645. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12646. }
  12647. retriesInt--;
  12648. }while((isSuccess == 0)&&(retriesInt >= 0));
  12649. }
  12650. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12651. {
  12652. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12653. memset(temp, 0, ARRAY_SIZE(temp));
  12654. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12655. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12656. int ftppathlen=strlen(ftpbuf);
  12657. int i=1;
  12658. char filenametemp[50];
  12659. while(i < ftppathlen)
  12660. {
  12661. int len=ftppathlen-i;
  12662. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12663. {
  12664. DEBUG_INFO(" compare '/' all right\n");
  12665. break;
  12666. }
  12667. i=i+1;
  12668. }
  12669. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12670. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12671. filenametemp[i+1] = 0;
  12672. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12673. pch=strchr(temp,'@');
  12674. if(pch==NULL)
  12675. {
  12676. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12677. protocol, host, &port, path);
  12678. strcpy(user,"anonymous");
  12679. strcpy(password,"");
  12680. }
  12681. else
  12682. {
  12683. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12684. protocol, user, password, host, &port, path);
  12685. }
  12686. sscanf(host,"%[^/]%s",host1, path1);
  12687. sprintf(ftppath,"%s", path1);
  12688. //DEBUG_INFO("protocol =%s\n",protocol);
  12689. //DEBUG_INFO("user =%s\n",user);
  12690. //DEBUG_INFO("password =%s\n",password);
  12691. //DEBUG_INFO("host1 =%s\n",host1);
  12692. //DEBUG_INFO("port =%d\n",port);
  12693. //DEBUG_INFO("path1 =%s\n",path1);
  12694. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12695. //ftpFile(host, user, password, port, ftppath, fname);
  12696. //download firmware pthred
  12697. if(port == 0)
  12698. {
  12699. port = 21;
  12700. }
  12701. do
  12702. {
  12703. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12704. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12705. sleep(1);
  12706. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12707. if(!isSuccess)
  12708. {
  12709. //BulldogUtil.sleepMs(interval*1000);
  12710. DEBUG_INFO("Update firmware request and download file fail.\n");
  12711. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12712. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12713. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12714. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12715. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12716. }
  12717. else
  12718. {
  12719. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12720. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12721. }
  12722. retriesInt--;
  12723. }while((!isSuccess)&&(retriesInt >= 0));
  12724. }
  12725. else
  12726. {
  12727. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12728. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12729. sleep(1);
  12730. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12731. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12732. }
  12733. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12734. interLock.isUpdateFirmwareGoing = 0;
  12735. pthread_exit(NULL);
  12736. }
  12737. int handleCertificateSignedRequest(char *uuid, char *payload)
  12738. {
  12739. mtrace();
  12740. int result = PASS;
  12741. json_object *CertificateSigned;
  12742. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12743. CertificateSigned = json_tokener_parse(payload);
  12744. if(!is_error(CertificateSigned))
  12745. {
  12746. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  12747. }
  12748. json_object_put(CertificateSigned);
  12749. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  12750. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  12751. fclose(fp);
  12752. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12753. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  12754. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  12755. sendCertificateSignedConfirmation(uuid);
  12756. return result;
  12757. }
  12758. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12759. {
  12760. mtrace();
  12761. int result = PASS;
  12762. json_object *DeleteCertificate;
  12763. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12764. DeleteCertificate = json_tokener_parse(payload);
  12765. if(!is_error(DeleteCertificate))
  12766. {
  12767. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12768. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12769. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12770. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12771. }
  12772. json_object_put(DeleteCertificate);
  12773. /*
  12774. * TODO: Delete certificateSigned process
  12775. */
  12776. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  12777. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  12778. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  12779. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  12780. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  12781. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  12782. sendDeleteCertificateConfirmation(uuid);
  12783. return result;
  12784. }
  12785. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12786. {
  12787. mtrace();
  12788. int result = PASS;
  12789. json_object *ExtendedTriggerMessage;
  12790. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12791. ExtendedTriggerMessage = json_tokener_parse(payload);
  12792. if(!is_error(ExtendedTriggerMessage))
  12793. {
  12794. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12795. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12796. {
  12797. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12798. }
  12799. else
  12800. {
  12801. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  12802. }
  12803. }
  12804. json_object_put(ExtendedTriggerMessage);
  12805. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  12806. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  12807. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  12808. {
  12809. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  12810. }
  12811. else
  12812. {
  12813. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  12814. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  12815. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12816. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  12817. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  12818. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  12819. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  12820. {
  12821. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12822. }
  12823. else
  12824. {
  12825. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12826. }
  12827. }
  12828. sendExtendedTriggerMessageConfirmation(uuid);
  12829. //==========================
  12830. // Trigger message
  12831. //==========================
  12832. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  12833. {
  12834. //sendBootNotificationRequest();
  12835. server_sign = FALSE;
  12836. }
  12837. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  12838. {
  12839. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  12840. }
  12841. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12842. {
  12843. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12844. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12845. {
  12846. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12847. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12848. }
  12849. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12850. }
  12851. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  12852. {
  12853. refreshStartTimer(&clientTime.Heartbeat);
  12854. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  12855. }
  12856. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  12857. {
  12858. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12859. {
  12860. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  12861. }
  12862. else
  12863. {
  12864. for(int idx=0;idx< gunTotalNumber;idx++)
  12865. {
  12866. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12867. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12868. }
  12869. }
  12870. }
  12871. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  12872. {
  12873. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  12874. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  12875. {
  12876. 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\" &");
  12877. }
  12878. }
  12879. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  12880. {
  12881. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12882. {
  12883. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  12884. }
  12885. else
  12886. {
  12887. for(int idx=0;idx< gunTotalNumber;idx++)
  12888. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  12889. }
  12890. }
  12891. return result;
  12892. }
  12893. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  12894. {
  12895. mtrace();
  12896. int result = PASS;
  12897. json_object *GetInstalledCertificateIds;
  12898. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  12899. GetInstalledCertificateIds = json_tokener_parse(payload);
  12900. if(!is_error(GetInstalledCertificateIds))
  12901. {
  12902. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  12903. }
  12904. json_object_put(GetInstalledCertificateIds);
  12905. /*
  12906. * TODO: Return installed certificate process
  12907. */
  12908. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  12909. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  12910. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  12911. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  12912. sendGetInstalledCertificateIdsConfirmation(uuid);
  12913. return result;
  12914. }
  12915. int handleGetLogRequest(char *uuid, char *payload)
  12916. {
  12917. mtrace();
  12918. int result = PASS;
  12919. json_object *GetLog;
  12920. DEBUG_INFO("handleGetLogRequest...\n");
  12921. GetLog = json_tokener_parse(payload);
  12922. if(!is_error(GetLog))
  12923. {
  12924. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  12925. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  12926. if(json_object_object_get(GetLog, "retries") != NULL)
  12927. {
  12928. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  12929. }
  12930. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  12931. {
  12932. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  12933. }
  12934. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  12935. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  12936. {
  12937. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  12938. }
  12939. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  12940. {
  12941. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  12942. }
  12943. }
  12944. json_object_put(GetLog);
  12945. /*
  12946. * TODO: Upload log process
  12947. */
  12948. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  12949. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  12950. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  12951. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  12952. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  12953. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  12954. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  12955. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  12956. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  12957. sendGetLogConfirmation(uuid);
  12958. return result;
  12959. }
  12960. int handleInstallCertificateRequest(char *uuid, char *payload)
  12961. {
  12962. mtrace();
  12963. int result = PASS;
  12964. json_object *InstallCertificate;
  12965. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12966. InstallCertificate = json_tokener_parse(payload);
  12967. if(!is_error(InstallCertificate))
  12968. {
  12969. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12970. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12971. /*
  12972. * TODO: Install certificate process
  12973. */
  12974. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  12975. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  12976. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  12977. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  12978. sendInstallCertificateConfirmation(uuid);
  12979. }
  12980. json_object_put(InstallCertificate);
  12981. return result;
  12982. }
  12983. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12984. {
  12985. mtrace();
  12986. int result = PASS;
  12987. json_object *SignedUpdateFirmware;
  12988. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12989. SignedUpdateFirmware = json_tokener_parse(payload);
  12990. if(!is_error(SignedUpdateFirmware))
  12991. {
  12992. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12993. {
  12994. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12995. }
  12996. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12997. {
  12998. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12999. }
  13000. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13001. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13002. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13003. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13004. {
  13005. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13006. }
  13007. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13008. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13009. }
  13010. json_object_put(SignedUpdateFirmware);
  13011. /*
  13012. * TODO: Upgrade firmware process
  13013. */
  13014. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13015. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  13016. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  13017. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  13018. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  13019. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  13020. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  13021. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  13022. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  13023. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  13024. sendInstallCertificateConfirmation(uuid);
  13025. return result;
  13026. }
  13027. int handleUnknownRequest(char *uuid, char *payload)
  13028. {
  13029. mtrace();
  13030. int result = PASS;
  13031. DEBUG_INFO("handleUnknownRequest...\n");
  13032. sendUnknownConfirmation(uuid);
  13033. result = PASS;
  13034. return result;
  13035. }
  13036. //==========================================
  13037. // Handle server response routine
  13038. //==========================================
  13039. void handleAuthorizeResponse(char *payload, int gun_index)
  13040. {
  13041. mtrace();
  13042. char expiryDatestr[30]={0};
  13043. char parentIdTagstr[20]={0};
  13044. char statusstr[20]={0};
  13045. int expiryDateISNULL=FALSE;
  13046. int parentIdTagISNULL=FALSE;
  13047. DEBUG_INFO("handleAuthorizeResponse...\n");
  13048. json_object *Authorize;
  13049. Authorize = json_tokener_parse(payload);
  13050. if(!is_error(Authorize))
  13051. {
  13052. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13053. {
  13054. // Required data
  13055. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13056. // Optional data
  13057. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13058. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13059. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13060. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13061. }
  13062. }
  13063. json_object_put(Authorize);
  13064. if(expiryDateISNULL == FALSE)
  13065. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13066. if(parentIdTagISNULL == FALSE)
  13067. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13068. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  13069. //Update idTag information to authorization cache if supproted
  13070. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13071. {
  13072. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13073. }
  13074. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  13075. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13076. authorizeRetryTimes = 0;
  13077. }
  13078. void handleBootNotificationResponse(char *payload, int gun_index)
  13079. {
  13080. mtrace();
  13081. char statusStr[12]={0};
  13082. char currentTimeStr[30]={0};
  13083. int intervalInt = 0;
  13084. DEBUG_INFO("handleBootNotificationResponse...\n");
  13085. json_object *BootNotification;
  13086. BootNotification = json_tokener_parse(payload);
  13087. if(!is_error(BootNotification))
  13088. {
  13089. // Required data
  13090. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13091. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13092. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13093. }
  13094. json_object_put(BootNotification);
  13095. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13096. BootNotificationInterval = intervalInt;
  13097. //write back to ShmOCPP16Data->BootNotification
  13098. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  13099. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13100. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  13101. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13102. {
  13103. if((intervalInt == 0) || (intervalInt >= 10))
  13104. {
  13105. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13106. HeartBeatWaitTime = intervalInt;
  13107. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13108. }
  13109. server_sign = TRUE;
  13110. server_pending =FALSE;
  13111. }
  13112. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13113. {
  13114. server_pending = TRUE;
  13115. }
  13116. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  13117. srand(time(NULL));
  13118. refreshStartTimer(&clientTime.Heartbeat);
  13119. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13120. SetOcppConnStatus(TRUE);
  13121. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  13122. }
  13123. void handleDataTransferResponse(char *payload, int gun_index)
  13124. {
  13125. char sstr[160]={0};//sstr[200]={ 0 };
  13126. int c = 0;
  13127. char *loc;
  13128. DEBUG_INFO("handleDataTransferResponse ...\n");
  13129. loc = strstr(payload, "status");
  13130. c = 0;
  13131. while (loc[3+strlen("status")+c] != '\"')
  13132. {
  13133. sstr[c] = loc[3+strlen("status")+c];
  13134. c++;
  13135. }
  13136. sstr[c] = '\0';
  13137. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  13138. }
  13139. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13140. {
  13141. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13142. //struct json_object *obj;
  13143. // obj = json_tokener_parse(payload);
  13144. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13145. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13146. //No fields are defined.
  13147. }
  13148. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13149. {
  13150. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13151. //struct json_object *obj;
  13152. // obj = json_tokener_parse(payload);
  13153. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13154. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13155. //No fields are defined.
  13156. }
  13157. void handleHeartbeatResponse(char *payload, int gun_index)
  13158. {
  13159. mtrace();
  13160. DEBUG_INFO("handleHeartbeatResponse...\n");
  13161. json_object *Heartbeat;
  13162. Heartbeat = json_tokener_parse(payload);
  13163. if(!is_error(Heartbeat))
  13164. {
  13165. // Required data
  13166. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13167. }
  13168. json_object_put(Heartbeat);
  13169. if(FirstHeartBeat == 0)
  13170. {
  13171. FirstHeartBeat = 1;
  13172. DEBUG_INFO("FirstHeartBeat \n");
  13173. }
  13174. HeartBeatWithNOResponse = 0;
  13175. refreshStartTimer(&clientTime.Heartbeat);
  13176. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  13177. }
  13178. void handleMeterValuesResponse(char *payload, int gun_index)
  13179. {
  13180. mtrace();
  13181. DEBUG_INFO("handleMeterValuesResponse...\n");
  13182. isQueueSendable = 1;
  13183. }
  13184. void handleStartTransactionResponse(char *payload, int gun_index)
  13185. {
  13186. mtrace();
  13187. //int transactionIdInt = 0;
  13188. FILE *outfile;
  13189. char data[100]={0};
  13190. DEBUG_INFO("handleStartTransactionResponse...\n");
  13191. json_object *StartTransaction;
  13192. StartTransaction = json_tokener_parse(payload);
  13193. if(!is_error(StartTransaction))
  13194. {
  13195. // Required data
  13196. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13197. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13198. // Optional data
  13199. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13200. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13201. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13202. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13203. }
  13204. json_object_put(StartTransaction);
  13205. isQueueSendable = 1;
  13206. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13207. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13208. //-----------Start : write to the Queue TransactionId file -----------------//
  13209. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  13210. {}
  13211. else
  13212. {
  13213. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  13214. if(log == NULL)
  13215. {
  13216. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13217. return ;
  13218. }
  13219. else
  13220. {
  13221. fclose(log);
  13222. }
  13223. }
  13224. // open file for writing
  13225. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13226. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  13227. {
  13228. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  13229. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13230. fputs(data, outfile);
  13231. fclose (outfile);
  13232. }
  13233. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13234. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13235. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13236. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  13237. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13238. }
  13239. void handleStatusNotificationResponse(char *payload, int gun_index)
  13240. {
  13241. mtrace();
  13242. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13243. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13244. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13245. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13246. }
  13247. void handleStopTransactionnResponse(char *payload, int gun_index)
  13248. {
  13249. mtrace();
  13250. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13251. json_object *StopTransaction;
  13252. StopTransaction = json_tokener_parse(payload);
  13253. if(!is_error(StopTransaction))
  13254. {
  13255. // Optional data
  13256. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13257. {
  13258. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13259. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13260. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13261. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13262. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13263. }
  13264. }
  13265. json_object_put(StopTransaction);
  13266. isQueueSendable = 1;
  13267. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13268. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13269. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13270. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13271. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13272. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13273. }
  13274. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13275. {
  13276. mtrace();
  13277. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13278. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  13279. }
  13280. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13281. {
  13282. mtrace();
  13283. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13284. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  13285. }
  13286. void handleSignCertificateResponse(char *payload, int gun_index)
  13287. {
  13288. mtrace();
  13289. DEBUG_INFO("handleSignCertificateResponse...\n");
  13290. json_object *SignCertificate;
  13291. SignCertificate = json_tokener_parse(payload);
  13292. if(!is_error(SignCertificate))
  13293. {
  13294. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13295. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  13296. }
  13297. json_object_put(SignCertificate);
  13298. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  13299. }
  13300. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13301. {
  13302. mtrace();
  13303. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13304. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13305. }
  13306. //==========================================
  13307. // Handle Error routine
  13308. //==========================================
  13309. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13310. {
  13311. mtrace();
  13312. #ifdef SystemLogMessage
  13313. DEBUG_INFO("errorCode: %s\n", errorCode);
  13314. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13315. DEBUG_INFO("errorDetails: %s\n", payload);
  13316. #endif
  13317. }
  13318. //===============================================
  13319. // Common routine
  13320. //===============================================
  13321. int initialConfigurationTable(void)
  13322. {
  13323. //clock_t start_t, end_t, total_t;
  13324. FILE *fp;
  13325. FILE *outfile;
  13326. char str[512]={0};
  13327. char sstr[256]={0};
  13328. int c = 0;
  13329. char *loc;
  13330. int confVersion = 11;
  13331. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13332. //start_t = clock();
  13333. //printf("Starting of the program, start_t = %ld\n", start_t);
  13334. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13335. // Check configuration file size is correct
  13336. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  13337. {
  13338. struct stat st;
  13339. stat("/Storage/OCPP/OCPPConfiguration", &st);
  13340. if(st.st_size < 3100)
  13341. {
  13342. system("rm -f /Storage/OCPP/OCPPConfiguration");
  13343. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13344. }
  13345. }
  13346. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  13347. {
  13348. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13349. if(outfile == NULL)
  13350. {
  13351. DEBUG_INFO("Error opening file\n");
  13352. return FALSE;
  13353. }
  13354. /*Core Profile*/
  13355. //AllowOfflineTxForUnknownId
  13356. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13360. //AuthorizationCacheEnabled
  13361. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13364. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13365. //AuthorizeRemoteTxRequests
  13366. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13368. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13370. //BlinkRepeat
  13371. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13375. //ClockAlignedDataInterval
  13376. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13379. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13380. //ConnectionTimeOut
  13381. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13384. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13385. //GetConfigurationMaxKeys
  13386. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13388. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13389. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13390. // HeartbeatInterval
  13391. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13395. // LightIntensity
  13396. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13399. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13400. // LocalAuthorizeOffline
  13401. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13403. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13404. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13405. // LocalPreAuthorize
  13406. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13409. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13410. // MaxEnergyOnInvalidId
  13411. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13413. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13414. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13415. // MeterValuesAlignedData
  13416. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13417. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13418. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13419. 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" );
  13420. else
  13421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13422. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13423. // MeterValuesAlignedDataMaxLength
  13424. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13426. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13428. else
  13429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13430. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13431. // MeterValuesSampledData
  13432. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13434. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13435. 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" );
  13436. else
  13437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13438. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13439. // MeterValuesSampledDataMaxLength
  13440. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13442. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13444. else
  13445. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13446. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13447. // MeterValueSampleInterval
  13448. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13450. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13451. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13452. // MinimumStatusDuration
  13453. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13456. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13457. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13458. // NumberOfConnectors
  13459. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13460. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13461. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13462. {
  13463. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13464. }
  13465. else
  13466. {
  13467. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13468. }
  13469. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13470. // ResetRetries
  13471. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13474. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13475. // ConnectorPhaseRotation
  13476. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13477. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13479. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13480. // ConnectorPhaseRotationMaxLength
  13481. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13484. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13485. // StopTransactionOnEVSideDisconnect
  13486. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13488. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13489. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13490. // StopTransactionOnInvalidId
  13491. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13492. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13493. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13494. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13495. // StopTxnAlignedData
  13496. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13498. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13499. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13500. // StopTxnAlignedDataMaxLength
  13501. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13504. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13505. // StopTxnSampledData
  13506. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13508. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13510. else
  13511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13512. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13513. // StopTxnSampledDataMaxLength
  13514. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13515. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13516. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13517. {
  13518. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13519. }
  13520. else
  13521. {
  13522. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13523. }
  13524. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13525. // SupportedFeatureProfiles
  13526. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13529. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13530. // SupportedFeatureProfilesMaxLength
  13531. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13534. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13535. // TransactionMessageAttempts
  13536. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13537. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13538. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13539. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13540. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13541. // TransactionMessageRetryInterval
  13542. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13543. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13544. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13545. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13546. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13547. // UnlockConnectorOnEVSideDisconnect
  13548. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13551. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13552. // WebSocketPingInterval
  13553. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13556. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13557. // QueueOffLineMeterValues
  13558. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13561. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13562. // AuthorizationKey
  13563. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13564. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13565. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  13566. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13567. // SecurityProfile
  13568. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13570. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  13571. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13572. // DefaultPrice
  13573. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13576. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13577. // CustomDisplayCostAndPrice
  13578. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13580. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13581. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13582. // CustomIdleFeeAfterStop
  13583. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13586. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13587. // TimeOffset
  13588. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  13591. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13592. // NextTimeOffsetTransitionDateTime
  13593. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  13596. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13597. // TimeOffsetNextTransition
  13598. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13600. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  13601. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13602. // SystemUptimeSec
  13603. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13606. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13607. // FreeVend
  13608. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "Free-FreeVend");
  13610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13611. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13612. // OcppServer
  13613. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13615. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13616. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13617. // MaintainServer
  13618. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13620. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13621. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13622. // Configuration Version
  13623. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13625. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13626. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13627. //* Local Auth List Management Profile*/
  13628. #if 0
  13629. //For OCTT Test Case
  13630. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13633. #endif
  13634. #if 1
  13635. //LocalAuthListEnabled
  13636. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13639. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13640. #endif
  13641. //LocalAuthListMaxLength
  13642. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  13645. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13646. //SendLocalListMaxLength
  13647. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13650. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13651. //ReserveConnectorZeroSupported
  13652. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13655. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13656. //* Smart Charging Profile */
  13657. //ChargeProfileMaxStackLevel
  13658. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13661. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13662. // ChargingScheduleAllowedChargingRateUnit
  13663. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13664. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13666. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13667. // ChargingScheduleMaxPeriods
  13668. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13671. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13672. // ConnectorSwitch3to1PhaseSupported
  13673. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13676. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13677. // MaxChargingProfilesInstalled
  13678. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13681. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13682. fclose(outfile);
  13683. }
  13684. else
  13685. {
  13686. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  13687. char keystr[60]={0};
  13688. char readonlystr[10]={0};
  13689. char valuestr[256]={0};
  13690. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  13691. if(fp == NULL) {
  13692. DEBUG_INFO("Error opening file");
  13693. return FALSE;
  13694. }
  13695. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13696. {
  13697. //DEBUG_INFO("Get Configuration \n");
  13698. if(strlen(str) > 0)
  13699. {
  13700. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13701. //*************************key*********************************/
  13702. if(strstr(str, "key") != NULL)
  13703. {
  13704. loc = strstr(str, "key");
  13705. c = 0;
  13706. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13707. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13708. {
  13709. sstr[c] = loc[strlen("key")+3+c];
  13710. c++;
  13711. }
  13712. sstr[c] = '\0';
  13713. strcpy(keystr,sstr);
  13714. }
  13715. //*************************readonly*********************************/
  13716. if(strstr(str, "readonly") != NULL)
  13717. {
  13718. loc = strstr(str, "readonly");
  13719. c = 0;
  13720. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13721. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13722. {
  13723. sstr[c] = loc[strlen("readonly")+2+c];
  13724. c++;
  13725. }
  13726. sstr[c] = '\0';
  13727. strcpy(readonlystr,sstr);
  13728. }
  13729. //*************************value*********************************/
  13730. if(strstr(str, "value") != NULL)
  13731. {
  13732. loc = strstr(str, "value");
  13733. c = 0;
  13734. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13735. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13736. {
  13737. sstr[c] = loc[strlen("value")+3+c];
  13738. c++;
  13739. }
  13740. sstr[c] = '\0';
  13741. strcpy(valuestr,sstr);
  13742. }
  13743. // DEBUG_INFO("keystr=%s\n",keystr);
  13744. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13745. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13746. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13747. {
  13748. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13749. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13750. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13751. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13752. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13753. }
  13754. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13755. {
  13756. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13757. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13758. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13759. }
  13760. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13761. {
  13762. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13763. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13764. }
  13765. if(strcmp(keystr, "BlinkRepeat") == 0)
  13766. {
  13767. //Charger.BlinkRepeat = Integer.parseInt(value);
  13768. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13769. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13770. }
  13771. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13772. {
  13773. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13774. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13775. }
  13776. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13777. {
  13778. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13779. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13780. }
  13781. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13782. {
  13783. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13784. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13785. }
  13786. if(strcmp(keystr, "HeartbeatInterval") == 0)
  13787. {
  13788. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13789. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  13790. HeartBeatWaitTime = atoi(valuestr);
  13791. }
  13792. if(strcmp(keystr, "LightIntensity") == 0)
  13793. {
  13794. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13795. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  13796. }
  13797. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  13798. {
  13799. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13800. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  13801. }
  13802. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  13803. {
  13804. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13805. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  13806. }
  13807. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  13808. {
  13809. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13810. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  13811. }
  13812. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  13813. {
  13814. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13815. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  13816. }
  13817. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  13818. {
  13819. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13820. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  13821. }
  13822. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  13823. {
  13824. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13825. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  13826. }
  13827. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  13828. {
  13829. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  13831. }
  13832. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  13833. {
  13834. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13835. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  13836. }
  13837. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  13838. {
  13839. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13840. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  13841. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  13842. }
  13843. if(strcmp(keystr, "NumberOfConnectors") == 0)
  13844. {
  13845. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13846. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  13847. }
  13848. if(strcmp(keystr, "ResetRetries") == 0)
  13849. {
  13850. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13851. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  13852. }
  13853. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  13854. {
  13855. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13856. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  13857. }
  13858. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  13859. {
  13860. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13861. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  13862. }
  13863. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  13864. {
  13865. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13866. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  13867. }
  13868. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  13869. {
  13870. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13871. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  13872. }
  13873. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  13874. {
  13875. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13876. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  13877. }
  13878. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  13879. {
  13880. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13881. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13882. }
  13883. if(strcmp(keystr, "StopTxnSampledData") == 0)
  13884. {
  13885. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13886. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  13887. }
  13888. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  13889. {
  13890. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13891. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13892. }
  13893. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  13894. {
  13895. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13896. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  13897. }
  13898. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  13899. {
  13900. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13901. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  13902. }
  13903. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  13904. {
  13905. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13906. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  13907. TransactionMessageAttemptsValue = atoi(valuestr);
  13908. }
  13909. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  13910. {
  13911. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13912. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  13913. TransactionMessageRetryIntervalValue = atoi(valuestr);
  13914. }
  13915. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  13916. {
  13917. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13918. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  13919. }
  13920. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  13921. {
  13922. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13923. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  13924. }
  13925. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  13926. {
  13927. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13928. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  13929. }
  13930. if(strcmp(keystr, "AuthorizationKey") == 0)
  13931. {
  13932. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13933. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  13934. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  13935. }
  13936. if(strcmp(keystr, "SecurityProfile") == 0)
  13937. {
  13938. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13939. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  13940. }
  13941. if(strcmp(keystr, "DefaultPrice") == 0)
  13942. {
  13943. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13944. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  13945. }
  13946. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  13947. {
  13948. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13949. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  13950. }
  13951. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  13952. {
  13953. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13954. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  13955. }
  13956. if(strcmp(keystr, "TimeOffset") == 0)
  13957. {
  13958. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13959. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  13960. }
  13961. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  13962. {
  13963. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13964. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  13965. }
  13966. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  13967. {
  13968. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13969. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  13970. }
  13971. if(strcmp(keystr, "SystemUptimeSec") == 0)
  13972. {
  13973. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13974. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  13975. }
  13976. if(strcmp(keystr, "FreeVend") == 0)
  13977. {
  13978. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13979. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  13980. }
  13981. if(strcmp(keystr, "OcppServer") == 0)
  13982. {
  13983. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13984. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13985. }
  13986. if(strcmp(keystr, "MaintainServer") == 0)
  13987. {
  13988. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13989. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  13990. }
  13991. if(strcmp(keystr, "ConfigurationVersion") == 0)
  13992. {
  13993. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13994. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  13995. }
  13996. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  13997. {
  13998. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13999. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14000. }
  14001. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14002. {
  14003. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14004. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14005. }
  14006. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14007. {
  14008. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14009. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14010. }
  14011. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14012. {
  14013. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14014. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14015. }
  14016. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14017. {
  14018. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14019. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14020. }
  14021. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14022. {
  14023. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14024. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14025. }
  14026. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14027. {
  14028. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14029. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14030. }
  14031. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14032. {
  14033. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14034. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14035. }
  14036. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14037. {
  14038. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14039. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14040. }
  14041. }
  14042. }
  14043. fclose(fp);
  14044. }
  14045. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14046. {
  14047. return PASS;
  14048. }
  14049. else
  14050. {
  14051. return FAIL;
  14052. }
  14053. }
  14054. void StoreConfigurationTable(void)
  14055. {
  14056. FILE *outfile;
  14057. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14058. if(outfile == NULL)
  14059. {
  14060. DEBUG_INFO("Error opening file");
  14061. return ;
  14062. }
  14063. /*Core Profile*/
  14064. //AllowOfflineTxForUnknownId
  14065. /*
  14066. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14067. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14070. */
  14071. //DEBUG_INFO("data=%s\n",data);
  14072. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14073. //AuthorizationCacheEnabled
  14074. /*
  14075. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14078. */
  14079. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14080. //AuthorizeRemoteTxRequests
  14081. /*
  14082. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14085. */
  14086. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14087. //BlinkRepeat
  14088. /*
  14089. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14092. */
  14093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14094. //ClockAlignedDataInterval
  14095. /*
  14096. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14099. */
  14100. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14101. //ConnectionTimeOut
  14102. /*
  14103. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14106. */
  14107. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14108. //GetConfigurationMaxKeys
  14109. /*
  14110. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14113. */
  14114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14115. // HeartbeatInterval
  14116. /*
  14117. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14120. */
  14121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14122. // LightIntensity
  14123. /*
  14124. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14127. */
  14128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14129. // LocalAuthorizeOffline
  14130. /*
  14131. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14134. */
  14135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14136. // LocalPreAuthorize
  14137. /*
  14138. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14141. */
  14142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14143. // MaxEnergyOnInvalidId
  14144. /*
  14145. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14148. */
  14149. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14150. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14151. // MeterValuesAlignedData
  14152. /*
  14153. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14156. */
  14157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14158. // MeterValuesAlignedDataMaxLength
  14159. /*
  14160. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14163. */
  14164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14165. // MeterValuesSampledData
  14166. /*
  14167. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14170. */
  14171. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14172. // MeterValuesSampledDataMaxLength
  14173. /*
  14174. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14177. */
  14178. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14179. // MeterValueSampleInterval
  14180. /*
  14181. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14184. */
  14185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14186. // MinimumStatusDuration
  14187. /*
  14188. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14191. */
  14192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14193. // NumberOfConnectors
  14194. /*
  14195. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14197. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14198. {
  14199. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14200. }
  14201. else
  14202. {
  14203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14204. }
  14205. */
  14206. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14207. // ResetRetries
  14208. /*
  14209. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14211. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14212. */
  14213. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14214. // ConnectorPhaseRotation
  14215. /*
  14216. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14219. */
  14220. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14221. // ConnectorPhaseRotationMaxLength
  14222. /*
  14223. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14226. */
  14227. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14228. // StopTransactionOnEVSideDisconnect
  14229. /*
  14230. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14233. */
  14234. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14235. // StopTransactionOnInvalidId
  14236. /*
  14237. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14240. */
  14241. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14242. // StopTxnAlignedData
  14243. /*
  14244. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14247. */
  14248. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14249. // StopTxnAlignedDataMaxLength
  14250. /*
  14251. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14254. */
  14255. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14256. // StopTxnSampledData
  14257. /*
  14258. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14261. */
  14262. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14263. // StopTxnSampledDataMaxLength
  14264. /*
  14265. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14268. */
  14269. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14270. // SupportedFeatureProfiles
  14271. /*
  14272. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14274. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14275. */
  14276. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14277. // SupportedFeatureProfilesMaxLength
  14278. /*
  14279. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14282. */
  14283. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14284. // TransactionMessageAttempts
  14285. /*
  14286. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14289. */
  14290. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14291. // TransactionMessageRetryInterval
  14292. /*
  14293. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14296. */
  14297. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14298. // UnlockConnectorOnEVSideDisconnect
  14299. /*
  14300. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14303. */
  14304. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14305. // WebSocketPingInterval
  14306. /*
  14307. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14308. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14310. */
  14311. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14312. // QueueOffLineMeterValues
  14313. /*
  14314. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14317. */
  14318. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14319. // AuthorizationKey
  14320. /*
  14321. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14324. */
  14325. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14326. // SecurityProfile
  14327. /*
  14328. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14331. */
  14332. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14333. // DefaultPrice
  14334. /*
  14335. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14337. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14338. */
  14339. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14340. // CustomDisplayCostAndPrice
  14341. /*
  14342. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14345. */
  14346. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14347. // CustomIdleFeeAfterStop
  14348. /*
  14349. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14351. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14352. */
  14353. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14354. // TimeOffset
  14355. /*
  14356. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  14359. */
  14360. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14361. // NextTimeOffsetTransitionDateTime
  14362. /*
  14363. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  14366. */
  14367. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14368. // TimeOffsetNextTransition
  14369. /*
  14370. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  14373. */
  14374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14375. // SystemUptimeSec
  14376. /*
  14377. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14380. */
  14381. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14382. // FreeVend
  14383. /*
  14384. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14387. */
  14388. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14389. // OcppServer
  14390. /*
  14391. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14394. */
  14395. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14396. // MaintainServer
  14397. /*
  14398. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14401. */
  14402. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14403. // ConfigurationVersion
  14404. /*
  14405. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14408. */
  14409. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14410. //* Local Auth List Management Profile*/
  14411. //LocalAuthListEnabled
  14412. /*
  14413. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14416. */
  14417. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14418. //LocalAuthListMaxLength
  14419. /*
  14420. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14423. */
  14424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14425. //SendLocalListMaxLength
  14426. /*
  14427. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14428. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14430. */
  14431. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14432. //ReserveConnectorZeroSupported
  14433. /*
  14434. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14436. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14437. */
  14438. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14439. //* Smart Charging Profile */
  14440. //ChargeProfileMaxStackLevel
  14441. /*
  14442. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14445. */
  14446. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14447. // ChargingScheduleAllowedChargingRateUnit
  14448. /*
  14449. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14450. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14451. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14452. */
  14453. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14454. // ChargingScheduleMaxPeriods
  14455. /*
  14456. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14457. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14459. */
  14460. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14461. // ConnectorSwitch3to1PhaseSupported
  14462. /*
  14463. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14464. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14465. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14466. */
  14467. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14468. // MaxChargingProfilesInstalled
  14469. /*
  14470. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14471. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14473. */
  14474. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14475. fclose(outfile);
  14476. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14477. }
  14478. void getKeyValue(char *keyReq)
  14479. {
  14480. int isEmpty = FALSE;
  14481. int isKnowKey = FALSE;
  14482. DEBUG_INFO("keyReq = %s\n", keyReq);
  14483. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14484. isEmpty = TRUE;
  14485. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14486. {
  14487. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14489. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14490. {
  14491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14492. }
  14493. else
  14494. {
  14495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14496. }
  14497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14498. isKnowKey = TRUE;
  14499. }
  14500. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14501. {
  14502. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14504. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14505. {
  14506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14507. }
  14508. else
  14509. {
  14510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14511. }
  14512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14513. isKnowKey = TRUE;
  14514. }
  14515. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14516. {
  14517. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14519. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14520. {
  14521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14522. }
  14523. else
  14524. {
  14525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14526. }
  14527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14528. isKnowKey = TRUE;
  14529. }
  14530. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14531. {
  14532. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14534. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14535. {
  14536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14537. }
  14538. else
  14539. {
  14540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14541. }
  14542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14543. isKnowKey = TRUE;
  14544. }
  14545. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14546. {
  14547. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14549. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14550. {
  14551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14552. }
  14553. else
  14554. {
  14555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14556. }
  14557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14558. isKnowKey = TRUE;
  14559. }
  14560. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14561. {
  14562. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14564. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14565. {
  14566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14567. }
  14568. else
  14569. {
  14570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14571. }
  14572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14573. isKnowKey = TRUE;
  14574. }
  14575. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14576. {
  14577. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14579. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14580. {
  14581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14582. }
  14583. else
  14584. {
  14585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14586. }
  14587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14588. isKnowKey = TRUE;
  14589. }
  14590. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14591. {
  14592. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14594. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14595. {
  14596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14597. }
  14598. else
  14599. {
  14600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14601. }
  14602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14603. isKnowKey = TRUE;
  14604. }
  14605. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14606. {
  14607. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14609. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14610. {
  14611. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14612. }
  14613. else
  14614. {
  14615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14616. }
  14617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14618. isKnowKey = TRUE;
  14619. }
  14620. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14621. {
  14622. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14624. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14625. {
  14626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14627. }
  14628. else
  14629. {
  14630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14631. }
  14632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14633. isKnowKey = TRUE;
  14634. }
  14635. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14636. {
  14637. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14639. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14640. {
  14641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14642. }
  14643. else
  14644. {
  14645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14646. }
  14647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14648. isKnowKey = TRUE;
  14649. }
  14650. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14651. {
  14652. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14654. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14655. {
  14656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14657. }
  14658. else
  14659. {
  14660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14661. }
  14662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14663. isKnowKey = TRUE;
  14664. }
  14665. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14666. {
  14667. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14669. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14670. {
  14671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14672. }
  14673. else
  14674. {
  14675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14676. }
  14677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14678. isKnowKey = TRUE;
  14679. }
  14680. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14681. {
  14682. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14684. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14685. {
  14686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14687. }
  14688. else
  14689. {
  14690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14691. }
  14692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14693. isKnowKey = TRUE;
  14694. }
  14695. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14696. {
  14697. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14699. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14700. {
  14701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14702. }
  14703. else
  14704. {
  14705. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14706. }
  14707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14708. isKnowKey = TRUE;
  14709. }
  14710. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14711. {
  14712. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14714. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14715. {
  14716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14717. }
  14718. else
  14719. {
  14720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14721. }
  14722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14723. isKnowKey = TRUE;
  14724. }
  14725. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14726. {
  14727. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14729. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14730. {
  14731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14732. }
  14733. else
  14734. {
  14735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14736. }
  14737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14738. isKnowKey = TRUE;
  14739. }
  14740. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14741. {
  14742. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14744. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14745. {
  14746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14747. }
  14748. else
  14749. {
  14750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14751. }
  14752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  14753. isKnowKey = TRUE;
  14754. }
  14755. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14756. {
  14757. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14759. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14760. {
  14761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14762. }
  14763. else
  14764. {
  14765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14766. }
  14767. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  14768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  14769. isKnowKey = TRUE;
  14770. }
  14771. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  14772. {
  14773. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  14774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  14775. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14776. {
  14777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  14778. }
  14779. else
  14780. {
  14781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  14782. }
  14783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  14784. isKnowKey = TRUE;
  14785. }
  14786. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  14787. {
  14788. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  14789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  14790. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14791. {
  14792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  14793. }
  14794. else
  14795. {
  14796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  14797. }
  14798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  14799. isKnowKey = TRUE;
  14800. }
  14801. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  14802. {
  14803. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  14804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  14805. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14806. {
  14807. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14808. }
  14809. else
  14810. {
  14811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14812. }
  14813. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  14814. isKnowKey = TRUE;
  14815. }
  14816. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  14817. {
  14818. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  14819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  14820. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14821. {
  14822. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14823. }
  14824. else
  14825. {
  14826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14827. }
  14828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  14829. isKnowKey = TRUE;
  14830. }
  14831. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  14832. {
  14833. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  14834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  14835. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14836. {
  14837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14838. }
  14839. else
  14840. {
  14841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14842. }
  14843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  14844. isKnowKey = TRUE;
  14845. }
  14846. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  14847. {
  14848. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  14849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  14850. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14851. {
  14852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14853. }
  14854. else
  14855. {
  14856. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14857. }
  14858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  14859. isKnowKey = TRUE;
  14860. }
  14861. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  14862. {
  14863. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  14864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  14865. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14866. {
  14867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14868. }
  14869. else
  14870. {
  14871. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14872. }
  14873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  14874. isKnowKey = TRUE;
  14875. }
  14876. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  14877. {
  14878. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  14879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  14880. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14881. {
  14882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  14883. }
  14884. else
  14885. {
  14886. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  14887. }
  14888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  14889. isKnowKey = TRUE;
  14890. }
  14891. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  14892. {
  14893. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  14894. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  14895. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14896. {
  14897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14898. }
  14899. else
  14900. {
  14901. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14902. }
  14903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  14904. isKnowKey = TRUE;
  14905. }
  14906. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  14907. {
  14908. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  14909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  14910. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14911. {
  14912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  14913. }
  14914. else
  14915. {
  14916. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  14917. }
  14918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  14919. isKnowKey = TRUE;
  14920. }
  14921. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  14922. {
  14923. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  14924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  14925. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14926. {
  14927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14928. }
  14929. else
  14930. {
  14931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14932. }
  14933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  14934. isKnowKey = TRUE;
  14935. }
  14936. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  14937. {
  14938. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  14939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  14940. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14941. {
  14942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  14943. }
  14944. else
  14945. {
  14946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  14947. }
  14948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  14949. isKnowKey = TRUE;
  14950. }
  14951. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  14952. {
  14953. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  14954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  14955. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14956. {
  14957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  14958. }
  14959. else
  14960. {
  14961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  14962. }
  14963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  14964. isKnowKey = TRUE;
  14965. }
  14966. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  14967. {
  14968. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  14969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  14970. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14971. {
  14972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14973. }
  14974. else
  14975. {
  14976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14977. }
  14978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  14979. isKnowKey = TRUE;
  14980. }
  14981. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  14982. {
  14983. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  14984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  14985. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14986. {
  14987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  14988. }
  14989. else
  14990. {
  14991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  14992. }
  14993. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  14994. isKnowKey = TRUE;
  14995. }
  14996. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  14997. {
  14998. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  14999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15000. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15001. {
  15002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15003. }
  15004. else
  15005. {
  15006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15007. }
  15008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15009. isKnowKey = TRUE;
  15010. }
  15011. /*
  15012. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15013. {
  15014. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15016. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15017. {
  15018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15019. }
  15020. else
  15021. {
  15022. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15023. }
  15024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15025. isKnowKey = TRUE;
  15026. }*/
  15027. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15028. {
  15029. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15031. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15032. {
  15033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15034. }
  15035. else
  15036. {
  15037. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15038. }
  15039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15040. isKnowKey = TRUE;
  15041. }
  15042. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15043. {
  15044. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15046. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15047. {
  15048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15049. }
  15050. else
  15051. {
  15052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15053. }
  15054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15055. isKnowKey = TRUE;
  15056. }
  15057. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15058. {
  15059. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15061. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15062. {
  15063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15064. }
  15065. else
  15066. {
  15067. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15068. }
  15069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15070. isKnowKey = TRUE;
  15071. }
  15072. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15073. {
  15074. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15075. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15076. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15077. {
  15078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15079. }
  15080. else
  15081. {
  15082. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15083. }
  15084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15085. isKnowKey = TRUE;
  15086. }
  15087. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  15088. {
  15089. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  15090. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  15091. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15092. {
  15093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  15094. }
  15095. else
  15096. {
  15097. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  15098. }
  15099. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  15100. isKnowKey = TRUE;
  15101. }
  15102. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  15103. {
  15104. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  15105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  15106. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15107. {
  15108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  15109. }
  15110. else
  15111. {
  15112. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  15113. }
  15114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  15115. isKnowKey = TRUE;
  15116. }
  15117. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  15118. {
  15119. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  15120. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  15121. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15122. {
  15123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  15124. }
  15125. else
  15126. {
  15127. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  15128. }
  15129. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  15130. isKnowKey = TRUE;
  15131. }
  15132. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15133. {
  15134. struct sysinfo s_info;
  15135. int error = sysinfo(&s_info);
  15136. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15138. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15139. {
  15140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15141. }
  15142. else
  15143. {
  15144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15145. }
  15146. if(error != 0)
  15147. {
  15148. DEBUG_WARN("System uptime get error: %d\n", error);
  15149. }
  15150. else
  15151. {
  15152. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15153. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15154. }
  15155. isKnowKey = TRUE;
  15156. }
  15157. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15158. {
  15159. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15161. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15162. {
  15163. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15164. }
  15165. else
  15166. {
  15167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15168. }
  15169. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  15170. isKnowKey = TRUE;
  15171. }
  15172. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15173. {
  15174. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15176. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15177. {
  15178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15179. }
  15180. else
  15181. {
  15182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15183. }
  15184. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15185. isKnowKey = TRUE;
  15186. }
  15187. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15188. {
  15189. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15191. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15192. {
  15193. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15194. }
  15195. else
  15196. {
  15197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15198. }
  15199. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15200. isKnowKey = TRUE;
  15201. }
  15202. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15203. {
  15204. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15206. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15207. {
  15208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15209. }
  15210. else
  15211. {
  15212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15213. }
  15214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15215. isKnowKey = TRUE;
  15216. }
  15217. #if 1
  15218. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15219. {
  15220. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15222. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15223. {
  15224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15225. }
  15226. else
  15227. {
  15228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15229. }
  15230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15231. isKnowKey = TRUE;
  15232. }
  15233. #endif
  15234. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15235. {
  15236. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15238. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15239. {
  15240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15241. }
  15242. else
  15243. {
  15244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15245. }
  15246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15247. isKnowKey = TRUE;
  15248. }
  15249. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15250. {
  15251. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15253. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15254. {
  15255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15256. }
  15257. else
  15258. {
  15259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15260. }
  15261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15262. isKnowKey = TRUE;
  15263. }
  15264. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15265. {
  15266. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15268. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15269. {
  15270. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15271. }
  15272. else
  15273. {
  15274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15275. }
  15276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15277. isKnowKey = TRUE;
  15278. }
  15279. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15280. {
  15281. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15283. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15284. {
  15285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15286. }
  15287. else
  15288. {
  15289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15290. }
  15291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15292. isKnowKey = TRUE;
  15293. }
  15294. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15295. {
  15296. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15298. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15299. {
  15300. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15301. }
  15302. else
  15303. {
  15304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15305. }
  15306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15307. isKnowKey = TRUE;
  15308. }
  15309. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15310. {
  15311. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15313. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15314. {
  15315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15316. }
  15317. else
  15318. {
  15319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15320. }
  15321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15322. isKnowKey = TRUE;
  15323. }
  15324. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15325. {
  15326. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15328. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15329. {
  15330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15331. }
  15332. else
  15333. {
  15334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15335. }
  15336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15337. isKnowKey = TRUE;
  15338. }
  15339. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15340. {
  15341. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15343. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15344. {
  15345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15346. }
  15347. else
  15348. {
  15349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15350. }
  15351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15352. isKnowKey = TRUE;
  15353. }
  15354. //=========================================================
  15355. if(!isEmpty && !isKnowKey)
  15356. {
  15357. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15358. strcpy(unknownkey[UnknownKeynum], keyReq);
  15359. UnknownKeynum = UnknownKeynum + 1;
  15360. }
  15361. }
  15362. void processUnkownKey(void)
  15363. {
  15364. DEBUG_INFO("processUnkownKey...\n");
  15365. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15366. for(int index=0; index < UnknownKeynum; index++)
  15367. {
  15368. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15369. {
  15370. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15371. }
  15372. }
  15373. }
  15374. int setKeyValue(char *key, char *value)
  15375. {
  15376. int isSuccess = NotSupported;
  15377. int check_ascii=0;
  15378. char str[501]={0};
  15379. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15380. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15381. {
  15382. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15383. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15384. {
  15385. strcpy(str, (const char*)value);
  15386. for(int i = 0; str[i]; i++){
  15387. str[i] = tolower(str[i]);
  15388. }
  15389. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15390. isSuccess = ConfigurationStatus_Accepted;
  15391. }
  15392. else
  15393. {
  15394. isSuccess = ConfigurationStatus_Rejected;
  15395. }
  15396. }
  15397. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15398. {
  15399. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15400. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15401. {
  15402. strcpy(str, (const char*)value);
  15403. for(int i = 0; str[i]; i++){
  15404. str[i] = tolower(str[i]);
  15405. }
  15406. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15407. isSuccess = ConfigurationStatus_Accepted;
  15408. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  15409. }
  15410. else
  15411. {
  15412. isSuccess = ConfigurationStatus_Rejected;
  15413. }
  15414. }
  15415. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15416. {
  15417. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15418. {
  15419. strcpy(str, (const char*)value);
  15420. for(int i = 0; str[i]; i++)
  15421. {
  15422. str[i] = tolower(str[i]);
  15423. }
  15424. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15425. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15426. isSuccess = ConfigurationStatus_Accepted;
  15427. }
  15428. else
  15429. {
  15430. isSuccess = ConfigurationStatus_Rejected;
  15431. }
  15432. }
  15433. if(strcmp(key, "BlinkRepeat") == 0)
  15434. {
  15435. //Charger.BlinkRepeat = Integer.parseInt(value);
  15436. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15437. {
  15438. check_ascii = value[0];
  15439. if( (check_ascii < 48) || (check_ascii > 57) )
  15440. {
  15441. isSuccess = ConfigurationStatus_Rejected;
  15442. }
  15443. else
  15444. {
  15445. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15446. isSuccess = ConfigurationStatus_Accepted;
  15447. }
  15448. }
  15449. else
  15450. {
  15451. isSuccess = ConfigurationStatus_Rejected;
  15452. }
  15453. }
  15454. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15455. {
  15456. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15457. {
  15458. check_ascii = value[0];
  15459. if( (check_ascii < 48) || (check_ascii > 57) )
  15460. {
  15461. isSuccess = ConfigurationStatus_Rejected;
  15462. }
  15463. else
  15464. {
  15465. if((atoi(value) == 0) || (atoi(value) >= 5))
  15466. {
  15467. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15468. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15469. isSuccess = ConfigurationStatus_Accepted;
  15470. }
  15471. else
  15472. isSuccess = ConfigurationStatus_Rejected;
  15473. }
  15474. }
  15475. else
  15476. {
  15477. isSuccess = ConfigurationStatus_Rejected;
  15478. }
  15479. }
  15480. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15481. {
  15482. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15483. {
  15484. check_ascii = value[0];
  15485. if( (check_ascii < 48) || (check_ascii > 57) )
  15486. {
  15487. isSuccess = ConfigurationStatus_Rejected;
  15488. }
  15489. else
  15490. {
  15491. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15492. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15493. isSuccess = ConfigurationStatus_Accepted;
  15494. }
  15495. }
  15496. else
  15497. {
  15498. isSuccess = ConfigurationStatus_Rejected;
  15499. }
  15500. }
  15501. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15502. {
  15503. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15504. {
  15505. check_ascii = value[0];
  15506. if( (check_ascii < 48) || (check_ascii > 57) )
  15507. {
  15508. isSuccess = ConfigurationStatus_Rejected;
  15509. }
  15510. else
  15511. {
  15512. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15513. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15514. isSuccess = ConfigurationStatus_Accepted;
  15515. }
  15516. }
  15517. else
  15518. {
  15519. isSuccess = ConfigurationStatus_Rejected;
  15520. }
  15521. }
  15522. if(strcmp(key, "HeartbeatInterval") == 0)
  15523. {
  15524. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15525. {
  15526. check_ascii = value[0];
  15527. if( (check_ascii < 48) || (check_ascii > 57) )
  15528. {
  15529. isSuccess = ConfigurationStatus_Rejected;
  15530. }
  15531. else
  15532. {
  15533. if((atoi(value) == 0) || (atoi(value) >= 10))
  15534. {
  15535. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15536. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15537. HeartBeatWaitTime = atoi(value);
  15538. isSuccess = ConfigurationStatus_Accepted;
  15539. }
  15540. else
  15541. {
  15542. isSuccess = ConfigurationStatus_Rejected;
  15543. }
  15544. }
  15545. }
  15546. else
  15547. {
  15548. isSuccess = ConfigurationStatus_Rejected;
  15549. }
  15550. }
  15551. if(strcmp(key, "LightIntensity") == 0)
  15552. {
  15553. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15554. {
  15555. check_ascii = value[0];
  15556. if( (check_ascii < 48) || (check_ascii > 57) )
  15557. {
  15558. isSuccess = ConfigurationStatus_Rejected;
  15559. }
  15560. else
  15561. {
  15562. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15563. isSuccess = ConfigurationStatus_Accepted;
  15564. }
  15565. }
  15566. else
  15567. {
  15568. isSuccess = ConfigurationStatus_Rejected;
  15569. }
  15570. }
  15571. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15572. {
  15573. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15574. {
  15575. strcpy(str, (const char*)value);
  15576. for(int i = 0; str[i]; i++)
  15577. {
  15578. str[i] = tolower(str[i]);
  15579. }
  15580. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15581. isSuccess = ConfigurationStatus_Accepted;
  15582. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15583. }
  15584. else
  15585. {
  15586. isSuccess = ConfigurationStatus_Rejected;
  15587. }
  15588. }
  15589. if(strcmp(key, "LocalPreAuthorize") == 0)
  15590. {
  15591. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15592. {
  15593. strcpy(str, (const char*)value);
  15594. for(int i = 0; str[i]; i++)
  15595. {
  15596. str[i] = tolower(str[i]);
  15597. }
  15598. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15599. isSuccess = ConfigurationStatus_Accepted;
  15600. }
  15601. else
  15602. {
  15603. isSuccess = ConfigurationStatus_Rejected;
  15604. }
  15605. }
  15606. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15607. {
  15608. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15609. {
  15610. check_ascii = value[0];
  15611. if( (check_ascii < 48) || (check_ascii > 57) )
  15612. {
  15613. isSuccess = ConfigurationStatus_Rejected;
  15614. }
  15615. else
  15616. {
  15617. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15618. isSuccess = ConfigurationStatus_Accepted;
  15619. }
  15620. }
  15621. else
  15622. {
  15623. isSuccess = ConfigurationStatus_Rejected;
  15624. }
  15625. }
  15626. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15627. {
  15628. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15629. {
  15630. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15631. isSuccess = ConfigurationStatus_Accepted;
  15632. }
  15633. else
  15634. {
  15635. isSuccess = ConfigurationStatus_Rejected;
  15636. }
  15637. }
  15638. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15639. {
  15640. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15641. {
  15642. check_ascii = value[0];
  15643. if( (check_ascii < 48) || (check_ascii > 57) )
  15644. {
  15645. isSuccess = ConfigurationStatus_Rejected;
  15646. }
  15647. else
  15648. {
  15649. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15650. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15651. isSuccess = ConfigurationStatus_Accepted;
  15652. }
  15653. }
  15654. else
  15655. {
  15656. isSuccess = ConfigurationStatus_Rejected;
  15657. }
  15658. }
  15659. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15660. {
  15661. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15662. {
  15663. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15664. isSuccess = ConfigurationStatus_Accepted;
  15665. }
  15666. else
  15667. {
  15668. isSuccess = ConfigurationStatus_Rejected;
  15669. }
  15670. }
  15671. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15672. {
  15673. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15674. {
  15675. check_ascii = value[0];
  15676. if( (check_ascii < 48) || (check_ascii > 57) )
  15677. {
  15678. isSuccess = ConfigurationStatus_Rejected;
  15679. }
  15680. else
  15681. {
  15682. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15683. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15684. isSuccess = ConfigurationStatus_Accepted;
  15685. }
  15686. }
  15687. else
  15688. {
  15689. isSuccess = ConfigurationStatus_Rejected;
  15690. }
  15691. }
  15692. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15693. {
  15694. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15695. {
  15696. check_ascii = value[0];
  15697. if( (check_ascii < 48) || (check_ascii > 57) )
  15698. {
  15699. isSuccess = ConfigurationStatus_Rejected;
  15700. }
  15701. else
  15702. {
  15703. if((atoi(value) == 0) || (atoi(value) >= 5))
  15704. {
  15705. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15706. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15707. isSuccess = ConfigurationStatus_Accepted;
  15708. }
  15709. else
  15710. {
  15711. isSuccess = ConfigurationStatus_Rejected;
  15712. }
  15713. }
  15714. }
  15715. else
  15716. {
  15717. isSuccess = ConfigurationStatus_Rejected;
  15718. }
  15719. }
  15720. if(strcmp(key, "MinimumStatusDuration") == 0)
  15721. {
  15722. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15723. {
  15724. check_ascii = value[0];
  15725. if( (check_ascii < 48) || (check_ascii > 57) )
  15726. {
  15727. isSuccess = ConfigurationStatus_Rejected;
  15728. }
  15729. else
  15730. {
  15731. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15732. {
  15733. isSuccess = ConfigurationStatus_Rejected;
  15734. }
  15735. else
  15736. {
  15737. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  15738. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  15739. server_cycle_Status = atoi(value); //StatusNotification Cycle
  15740. isSuccess = ConfigurationStatus_Accepted;
  15741. }
  15742. }
  15743. }
  15744. else
  15745. {
  15746. isSuccess = ConfigurationStatus_Rejected;
  15747. }
  15748. }
  15749. if(strcmp(key, "NumberOfConnectors") == 0)
  15750. {
  15751. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15752. {
  15753. check_ascii = value[0];
  15754. if( (check_ascii < 48) || (check_ascii > 57) )
  15755. {
  15756. isSuccess = ConfigurationStatus_Rejected;
  15757. }
  15758. else
  15759. {
  15760. //Charger.ResetRetries = Integer.parseInt(value);
  15761. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  15762. isSuccess = ConfigurationStatus_Accepted;
  15763. }
  15764. }
  15765. else
  15766. {
  15767. isSuccess = ConfigurationStatus_Rejected;
  15768. }
  15769. }
  15770. if(strcmp(key, "ResetRetries") == 0)
  15771. {
  15772. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15773. {
  15774. check_ascii = value[0];
  15775. if( (check_ascii < 48) || (check_ascii > 57) )
  15776. {
  15777. isSuccess = ConfigurationStatus_Rejected;
  15778. }
  15779. else
  15780. {
  15781. //Charger.ResetRetries = Integer.parseInt(value);
  15782. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  15783. isSuccess = ConfigurationStatus_Accepted;
  15784. }
  15785. }
  15786. else
  15787. {
  15788. isSuccess = ConfigurationStatus_Rejected;
  15789. }
  15790. }
  15791. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  15792. {
  15793. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15794. {
  15795. strcpy(str, (const char*)value);
  15796. for(int i = 0; str[i]; i++)
  15797. {
  15798. str[i] = tolower(str[i]);
  15799. }
  15800. if(strcmp(str, "notapplicable")== 0)
  15801. {
  15802. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  15803. isSuccess = ConfigurationStatus_Accepted;
  15804. }
  15805. else if(strcmp(str, "unknown")== 0)
  15806. {
  15807. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  15808. isSuccess = ConfigurationStatus_Accepted;
  15809. }
  15810. else if(strcmp(str, "rst")== 0)
  15811. {
  15812. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  15813. isSuccess = ConfigurationStatus_Accepted;
  15814. }
  15815. else if(strcmp(str, "rts")== 0)
  15816. {
  15817. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  15818. isSuccess = ConfigurationStatus_Accepted;
  15819. }
  15820. else if(strcmp(str, "srt")== 0)
  15821. {
  15822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  15823. isSuccess = ConfigurationStatus_Accepted;
  15824. }
  15825. else if(strcmp(str, "str")== 0)
  15826. {
  15827. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  15828. isSuccess = ConfigurationStatus_Accepted;
  15829. }
  15830. else if(strcmp(str, "trs")== 0)
  15831. {
  15832. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  15833. isSuccess = ConfigurationStatus_Accepted;
  15834. }
  15835. else if(strcmp(str, "tsr")== 0)
  15836. {
  15837. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  15838. isSuccess = ConfigurationStatus_Accepted;
  15839. }
  15840. else
  15841. {
  15842. isSuccess = ConfigurationStatus_Rejected;
  15843. }
  15844. }
  15845. else
  15846. {
  15847. isSuccess = ConfigurationStatus_Rejected;
  15848. }
  15849. }
  15850. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  15851. {
  15852. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15853. {
  15854. check_ascii = value[0];
  15855. if( (check_ascii < 48) || (check_ascii > 57) )
  15856. {
  15857. isSuccess = ConfigurationStatus_Rejected;
  15858. }
  15859. else
  15860. {
  15861. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  15862. isSuccess = ConfigurationStatus_Accepted;
  15863. }
  15864. }
  15865. else
  15866. {
  15867. isSuccess = ConfigurationStatus_Rejected;
  15868. }
  15869. }
  15870. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  15871. {
  15872. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15873. {
  15874. strcpy(str, (const char*)value);
  15875. for(int i = 0; str[i]; i++)
  15876. {
  15877. str[i] = tolower(str[i]);
  15878. }
  15879. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15880. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15881. isSuccess = ConfigurationStatus_Accepted;
  15882. }
  15883. else
  15884. {
  15885. isSuccess = ConfigurationStatus_Rejected;
  15886. }
  15887. }
  15888. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  15889. {
  15890. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15891. {
  15892. strcpy(str, (const char*)value);
  15893. for(int i = 0; str[i]; i++)
  15894. {
  15895. str[i] = tolower(str[i]);
  15896. }
  15897. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  15898. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15899. isSuccess = ConfigurationStatus_Accepted;
  15900. }
  15901. else
  15902. {
  15903. isSuccess = ConfigurationStatus_Rejected;
  15904. }
  15905. }
  15906. if(strcmp(key, "StopTxnAlignedData") == 0)
  15907. {
  15908. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15909. {
  15910. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  15911. isSuccess = ConfigurationStatus_Accepted;
  15912. }
  15913. else
  15914. {
  15915. isSuccess = ConfigurationStatus_Rejected;
  15916. }
  15917. }
  15918. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  15919. {
  15920. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15921. {
  15922. check_ascii = value[0];
  15923. if( (check_ascii < 48) || (check_ascii > 57) )
  15924. {
  15925. isSuccess = ConfigurationStatus_Rejected;
  15926. }
  15927. else
  15928. {
  15929. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  15930. isSuccess = ConfigurationStatus_Accepted;
  15931. }
  15932. }
  15933. else
  15934. {
  15935. isSuccess = ConfigurationStatus_Rejected;
  15936. }
  15937. }
  15938. if(strcmp(key, "StopTxnSampledData") == 0)
  15939. {
  15940. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15941. {
  15942. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  15943. isSuccess = ConfigurationStatus_Accepted;
  15944. }
  15945. else
  15946. {
  15947. isSuccess = ConfigurationStatus_Rejected;
  15948. }
  15949. }
  15950. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  15951. {
  15952. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15953. {
  15954. check_ascii = value[0];
  15955. if( (check_ascii < 48) || (check_ascii > 57) )
  15956. {
  15957. isSuccess = ConfigurationStatus_Rejected;
  15958. }
  15959. else
  15960. {
  15961. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  15962. isSuccess = ConfigurationStatus_Accepted;
  15963. }
  15964. }
  15965. else
  15966. {
  15967. isSuccess = ConfigurationStatus_Rejected;
  15968. }
  15969. }
  15970. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  15971. {
  15972. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15973. {
  15974. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  15975. isSuccess = ConfigurationStatus_Accepted;
  15976. }
  15977. else
  15978. {
  15979. isSuccess = ConfigurationStatus_Rejected;
  15980. }
  15981. }
  15982. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  15983. {
  15984. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15985. {
  15986. check_ascii = value[0];
  15987. if( (check_ascii < 48) || (check_ascii > 57) )
  15988. {
  15989. isSuccess = ConfigurationStatus_Rejected;
  15990. }
  15991. else
  15992. {
  15993. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  15994. isSuccess = ConfigurationStatus_Accepted;
  15995. }
  15996. }
  15997. else
  15998. {
  15999. isSuccess = ConfigurationStatus_Rejected;
  16000. }
  16001. }
  16002. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16003. {
  16004. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16005. {
  16006. check_ascii = value[0];
  16007. if( (check_ascii < 48) || (check_ascii > 57) )
  16008. {
  16009. isSuccess = ConfigurationStatus_Rejected;
  16010. }
  16011. else
  16012. {
  16013. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16014. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16015. TransactionMessageAttemptsValue = atoi(value);
  16016. isSuccess = ConfigurationStatus_Accepted;
  16017. }
  16018. }
  16019. else
  16020. {
  16021. isSuccess = ConfigurationStatus_Rejected;
  16022. }
  16023. }
  16024. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16025. {
  16026. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16027. {
  16028. check_ascii = value[0];
  16029. if( (check_ascii < 48) || (check_ascii > 57) )
  16030. {
  16031. isSuccess = ConfigurationStatus_Rejected;
  16032. }
  16033. else
  16034. {
  16035. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16036. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16037. TransactionMessageRetryIntervalValue = atoi(value);
  16038. isSuccess = ConfigurationStatus_Accepted;
  16039. }
  16040. }
  16041. else
  16042. {
  16043. isSuccess = ConfigurationStatus_Rejected;
  16044. }
  16045. }
  16046. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16047. {
  16048. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16049. {
  16050. strcpy(str, (const char*)value);
  16051. for(int i = 0; str[i]; i++)
  16052. {
  16053. str[i] = tolower(str[i]);
  16054. }
  16055. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16056. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16057. isSuccess = ConfigurationStatus_Accepted;
  16058. }
  16059. else
  16060. {
  16061. isSuccess = ConfigurationStatus_Rejected;
  16062. }
  16063. }
  16064. if(strcmp(key, "WebSocketPingInterval") == 0)
  16065. {
  16066. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16067. {
  16068. check_ascii = value[0];
  16069. if( (check_ascii < 48) || (check_ascii > 57) )
  16070. {
  16071. isSuccess = ConfigurationStatus_Rejected;
  16072. }
  16073. else
  16074. {
  16075. if((atoi(value) == 0) || (atoi(value) >= 10))
  16076. {
  16077. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16078. isSuccess = ConfigurationStatus_Accepted;
  16079. }
  16080. else
  16081. isSuccess = ConfigurationStatus_Rejected;
  16082. }
  16083. }
  16084. else
  16085. {
  16086. isSuccess = ConfigurationStatus_Rejected;
  16087. }
  16088. }
  16089. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16090. {
  16091. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16092. {
  16093. strcpy(str, (const char*)value);
  16094. for(int i = 0; str[i]; i++)
  16095. {
  16096. str[i] = tolower(str[i]);
  16097. }
  16098. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16099. isSuccess = ConfigurationStatus_Accepted;
  16100. }
  16101. else
  16102. {
  16103. isSuccess = ConfigurationStatus_Rejected;
  16104. }
  16105. }
  16106. if(strcmp(key, "AuthorizationKey") == 0)
  16107. {
  16108. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16109. {
  16110. strcpy(str, (const char*)value);
  16111. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16112. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16113. isSuccess = ConfigurationStatus_Accepted;
  16114. }
  16115. else
  16116. {
  16117. isSuccess = ConfigurationStatus_Rejected;
  16118. }
  16119. }
  16120. if(strcmp(key, "SecurityProfile") == 0)
  16121. {
  16122. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16123. {
  16124. check_ascii = value[0];
  16125. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16126. {
  16127. isSuccess = ConfigurationStatus_Rejected;
  16128. }
  16129. else if(check_ascii == 0x33)
  16130. {
  16131. isSuccess = NotSupported;
  16132. }
  16133. else
  16134. {
  16135. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16136. {
  16137. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16138. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  16139. isSuccess = ConfigurationStatus_Accepted;
  16140. }
  16141. else
  16142. isSuccess = ConfigurationStatus_Rejected;
  16143. }
  16144. }
  16145. else
  16146. {
  16147. isSuccess = ConfigurationStatus_Rejected;
  16148. }
  16149. }
  16150. if(strcmp(key, "DefaultPrice") == 0)
  16151. {
  16152. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16153. {
  16154. strcpy(str, (const char*)value);
  16155. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16156. isSuccess = ConfigurationStatus_Accepted;
  16157. }
  16158. else
  16159. {
  16160. isSuccess = ConfigurationStatus_Rejected;
  16161. }
  16162. }
  16163. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16164. {
  16165. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16166. {
  16167. strcpy(str, (const char*)value);
  16168. for(int i = 0; str[i]; i++)
  16169. {
  16170. str[i] = tolower(str[i]);
  16171. }
  16172. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16173. isSuccess = ConfigurationStatus_Accepted;
  16174. }
  16175. else
  16176. {
  16177. isSuccess = ConfigurationStatus_Rejected;
  16178. }
  16179. }
  16180. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16181. {
  16182. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16183. {
  16184. strcpy(str, (const char*)value);
  16185. for(int i = 0; str[i]; i++)
  16186. {
  16187. str[i] = tolower(str[i]);
  16188. }
  16189. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16190. isSuccess = ConfigurationStatus_Accepted;
  16191. }
  16192. else
  16193. {
  16194. isSuccess = ConfigurationStatus_Rejected;
  16195. }
  16196. }
  16197. if(strcmp(key, "TimeOffset") == 0)
  16198. {
  16199. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16200. {
  16201. strcpy(str, (const char*)value);
  16202. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  16203. isSuccess = ConfigurationStatus_Accepted;
  16204. }
  16205. else
  16206. {
  16207. isSuccess = ConfigurationStatus_Rejected;
  16208. }
  16209. }
  16210. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  16211. {
  16212. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  16213. {
  16214. strcpy(str, (const char*)value);
  16215. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  16216. isSuccess = ConfigurationStatus_Accepted;
  16217. }
  16218. else
  16219. {
  16220. isSuccess = ConfigurationStatus_Rejected;
  16221. }
  16222. }
  16223. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  16224. {
  16225. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  16226. {
  16227. strcpy(str, (const char*)value);
  16228. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  16229. isSuccess = ConfigurationStatus_Accepted;
  16230. }
  16231. else
  16232. {
  16233. isSuccess = ConfigurationStatus_Rejected;
  16234. }
  16235. }
  16236. if(strcmp(key, "SystemUptimeSec") == 0)
  16237. {
  16238. isSuccess = NotSupported;
  16239. }
  16240. if(strcmp(key, "FreeVend") == 0)
  16241. {
  16242. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16243. {
  16244. strcpy(str, (const char*)value);
  16245. for(int i = 0; str[i]; i++)
  16246. {
  16247. str[i] = tolower(str[i]);
  16248. }
  16249. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16250. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16251. isSuccess = ConfigurationStatus_Accepted;
  16252. }
  16253. else
  16254. {
  16255. isSuccess = ConfigurationStatus_Rejected;
  16256. }
  16257. }
  16258. if(strcmp(key, "OcppServer") == 0)
  16259. {
  16260. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16261. {
  16262. strcpy(str, (const char*)value);
  16263. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16264. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16265. isSuccess = ConfigurationStatus_Accepted;
  16266. }
  16267. else
  16268. {
  16269. isSuccess = ConfigurationStatus_Rejected;
  16270. }
  16271. }
  16272. if(strcmp(key, "MaintainServer") == 0)
  16273. {
  16274. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16275. {
  16276. strcpy(str, (const char*)value);
  16277. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16278. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16279. isSuccess = ConfigurationStatus_Accepted;
  16280. }
  16281. else
  16282. {
  16283. isSuccess = ConfigurationStatus_Rejected;
  16284. }
  16285. }
  16286. #if 0
  16287. //For OCPP Test Case
  16288. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16289. {
  16290. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16291. {
  16292. strcpy(str, (const char*)value);
  16293. for(int i = 0; str[i]; i++)
  16294. {
  16295. str[i] = tolower(str[i]);
  16296. }
  16297. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16298. isSuccess = ConfigurationStatus_Accepted;
  16299. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16300. }
  16301. else
  16302. {
  16303. isSuccess = ConfigurationStatus_Rejected;
  16304. }
  16305. }
  16306. #endif
  16307. #if 1
  16308. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16309. {
  16310. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16311. {
  16312. strcpy(str, (const char*)value);
  16313. for(int i = 0; str[i]; i++)
  16314. {
  16315. str[i] = tolower(str[i]);
  16316. }
  16317. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16318. isSuccess = ConfigurationStatus_Accepted;
  16319. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16320. }
  16321. else
  16322. {
  16323. isSuccess = ConfigurationStatus_Rejected;
  16324. }
  16325. }
  16326. #endif
  16327. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16328. {
  16329. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16330. {
  16331. check_ascii = value[0];
  16332. if( (check_ascii < 48) || (check_ascii > 57) )
  16333. {
  16334. isSuccess = ConfigurationStatus_Rejected;
  16335. }
  16336. else
  16337. {
  16338. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16339. isSuccess = ConfigurationStatus_Accepted;
  16340. }
  16341. }
  16342. else
  16343. {
  16344. isSuccess = ConfigurationStatus_Rejected;
  16345. }
  16346. }
  16347. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16348. {
  16349. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16350. {
  16351. check_ascii = value[0];
  16352. if( (check_ascii < 48) || (check_ascii > 57) )
  16353. {
  16354. isSuccess = ConfigurationStatus_Rejected;
  16355. }
  16356. else
  16357. {
  16358. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16359. isSuccess = ConfigurationStatus_Accepted;
  16360. }
  16361. }
  16362. else
  16363. {
  16364. isSuccess = ConfigurationStatus_Rejected;
  16365. }
  16366. }
  16367. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16368. {
  16369. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16370. {
  16371. strcpy(str, (const char*)value);
  16372. for(int i = 0; str[i]; i++)
  16373. {
  16374. str[i] = tolower(str[i]);
  16375. }
  16376. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16377. isSuccess = ConfigurationStatus_Accepted;
  16378. }
  16379. else
  16380. {
  16381. isSuccess = ConfigurationStatus_Rejected;
  16382. }
  16383. }
  16384. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16385. {
  16386. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16387. {
  16388. check_ascii = value[0];
  16389. if( (check_ascii < 48) || (check_ascii > 57) )
  16390. {
  16391. isSuccess = ConfigurationStatus_Rejected;
  16392. }
  16393. else
  16394. {
  16395. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16396. isSuccess = ConfigurationStatus_Accepted;
  16397. }
  16398. }
  16399. else
  16400. {
  16401. isSuccess = ConfigurationStatus_Rejected;
  16402. }
  16403. }
  16404. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16405. {
  16406. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16407. {
  16408. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16409. isSuccess = ConfigurationStatus_Accepted;
  16410. }
  16411. else
  16412. {
  16413. isSuccess = ConfigurationStatus_Rejected;
  16414. }
  16415. }
  16416. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16417. {
  16418. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16419. {
  16420. check_ascii = value[0];
  16421. if( (check_ascii < 48) || (check_ascii > 57) )
  16422. {
  16423. isSuccess = ConfigurationStatus_Rejected;
  16424. }
  16425. else
  16426. {
  16427. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16428. isSuccess = ConfigurationStatus_Accepted;
  16429. }
  16430. }
  16431. else
  16432. {
  16433. isSuccess = ConfigurationStatus_Rejected;
  16434. }
  16435. }
  16436. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16437. {
  16438. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16439. {
  16440. strcpy(str, (const char*)value);
  16441. for(int i = 0; str[i]; i++)
  16442. {
  16443. str[i] = tolower(str[i]);
  16444. }
  16445. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16446. isSuccess = ConfigurationStatus_Accepted;
  16447. }
  16448. else
  16449. {
  16450. isSuccess = ConfigurationStatus_Rejected;
  16451. }
  16452. }
  16453. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16454. {
  16455. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16456. {
  16457. check_ascii = value[0];
  16458. if( (check_ascii < 48) || (check_ascii > 57) )
  16459. {
  16460. isSuccess = ConfigurationStatus_Rejected;
  16461. }
  16462. else
  16463. {
  16464. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16465. isSuccess = ConfigurationStatus_Accepted;
  16466. }
  16467. }
  16468. else
  16469. {
  16470. isSuccess = ConfigurationStatus_Rejected;
  16471. }
  16472. }
  16473. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16474. return isSuccess;
  16475. }
  16476. int TransactionMessageAttemptsGet(void)
  16477. {
  16478. return TransactionMessageAttemptsValue;
  16479. }
  16480. int FirstHeartBeatResponse(void)
  16481. {
  16482. return FirstHeartBeat;
  16483. }
  16484. int TransactionMessageRetryIntervalGet(void)
  16485. {
  16486. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16487. }
  16488. int ReadHttpStatus(int sock)
  16489. {
  16490. //char c;
  16491. char buff[1024]="",*ptr=buff+1;
  16492. int bytes_received, status;
  16493. DEBUG_INFO("Begin Response ..\n");
  16494. while((bytes_received = recv(sock, ptr, 1, 0))){
  16495. if(bytes_received==-1){
  16496. perror("ReadHttpStatus");
  16497. exit(1);
  16498. }
  16499. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16500. ptr++;
  16501. }
  16502. *ptr=0;
  16503. ptr=buff+1;
  16504. sscanf(ptr,"%*s %d ", &status);
  16505. DEBUG_INFO("%s\n",ptr);
  16506. DEBUG_INFO("status=%d\n",status);
  16507. DEBUG_INFO("End Response ..\n");
  16508. return (bytes_received>0)?status:0;
  16509. }
  16510. //the only filed that it parsed is 'Content-Length'
  16511. int ParseHeader(int sock)
  16512. {
  16513. //char c;
  16514. char buff[1024]="",*ptr=buff+4;
  16515. int bytes_received;
  16516. DEBUG_INFO("Begin HEADER ..\n");
  16517. while((bytes_received = recv(sock, ptr, 1, 0))){
  16518. if(bytes_received==-1){
  16519. perror("Parse Header");
  16520. exit(1);
  16521. }
  16522. if(
  16523. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16524. (ptr[-1]=='\r') && (*ptr=='\n' )
  16525. ) break;
  16526. ptr++;
  16527. }
  16528. *ptr=0;
  16529. ptr=buff+4;
  16530. //printf("%s",ptr);
  16531. if(bytes_received){
  16532. ptr=strstr(ptr,"Content-Length:");
  16533. if(ptr){
  16534. sscanf(ptr,"%*s %d",&bytes_received);
  16535. }else
  16536. bytes_received=-1; //unknown size
  16537. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16538. }
  16539. DEBUG_INFO("End HEADER ..\n");
  16540. return bytes_received ;
  16541. }
  16542. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16543. {
  16544. int result = TRUE;
  16545. char rmFileCmd[100]={0};
  16546. char FilePath[100]={0};
  16547. char ftpbuf[200];
  16548. int systemresult;
  16549. sprintf(FilePath,"/mnt/%s",filename);
  16550. system("ping 8.8.8.8 &");
  16551. if((access(FilePath,F_OK))!=-1)
  16552. {
  16553. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16554. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16555. system(rmFileCmd);
  16556. }
  16557. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16558. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16559. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16560. systemresult = system(ftpbuf);
  16561. if(systemresult != 0)
  16562. {
  16563. DEBUG_INFO("http DownLoad error!\n");
  16564. result = FALSE;
  16565. }
  16566. system("pkill ping");
  16567. return result;
  16568. }
  16569. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16570. {
  16571. int result = TRUE;
  16572. char rmFileCmd[100]={0};
  16573. char FilePath[100]={0};
  16574. char ftpbuf[200];
  16575. int systemresult;
  16576. sprintf(FilePath,"/mnt/%s",filename);
  16577. system("ping 8.8.8.8 &");
  16578. if((access(FilePath,F_OK))!=-1)
  16579. {
  16580. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16581. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16582. system(rmFileCmd);
  16583. }
  16584. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16585. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16586. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16587. systemresult = system(ftpbuf);
  16588. if(systemresult != 0)
  16589. {
  16590. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16591. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16592. systemresult = system(ftpbuf);
  16593. if(systemresult != 0)
  16594. {
  16595. DEBUG_WARN("wget error!\n");
  16596. result = FALSE;
  16597. }
  16598. }
  16599. system("pkill ping");
  16600. return result;
  16601. }
  16602. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16603. {
  16604. char rmFileCmd[100]={0};
  16605. char FilePath[100]={0};
  16606. char buf[512];
  16607. int systemresult = 0;
  16608. //DEBUG_INFO("filename=%s\n",filename);
  16609. //DEBUG_INFO("url=%s\n",url);
  16610. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16611. if((access(FilePath,F_OK))!=-1)
  16612. {
  16613. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16614. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16615. system(rmFileCmd);
  16616. }
  16617. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16618. if(fp == NULL)
  16619. {
  16620. DEBUG_INFO("log is NULL\n");
  16621. return FALSE;
  16622. }
  16623. else
  16624. {
  16625. fprintf(fp, "%s\n", url);
  16626. fprintf(fp, "%s\n", filename);
  16627. fclose(fp);
  16628. }
  16629. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16630. if(phpFP == NULL)
  16631. {
  16632. DEBUG_INFO("PHP upload fail.\n");
  16633. return FALSE;
  16634. }
  16635. else
  16636. {
  16637. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16638. {
  16639. if(strstr(buf, "result") != NULL)
  16640. {
  16641. sscanf(buf, "result: %d", &systemresult);
  16642. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16643. }
  16644. }
  16645. pclose(phpFP);
  16646. }
  16647. if(systemresult != 1)
  16648. {
  16649. DEBUG_INFO("HTTP upload error!\n");
  16650. return FALSE;
  16651. }
  16652. return TRUE;
  16653. }
  16654. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16655. {
  16656. int result = FALSE;
  16657. char ftpbuf[200];
  16658. int systemresult;
  16659. /*
  16660. // Domaind name transfer to IP address
  16661. struct hostent* server;
  16662. char *IPbuffer;
  16663. server = gethostbyname(location);
  16664. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16665. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16666. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16667. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16668. systemresult = system(ftpbuf);
  16669. if(systemresult != 0)
  16670. {
  16671. DEBUG_INFO("ftpput error!\n");
  16672. }
  16673. else
  16674. {
  16675. result = TRUE;
  16676. DEBUG_INFO("ftpput OK!\n");
  16677. }
  16678. return result;
  16679. }
  16680. int GetOcppServerURL()
  16681. {
  16682. int result = FALSE;
  16683. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16684. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16685. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16686. struct yuarel url;
  16687. char urlStr[512];
  16688. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  16689. {
  16690. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  16691. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16692. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16693. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  16694. if(yuarel_parse(&url, urlStr) != -1)
  16695. {
  16696. sprintf(OcppProtocol, "%s", url.scheme);
  16697. sprintf(OcppHost, "%s", url.host);
  16698. if(url.path == NULL)
  16699. OcppTempPath[0] = '\0';
  16700. else
  16701. {
  16702. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  16703. {
  16704. sprintf(OcppTempPath, "%s/", url.path);
  16705. }
  16706. else
  16707. {
  16708. sprintf(OcppTempPath, "%s", url.path);
  16709. }
  16710. }
  16711. if(url.port == 0)
  16712. {
  16713. if(strcmp(OcppProtocol, "wss") == 0)
  16714. OcppPort = 443;
  16715. else
  16716. OcppPort = 80;
  16717. }
  16718. else
  16719. OcppPort = url.port;
  16720. result = TRUE;
  16721. }
  16722. }
  16723. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  16724. {
  16725. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  16726. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16727. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16728. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  16729. if(yuarel_parse(&url, urlStr) != -1)
  16730. {
  16731. sprintf(OcppProtocol, "%s", url.scheme);
  16732. sprintf(OcppHost, "%s", url.host);
  16733. if(url.path == NULL)
  16734. OcppTempPath[0] = '\0';
  16735. else
  16736. sprintf(OcppTempPath, "%s", url.path);
  16737. if(url.port == 0)
  16738. {
  16739. if(strcmp(OcppProtocol, "wss") == 0)
  16740. OcppPort = 443;
  16741. else
  16742. OcppPort = 80;
  16743. }
  16744. else
  16745. OcppPort = url.port;
  16746. result = TRUE;
  16747. }
  16748. }
  16749. else
  16750. {
  16751. strcpy(OcppHost,"");
  16752. }
  16753. return result;
  16754. }
  16755. int GetOcppPath()
  16756. {
  16757. int result = FALSE;
  16758. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  16759. {
  16760. if(OcppTempPath == NULL)
  16761. {
  16762. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16763. }
  16764. else
  16765. {
  16766. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16767. }
  16768. result = TRUE;
  16769. goto End;
  16770. }
  16771. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  16772. {
  16773. if(OcppTempPath == NULL)
  16774. {
  16775. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  16776. }
  16777. else
  16778. {
  16779. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  16780. }
  16781. result = TRUE;
  16782. goto End;
  16783. }
  16784. else
  16785. {
  16786. strcpy(OcppPath,"");
  16787. }
  16788. End:
  16789. return result;
  16790. }
  16791. int GetOcppPort()
  16792. {
  16793. return OcppPort;
  16794. }
  16795. int GetOcppConnStatus(void)
  16796. {
  16797. return ShmOCPP16Data->OcppConnStatus;
  16798. }
  16799. void SetOcppConnStatus(uint8_t status)
  16800. {
  16801. ShmOCPP16Data->OcppConnStatus = status;
  16802. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  16803. }
  16804. int GetHeartBeatWithNOResponse(void)
  16805. {
  16806. return HeartBeatWithNOResponse;
  16807. }
  16808. void SetHeartBeatWithNOResponse(void)
  16809. {
  16810. HeartBeatWithNOResponse = 0;
  16811. }
  16812. void GetStartTransactionIdTag(int gun_index)
  16813. {
  16814. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  16815. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  16816. }
  16817. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  16818. {
  16819. char ch;
  16820. FILE *fptr1;
  16821. int temptransactionId;
  16822. char str[100]={0};
  16823. temptransactionId = 0;
  16824. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  16825. {
  16826. DEBUG_INFO("IdTag is empty.\n");
  16827. return temptransactionId;
  16828. }
  16829. /*------ Read the file ----------------*/
  16830. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  16831. if (!fptr1)
  16832. {
  16833. DEBUG_INFO("QueueTransactionId file open error.\n");
  16834. //printf(" File not found or unable to open the input file!!\n");
  16835. return temptransactionId;
  16836. }
  16837. ch=fgetc(fptr1);
  16838. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  16839. rewind(fptr1);
  16840. if(ch!=EOF)
  16841. {
  16842. // printf("%c",ch);
  16843. while (fgets(str, 100, fptr1) != NULL)
  16844. {
  16845. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16846. if(str[0]=='\0')
  16847. {
  16848. break;
  16849. }
  16850. char *revbuf[8] = {0}; // Variable store string split
  16851. int num = 0;// Quantity after string split
  16852. DEBUG_INFO("Transaction queue data= %s\n", str);
  16853. splitstring(str,",",revbuf,&num); // String split
  16854. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  16855. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  16856. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  16857. DEBUG_INFO("------------------------------\n");
  16858. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  16859. {
  16860. if(isStopTransaction)
  16861. {
  16862. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  16863. {
  16864. temptransactionId = atoi(revbuf[2]);
  16865. //break;
  16866. }
  16867. }
  16868. else
  16869. {
  16870. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  16871. {
  16872. temptransactionId = atoi(revbuf[2]);
  16873. //break;
  16874. }
  16875. }
  16876. }
  16877. }
  16878. }
  16879. else
  16880. DEBUG_INFO("EOF\n");
  16881. fclose(fptr1);
  16882. /*------- End of reading ---------------*/
  16883. return temptransactionId;
  16884. }
  16885. void SetTransactionIdZero(int transactionId)
  16886. {
  16887. char ch;
  16888. FILE *fptr1, *fptr2;
  16889. int temptransactionId = 0;
  16890. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  16891. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  16892. if (!fptr1)
  16893. {
  16894. //printf(" File not found or unable to open the input file!!\n");
  16895. return ;
  16896. }
  16897. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  16898. if (!fptr2)
  16899. {
  16900. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  16901. fclose(fptr1);
  16902. return ;
  16903. }
  16904. ch=fgetc(fptr1);
  16905. rewind(fptr1);
  16906. if(ch!=EOF)
  16907. {
  16908. // copy all contents to the temporary file except the specific line
  16909. while (fgets(str, 100, fptr1) != NULL)
  16910. {
  16911. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16912. if(str[0]=='\0')
  16913. {
  16914. break;
  16915. }
  16916. char *revbuf[8] = {0};
  16917. int num = 0;
  16918. strcpy(strtemp, str);
  16919. splitstring(str,",",revbuf,&num);
  16920. if(revbuf[2][0] != '\0')
  16921. {
  16922. temptransactionId = atoi(revbuf[2]);
  16923. if(transactionId != temptransactionId)
  16924. {
  16925. fprintf(fptr2, "%s\n", strtemp);
  16926. }
  16927. }
  16928. }
  16929. }
  16930. fclose(fptr1);
  16931. fclose(fptr2);
  16932. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  16933. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  16934. /*------ Read the file ----------------*/
  16935. }
  16936. int InternetDisconnect(void)
  16937. {
  16938. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  16939. }
  16940. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  16941. void storeTempStopTransaction(int gun_index)
  16942. {
  16943. char guid[37]={0};
  16944. int tempIndex = 0;
  16945. char TempStopTransaction[256];
  16946. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  16947. DEBUG_INFO("storeTempStopTransaction...\n");
  16948. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  16949. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  16950. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  16951. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16952. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16953. {
  16954. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16955. {
  16956. tempIndex = ((gun_index==2) ? 1: 0);
  16957. }
  16958. else
  16959. {
  16960. tempIndex = gun_index;
  16961. }
  16962. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16963. {
  16964. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16965. {
  16966. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  16967. }
  16968. }// END OF CHAdeMO_QUANTITY
  16969. }
  16970. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16971. {
  16972. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16973. {
  16974. tempIndex = ((gun_index==2) ? 1: 0);
  16975. }
  16976. else
  16977. {
  16978. tempIndex = gun_index;
  16979. }
  16980. for (int index = 0; index < CCS_QUANTITY; index++)
  16981. {
  16982. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16983. {
  16984. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  16985. }
  16986. }// END OF CCS_QUANTITY
  16987. }
  16988. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16989. {
  16990. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16991. {
  16992. tempIndex = ((gun_index==2) ? 1: 0);
  16993. }
  16994. else
  16995. {
  16996. tempIndex = gun_index;
  16997. }
  16998. for (int index = 0; index < GB_QUANTITY; index++)
  16999. {
  17000. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17001. {
  17002. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17003. }
  17004. }// END OF GB_QUANTITY
  17005. }
  17006. else if(gunType[gun_index] == GUN_TYPE_DO)
  17007. {
  17008. tempIndex = gun_index;
  17009. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17010. {
  17011. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17012. {
  17013. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17014. }
  17015. }
  17016. }
  17017. else
  17018. {
  17019. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17020. {
  17021. tempIndex = 2;
  17022. }
  17023. else
  17024. {
  17025. tempIndex = gun_index;
  17026. }
  17027. for (int index = 0; index < AC_QUANTITY; index++)
  17028. {
  17029. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17030. {
  17031. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17032. }
  17033. }// END OF AC_QUANTITY
  17034. }
  17035. //Stop Transaction Time
  17036. struct timeval tmnow;
  17037. struct tm *tm;
  17038. char buf[28];//, usec_buf[6];
  17039. gettimeofday(&tmnow, NULL);
  17040. time_t t;
  17041. t = time(NULL);
  17042. /*UTC time and date*/
  17043. tm = gmtime(&t);
  17044. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17045. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  17046. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  17047. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17048. random_uuid(guid);
  17049. /***********************************transactionData******************************************************/
  17050. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17051. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17052. //=================================
  17053. //1. Transaction_Begin
  17054. //=================================
  17055. //============================== Energy.Active.Import.Interval ===========================================
  17056. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17057. {
  17058. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  17059. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17060. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  17061. 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*/]);
  17062. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17063. 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))
  17064. {
  17065. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  17066. }
  17067. else
  17068. {
  17069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  17070. }
  17071. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  17072. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17073. }
  17074. //=================================
  17075. //2. Transaction_End
  17076. //=================================
  17077. //2.1====================================== Current.Import L1 ==============================================
  17078. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17079. {
  17080. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17081. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17082. {
  17083. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17084. {
  17085. tempIndex = ((gun_index==2) ? 1: 0);
  17086. }
  17087. else
  17088. {
  17089. tempIndex = gun_index;
  17090. }
  17091. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17092. {
  17093. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17094. {
  17095. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17096. }
  17097. }// End of for CHAdeMO_QUANTITY
  17098. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17099. }
  17100. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17101. {
  17102. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17103. {
  17104. tempIndex = ((gun_index==2) ? 1: 0);
  17105. }
  17106. else
  17107. {
  17108. tempIndex = gun_index;
  17109. }
  17110. for (int index = 0; index < CCS_QUANTITY; index++)
  17111. {
  17112. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17113. {
  17114. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17115. }
  17116. }// End of for CCS_QUANTITY
  17117. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17118. }
  17119. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17120. {
  17121. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17122. {
  17123. tempIndex = ((gun_index==2) ? 1: 0);
  17124. }
  17125. else
  17126. {
  17127. tempIndex = gun_index;
  17128. }
  17129. for (int index = 0; index < GB_QUANTITY; index++)
  17130. {
  17131. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17132. {
  17133. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17134. }
  17135. }// End of for GB_QUANTITY
  17136. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17137. }
  17138. else if(gunType[gun_index] == GUN_TYPE_DO)
  17139. {
  17140. tempIndex = gun_index;
  17141. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17142. {
  17143. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17144. {
  17145. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17146. }
  17147. }
  17148. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17149. }
  17150. else
  17151. {
  17152. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17153. {
  17154. tempIndex = 2;
  17155. }
  17156. else
  17157. {
  17158. tempIndex = gun_index;
  17159. }
  17160. for (int index = 0; index < AC_QUANTITY; index++)
  17161. {
  17162. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17163. {
  17164. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17165. }
  17166. }// End of for AC_QUANTITY
  17167. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17168. }
  17169. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17170. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17171. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17172. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17173. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17174. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17175. }
  17176. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17177. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17178. {
  17179. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17180. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17181. {
  17182. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17183. {
  17184. tempIndex = ((gun_index==2) ? 1: 0);
  17185. }
  17186. else
  17187. {
  17188. tempIndex = gun_index;
  17189. }
  17190. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17191. {
  17192. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17193. {
  17194. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17195. }
  17196. }// END OF CHAdeMO_QUANTITY
  17197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17198. }
  17199. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17200. {
  17201. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17202. {
  17203. tempIndex = ((gun_index==2) ? 1: 0);
  17204. }
  17205. else
  17206. {
  17207. tempIndex = gun_index;
  17208. }
  17209. for (int index = 0; index < CCS_QUANTITY; index++)
  17210. {
  17211. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17212. {
  17213. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17214. }
  17215. }// END OF CCS_QUANTITY
  17216. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17217. }
  17218. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17219. {
  17220. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17221. {
  17222. tempIndex = ((gun_index==2) ? 1: 0);
  17223. }
  17224. else
  17225. {
  17226. tempIndex = gun_index;
  17227. }
  17228. for (int index = 0; index < GB_QUANTITY; index++)
  17229. {
  17230. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17231. {
  17232. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17233. }
  17234. }// END OF GB_QUANTITY
  17235. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17236. }
  17237. else if(gunType[gun_index] == GUN_TYPE_DO)
  17238. {
  17239. tempIndex = gun_index;
  17240. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17241. {
  17242. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17243. {
  17244. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17245. }
  17246. }
  17247. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17248. }
  17249. else
  17250. {
  17251. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17252. {
  17253. tempIndex = 2;
  17254. }
  17255. else
  17256. {
  17257. tempIndex = gun_index;
  17258. }
  17259. for (int index = 0; index < AC_QUANTITY; index++)
  17260. {
  17261. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17262. {
  17263. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17264. }
  17265. }// END OF AC_QUANTITY
  17266. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17267. }
  17268. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17269. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17270. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17271. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17272. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17273. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17274. }
  17275. //2.3====================================== Power.Active.Import =========================================
  17276. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17277. {
  17278. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17279. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17280. {
  17281. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17282. {
  17283. tempIndex = ((gun_index==2) ? 1: 0);
  17284. }
  17285. else
  17286. {
  17287. tempIndex = gun_index;
  17288. }
  17289. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17290. {
  17291. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17292. {
  17293. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17294. }
  17295. } // End for CHAdeMO_QUANTITY
  17296. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17297. }
  17298. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17299. {
  17300. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17301. {
  17302. tempIndex = ((gun_index==2) ? 1: 0);
  17303. }
  17304. else
  17305. {
  17306. tempIndex = gun_index;
  17307. }
  17308. for (int index = 0; index < CCS_QUANTITY; index++)
  17309. {
  17310. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17311. {
  17312. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17313. }
  17314. } // END for CCS_QUANTITY
  17315. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17316. }
  17317. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17318. {
  17319. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17320. {
  17321. tempIndex = ((gun_index==2) ? 1: 0);
  17322. }
  17323. else
  17324. {
  17325. tempIndex = gun_index;
  17326. }
  17327. for (int index = 0; index < GB_QUANTITY; index++)
  17328. {
  17329. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17330. {
  17331. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17332. }
  17333. }// END for GB_QUANTITY
  17334. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17335. }
  17336. else if(gunType[gun_index] == GUN_TYPE_DO)
  17337. {
  17338. tempIndex = gun_index;
  17339. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17340. {
  17341. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17342. {
  17343. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17344. }
  17345. }
  17346. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17347. }
  17348. else
  17349. {
  17350. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17351. {
  17352. tempIndex = 2;
  17353. }
  17354. else
  17355. {
  17356. tempIndex = gun_index;
  17357. }
  17358. for (int index = 0; index < AC_QUANTITY; index++)
  17359. {
  17360. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17361. {
  17362. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17363. }
  17364. } // END for AC_QUANTITY
  17365. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17366. }
  17367. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17368. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17369. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17370. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17371. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17372. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17373. }
  17374. //2.4====================================== Voltage L1 ====================================================
  17375. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17376. {
  17377. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17378. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  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 < CHAdeMO_QUANTITY; index++)
  17389. {
  17390. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17391. {
  17392. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17393. }
  17394. } // END OF FOR CHAdeMO_QUANTITY
  17395. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17396. }
  17397. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17398. {
  17399. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17400. {
  17401. tempIndex = ((gun_index==2) ? 1: 0);
  17402. }
  17403. else
  17404. {
  17405. tempIndex = gun_index;
  17406. }
  17407. for (int index = 0; index < CCS_QUANTITY; index++)
  17408. {
  17409. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17410. {
  17411. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17412. }
  17413. } // END OF FOR CCS_QUANTITY
  17414. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17415. }
  17416. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17417. {
  17418. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17419. {
  17420. tempIndex = ((gun_index==2) ? 1: 0);
  17421. }
  17422. else
  17423. {
  17424. tempIndex = gun_index;
  17425. }
  17426. for (int index = 0; index < GB_QUANTITY; index++)
  17427. {
  17428. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17429. {
  17430. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17431. }
  17432. } // END OF FOR GB_QUANTITY
  17433. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17434. }
  17435. else if(gunType[gun_index] == GUN_TYPE_DO)
  17436. {
  17437. tempIndex = gun_index;
  17438. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17439. {
  17440. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17441. {
  17442. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17443. }
  17444. }
  17445. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17446. }
  17447. else
  17448. {
  17449. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17450. {
  17451. tempIndex = 2;
  17452. }
  17453. else
  17454. {
  17455. tempIndex = gun_index;
  17456. }
  17457. for (int index = 0; index < AC_QUANTITY; index++)
  17458. {
  17459. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17460. {
  17461. 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
  17462. }
  17463. } // END OF FOR AC_QUANTITY
  17464. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17465. }
  17466. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17467. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17468. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17469. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17470. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17471. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17472. }
  17473. //2.5============================================== End SoC =========================================================
  17474. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17475. {
  17476. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17477. 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))
  17478. {
  17479. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17480. {
  17481. tempIndex = ((gun_index==2) ? 1: 0);
  17482. }
  17483. else
  17484. {
  17485. tempIndex = gun_index;
  17486. }
  17487. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17488. {
  17489. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17490. {
  17491. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17492. {
  17493. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17494. }
  17495. }
  17496. }
  17497. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17498. {
  17499. for (int index = 0; index < CCS_QUANTITY; index++)
  17500. {
  17501. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17502. {
  17503. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17504. }
  17505. }
  17506. }
  17507. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17508. {
  17509. for (int index = 0; index < GB_QUANTITY; index++)
  17510. {
  17511. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17512. {
  17513. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17514. }
  17515. }
  17516. }
  17517. else if(gunType[gun_index] == GUN_TYPE_DO)
  17518. {
  17519. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17520. {
  17521. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17522. {
  17523. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17524. }
  17525. }
  17526. }
  17527. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17528. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17529. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17530. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17531. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17532. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17533. } // END FOR DC CASE
  17534. }
  17535. //2.6====================================== Current.Import L2 ==============================================
  17536. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17537. {
  17538. // AC 3 phase L2 current
  17539. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17540. {
  17541. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17542. {
  17543. tempIndex = 2;
  17544. }
  17545. else
  17546. {
  17547. tempIndex = gun_index;
  17548. }
  17549. for (int index = 0; index < AC_QUANTITY; index++)
  17550. {
  17551. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17552. {
  17553. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17554. }
  17555. }// End of for AC_QUANTITY
  17556. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17557. }
  17558. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17559. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17560. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17561. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17562. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17563. }
  17564. //2.7====================================== Current.Import L3 ==============================================
  17565. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17566. {
  17567. // AC 3 phase L3 current
  17568. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17569. {
  17570. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17571. {
  17572. tempIndex = 2;
  17573. }
  17574. else
  17575. {
  17576. tempIndex = gun_index;
  17577. }
  17578. for (int index = 0; index < AC_QUANTITY; index++)
  17579. {
  17580. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17581. {
  17582. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17583. }
  17584. }// End of for AC_QUANTITY
  17585. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17586. }
  17587. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17588. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17589. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17590. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17592. }
  17593. //2.9====================================== Voltage L2 ====================================================
  17594. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17595. {
  17596. // AC 3 phase L2 volatge
  17597. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17598. {
  17599. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17600. {
  17601. tempIndex = 2;
  17602. }
  17603. else
  17604. {
  17605. tempIndex = gun_index;
  17606. }
  17607. for (int index = 0; index < AC_QUANTITY; index++)
  17608. {
  17609. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17610. {
  17611. 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
  17612. }
  17613. } // END OF FOR AC_QUANTITY
  17614. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  17615. }
  17616. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17617. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17618. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17619. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17620. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17621. }
  17622. //2.10====================================== Voltage L3 ====================================================
  17623. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17624. {
  17625. // AC 3 phase L3 volatge
  17626. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17627. {
  17628. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17629. {
  17630. tempIndex = 2;
  17631. }
  17632. else
  17633. {
  17634. tempIndex = gun_index;
  17635. }
  17636. for (int index = 0; index < AC_QUANTITY; index++)
  17637. {
  17638. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17639. {
  17640. 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
  17641. }
  17642. } // END OF FOR AC_QUANTITY
  17643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  17644. }
  17645. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17646. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  17647. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  17648. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  17649. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17650. }
  17651. //====================== Start SoC ================================
  17652. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17653. {
  17654. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17655. 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))
  17656. {
  17657. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17658. {
  17659. tempIndex = ((gun_index==2) ? 1: 0);
  17660. }
  17661. else
  17662. {
  17663. tempIndex = gun_index;
  17664. }
  17665. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17666. {
  17667. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17668. {
  17669. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17670. {
  17671. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  17672. }
  17673. }
  17674. }
  17675. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17676. {
  17677. for (int index = 0; index < CCS_QUANTITY; index++)
  17678. {
  17679. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17680. {
  17681. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  17682. }
  17683. }
  17684. }
  17685. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17686. {
  17687. for (int index = 0; index < GB_QUANTITY; index++)
  17688. {
  17689. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17690. {
  17691. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  17692. }
  17693. }
  17694. }
  17695. else if(gunType[gun_index] == GUN_TYPE_DO)
  17696. {
  17697. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17698. {
  17699. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17700. {
  17701. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  17702. }
  17703. }
  17704. }
  17705. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17706. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  17707. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17708. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  17709. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  17710. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17711. } // END FOR DC CASE
  17712. }
  17713. //======================================== Message create ==============================================
  17714. json_object *StopTransaction = json_object_new_object();
  17715. json_object *transactionDatas = json_object_new_array();
  17716. json_object *sampledValues = json_object_new_array();
  17717. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  17718. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  17719. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  17720. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  17721. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  17722. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  17723. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  17724. {
  17725. json_object *transactionData = json_object_new_object();
  17726. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  17727. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  17728. {
  17729. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  17730. {
  17731. json_object *sampledValue = json_object_new_object();
  17732. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  17733. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  17734. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  17735. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  17736. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  17737. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  17738. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  17739. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  17740. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  17741. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  17742. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  17743. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  17744. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  17745. json_object_array_add(sampledValues, sampledValue);
  17746. }
  17747. }
  17748. json_object_object_add(transactionData, "sampledValue", sampledValues);
  17749. json_object_array_add(transactionDatas, transactionData);
  17750. }
  17751. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  17752. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  17753. ,MESSAGE_TYPE_CALL
  17754. ,guid
  17755. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  17756. json_object_put(StopTransaction);
  17757. // Check File "TempStopTransaction" Exist
  17758. if((access(TempStopTransaction,F_OK))!=-1)
  17759. {
  17760. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  17761. fclose(fopen(TempStopTransaction, "w"));
  17762. }
  17763. else
  17764. {
  17765. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  17766. FILE *log = fopen(TempStopTransaction, "w+");
  17767. if(log == NULL)
  17768. {
  17769. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  17770. return ;
  17771. }
  17772. else
  17773. {
  17774. fclose(log);
  17775. }
  17776. }
  17777. //Add TempStopTransaction | Update TempStopTransaction
  17778. // open file for writing
  17779. FILE *outfile;
  17780. outfile = fopen (TempStopTransaction, "a");
  17781. //DEBUG_INFO("data = %s\n", queuedata);
  17782. fputs(queuedata, outfile);
  17783. fputs("\n", outfile);
  17784. fclose (outfile);
  17785. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17786. OCPP_updatePeriodEnergy(gun_index);
  17787. }
  17788. void checkTempStopTransaction(int gun_index)
  17789. {
  17790. FILE *fptr1;
  17791. char ch;
  17792. char str[QUEUE_MESSAGE_LENGTH]={0};
  17793. char guid[37]={0};
  17794. char tempdata[65]={0};
  17795. char connectorStr[2]={0};
  17796. char TempStopTransaction[256];
  17797. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  17798. fptr1 = fopen(TempStopTransaction, "r");
  17799. //TempStopTransaction格式: 槍號,StopTransaction封包
  17800. if (!fptr1)
  17801. {
  17802. //printf(" File not found or unable to open the input file!!\n");
  17803. return ;
  17804. }
  17805. ch=fgetc(fptr1);
  17806. //printf(" Now the content of the file %s is : \n",fname);
  17807. rewind(fptr1);
  17808. if(ch!=EOF)
  17809. {
  17810. // copy all contents to the temporary file except the specific line
  17811. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  17812. {
  17813. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17814. if(str[0]=='\0')
  17815. {
  17816. break;
  17817. }
  17818. //TempStopTransaction格式: 槍號,StopTransaction封包
  17819. strncpy(connectorStr, str, 1);
  17820. if(atoi(connectorStr) != (gun_index+1))
  17821. {
  17822. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  17823. fclose(fptr1);
  17824. return ;
  17825. }
  17826. //random_uuid(guid);
  17827. strncpy(guid, str+6, 36); //copy guid
  17828. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  17829. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  17830. {
  17831. //DEBUG_INFO("StopTransaction mapitem pass\n");
  17832. }
  17833. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  17834. OCPP_insert_transaction_msg(NO, str);
  17835. memset(str,0,ARRAY_SIZE(str));
  17836. }
  17837. }
  17838. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  17839. fclose(fptr1);
  17840. remove(TempStopTransaction); // remove the original file
  17841. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17842. }
  17843. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  17844. {
  17845. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  17846. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  17847. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  17848. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  17849. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  17850. }
  17851. int GetWebSocketPingInterval(void)
  17852. {
  17853. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  17854. }
  17855. int GetServerSign(void)
  17856. {
  17857. return server_sign;
  17858. }
  17859. uint8_t GetOcppSecurityProfile()
  17860. {
  17861. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  17862. }
  17863. void GetOcppChargerBoxId(uint8_t *data)
  17864. {
  17865. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17866. }
  17867. void GetOcppSecurityPassword(uint8_t *data)
  17868. {
  17869. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17870. }
  17871. void SetOcppVersion(uint8_t *version)
  17872. {
  17873. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  17874. DEBUG_INFO("ocpp version: %s\n", version);
  17875. if(strstr((char*)version, "ocpp1.6") != NULL)
  17876. {
  17877. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  17878. }
  17879. else if(strstr((char*)version, "ocpp2.0") != NULL)
  17880. {
  17881. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  17882. system("pkill OcppBackend");
  17883. }
  17884. }
  17885. void SetServerSign(int value)
  17886. {
  17887. server_sign = value;
  17888. }
  17889. int GetBootNotificationInterval(void)
  17890. {
  17891. return BootNotificationInterval;
  17892. }
  17893. int GetInternetConn(void)
  17894. {
  17895. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  17896. }
  17897. int GetBackendConnectionTimeout(void)
  17898. {
  17899. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  17900. }
  17901. int isConnectorInitMode(int gun_index)
  17902. {
  17903. int tempIndex = 0;
  17904. int result = TRUE;
  17905. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17906. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17907. {
  17908. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17909. {
  17910. tempIndex = ((gun_index==2) ? 1: 0);
  17911. }
  17912. else
  17913. {
  17914. tempIndex = gun_index;
  17915. }
  17916. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17917. {
  17918. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  17919. {
  17920. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17921. } //end of the same index
  17922. }//end of for CHAdeMO_QUANTITY
  17923. }
  17924. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17925. {
  17926. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17927. {
  17928. tempIndex = ((gun_index==2) ? 1: 0);
  17929. }
  17930. else
  17931. {
  17932. tempIndex = gun_index;
  17933. }
  17934. for (int index = 0; index < CCS_QUANTITY; index++)
  17935. {
  17936. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17937. {
  17938. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17939. } //end of the same index
  17940. } // end of for CCS_QUANTITY
  17941. }
  17942. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17943. {
  17944. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17945. {
  17946. tempIndex = ((gun_index==2) ? 1: 0);
  17947. }
  17948. else
  17949. {
  17950. tempIndex = gun_index;
  17951. }
  17952. for (int index = 0; index < GB_QUANTITY; index++)
  17953. {
  17954. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17955. {
  17956. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17957. } //end of the same index
  17958. } // end of for GB_QUANTITY
  17959. }
  17960. else if(gunType[gun_index] == GUN_TYPE_DO)
  17961. {
  17962. tempIndex = gun_index;
  17963. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17964. {
  17965. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17966. {
  17967. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17968. } //end of the same index
  17969. }
  17970. }
  17971. else
  17972. {
  17973. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17974. {
  17975. tempIndex = 2;
  17976. }
  17977. else
  17978. {
  17979. tempIndex = gun_index;
  17980. }
  17981. for (int index = 0; index < AC_QUANTITY; index++)
  17982. {
  17983. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17984. {
  17985. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17986. }//end of the same index
  17987. }//end of for AC_QUANTITY
  17988. }
  17989. return result;
  17990. }
  17991. void refreshProcDogTimer()
  17992. {
  17993. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  17994. }
  17995. void InitialSystemValue(void)
  17996. {
  17997. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  17998. locallistVersion=0;
  17999. BootNotificationInterval = 0;
  18000. authorizeRetryTimes = 0;
  18001. GunStatusInterval = 10;
  18002. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18003. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18004. //Hear Beat
  18005. HeartBeatWithNOResponse = 0;
  18006. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18007. FirstHeartBeat = 0;
  18008. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18009. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18010. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18011. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18012. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18013. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18014. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18015. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18016. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18017. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18018. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18019. //Status && ConnectorPlugIn Setting
  18020. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18021. {
  18022. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18023. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18024. }
  18025. for (int index = 0; index < CCS_QUANTITY; index++)
  18026. {
  18027. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18028. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18029. }
  18030. for (int index = 0; index < GB_QUANTITY; index++)
  18031. {
  18032. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18033. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18034. }
  18035. for (int index = 0; index < AC_QUANTITY; index++)
  18036. {
  18037. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18038. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18039. }
  18040. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18041. {
  18042. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18043. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18044. }
  18045. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18046. {
  18047. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18048. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18049. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18050. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18051. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18052. }
  18053. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18054. refreshStartTimer(&clientTime.Heartbeat);
  18055. sleep(1);
  18056. }
  18057. void LWS_Send(char *str)
  18058. {
  18059. //=====================================================
  18060. // Check InternetConn 0: disconnected, 1: connected
  18061. //====================================================
  18062. if(GetOcppConnStatus() == 0)
  18063. {
  18064. DEBUG_INFO("offline now !!!\n");
  18065. return;
  18066. }
  18067. // Only disable isWebsocketSendable operation initiated by charger
  18068. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18069. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18070. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18071. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18072. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18073. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18074. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18075. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18076. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18077. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18078. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18079. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18080. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18081. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18082. {
  18083. isWebsocketSendable = 0;
  18084. }
  18085. pthread_mutex_lock(&lock_send);
  18086. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18087. sprintf((char *)SendBuffer, "%s", str);
  18088. SendBufLen = strlen(str);
  18089. pthread_mutex_unlock(&lock_send);
  18090. lws_callback_on_writable(wsi_client);
  18091. //lws_service(context, 0);
  18092. //sleep(1);
  18093. }
  18094. void LWS_SendNow(char *str)
  18095. {
  18096. //=====================================================
  18097. // Check InternetConn 0: disconnected, 1: connected
  18098. //====================================================
  18099. if(GetOcppConnStatus() == 0)
  18100. {
  18101. DEBUG_INFO("offline now !!!\n");
  18102. return;
  18103. }
  18104. // Only disable isWebsocketSendable operation initiated by charger
  18105. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18106. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18107. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18108. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18109. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18110. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18111. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18112. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18113. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18114. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18115. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18116. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18117. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18118. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18119. {
  18120. isWebsocketSendable = 0;
  18121. }
  18122. pthread_mutex_lock(&lock_send);
  18123. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18124. sprintf((char *)SendBuffer, "%s", str);
  18125. SendBufLen = strlen(str);
  18126. pthread_mutex_unlock(&lock_send);
  18127. lws_callback_on_writable(wsi_client);
  18128. lws_service(context, 0);
  18129. //sleep(1);
  18130. }