MessageHandler.c 910 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775
  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 result = FAIL;
  8340. char keystr[40]={0};
  8341. char valuestr[501]={0}; //value should be limited in 500 bytes
  8342. char comfirmstr[20]={0};
  8343. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8344. json_object *ChangeConfiguration;
  8345. ChangeConfiguration = json_tokener_parse(payload);
  8346. if(!is_error(ChangeConfiguration))
  8347. {
  8348. // Required data
  8349. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8350. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8351. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8352. {
  8353. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8354. }
  8355. else
  8356. {
  8357. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8358. }
  8359. }
  8360. json_object_put(ChangeConfiguration);
  8361. if((uuid==NULL) || (payload ==NULL) || (strlen(valuestr)<=0))
  8362. {
  8363. DEBUG_ERROR("Payload is null or not accepted.\n");
  8364. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8365. }
  8366. else
  8367. {
  8368. int status = setKeyValue(keystr, valuestr);
  8369. switch(status)
  8370. {
  8371. case ConfigurationStatus_Accepted:
  8372. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8373. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8374. StoreConfigurationTable();
  8375. break;
  8376. case RebootRequired:
  8377. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8378. StoreConfigurationTable();
  8379. break;
  8380. case NotSupported:
  8381. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8382. break;
  8383. case ConfigurationStatus_Rejected:
  8384. default:
  8385. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8386. break;
  8387. }
  8388. }
  8389. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8390. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8391. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8392. {
  8393. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8394. SetOcppConnStatus(FALSE);
  8395. }
  8396. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8397. {
  8398. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8399. }
  8400. return result;
  8401. }
  8402. int handleClearCacheRequest(char *uuid, char *payload)
  8403. {
  8404. mtrace();
  8405. int result = FAIL;
  8406. char comfirmstr[20];
  8407. char rmFileCmd[100]={0};
  8408. struct stat stats;
  8409. DEBUG_INFO("handleClearCacheRequest...\n");
  8410. stat("/Storage/OCPP", &stats);
  8411. // Check for directory existence
  8412. if (S_ISDIR(stats.st_mode) == 1)
  8413. {}
  8414. else
  8415. {
  8416. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8417. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  8418. system(rmFileCmd);
  8419. }
  8420. if(OCPP_cleanLocalCache())
  8421. {
  8422. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8423. }
  8424. else
  8425. {
  8426. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8427. }
  8428. sendClearCacheConfirmation(uuid, comfirmstr);
  8429. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8430. return result;
  8431. }
  8432. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8433. {
  8434. mtrace();
  8435. int result = FAIL;
  8436. int resultRename;
  8437. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8438. char chargingProfilePurposeStr[26]={0};
  8439. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8440. char tempchargingProfilePurposeStr[26]={0};
  8441. char str[100]={0};
  8442. char fname[200]={0};
  8443. char comfirmstr[20]={0};
  8444. char word[1600]={0};
  8445. int clearflag = FALSE;
  8446. int chargingProfileIdIsNULL = FALSE;
  8447. int connectorIsNULL = FALSE;
  8448. int chargingProfilePurposeIsNULL = FALSE;
  8449. int stackLevelIsNULL = FALSE;
  8450. //int GotoEnd = FALSE;
  8451. FILE *fptr1, *fptr2;
  8452. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  8453. int n_chargingProfile=0;
  8454. int isEmptyFile = FALSE;
  8455. char sLineWord[1600]={0};
  8456. char chargingProfiles[10][100]={0};
  8457. int ChargeProfileCount = 0;
  8458. int ch;
  8459. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8460. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8461. json_object *ClearChargingProfile;
  8462. ClearChargingProfile = json_tokener_parse(payload);
  8463. if(!is_error(ClearChargingProfile))
  8464. {
  8465. // Optional data
  8466. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8467. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8468. else
  8469. chargingProfileIdIsNULL = TRUE;
  8470. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8471. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8472. else
  8473. connectorIsNULL = TRUE;
  8474. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8475. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8476. else
  8477. chargingProfilePurposeIsNULL = TRUE;
  8478. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8479. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8480. else
  8481. stackLevelIsNULL = TRUE;
  8482. }
  8483. json_object_put(ClearChargingProfile);
  8484. if(connectorIsNULL == FALSE)
  8485. {
  8486. switch(connectorIdInt)
  8487. {
  8488. case 0:
  8489. if(chargingProfilePurposeIsNULL == TRUE)
  8490. {
  8491. int l = 0;
  8492. strcpy(fname, ChargePointMaxProfile_JSON);
  8493. if((access(fname,F_OK))!=-1)
  8494. {
  8495. strcpy(chargingProfiles[l], fname);
  8496. l = l + 1;
  8497. }
  8498. strcpy(fname, TxDefaultProfile_0_JSON);
  8499. if((access(fname,F_OK))!=-1)
  8500. {
  8501. strcpy(chargingProfiles[l], fname);
  8502. l = l + 1;
  8503. }
  8504. ChargeProfileCount = l;
  8505. }
  8506. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8507. {
  8508. strcpy(fname, ChargePointMaxProfile_JSON);
  8509. if((access(fname,F_OK))!=-1)
  8510. {
  8511. strcpy(chargingProfiles[0], fname);
  8512. ChargeProfileCount = 1;
  8513. }
  8514. }
  8515. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8516. {
  8517. strcpy(fname, TxDefaultProfile_0_JSON);
  8518. if((access(fname,F_OK))!=-1)
  8519. {
  8520. strcpy(chargingProfiles[0], fname);
  8521. ChargeProfileCount = 1;
  8522. }
  8523. }
  8524. break;
  8525. default:
  8526. if(chargingProfilePurposeIsNULL == TRUE)
  8527. {
  8528. int m = 0;
  8529. memset(fname, 0, ARRAY_SIZE(fname));
  8530. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8531. if((access(fname,F_OK))!=-1)
  8532. {
  8533. strcpy(chargingProfiles[m], fname);
  8534. m = m + 1;
  8535. }
  8536. memset(fname, 0, ARRAY_SIZE(fname));
  8537. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8538. if((access(fname,F_OK))!=-1)
  8539. {
  8540. strcpy(chargingProfiles[m], fname);
  8541. m = m + 1;
  8542. }
  8543. ChargeProfileCount = m;
  8544. }
  8545. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8546. {
  8547. //strcpy(fname, TxDefaultProfile_1_JSON);
  8548. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8549. if((access(fname,F_OK))!=-1)
  8550. {
  8551. strcpy(chargingProfiles[0], fname);
  8552. ChargeProfileCount = 1;
  8553. }
  8554. }
  8555. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8556. {
  8557. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8558. if((access(fname,F_OK))!=-1)
  8559. {
  8560. strcpy(chargingProfiles[0], fname);
  8561. ChargeProfileCount = 1;
  8562. }
  8563. //strcpy(fname, TxProfile_1_JSON);
  8564. }
  8565. //strcpy(fname, ChargePointMaxProfile_JSON );
  8566. break;
  8567. }
  8568. }
  8569. else // Check all Charging Profiles
  8570. {
  8571. int i = 0;
  8572. char fnametemp[200]={0};
  8573. ChargeProfileCount = 0;
  8574. //Check ChargePointMaxProfile.json exit
  8575. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8576. {
  8577. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  8578. i = i + 1;
  8579. }
  8580. //Check TxDefaultProfile_0.json exit
  8581. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8582. {
  8583. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  8584. i = i + 1;
  8585. }
  8586. //Check TxDefaultProfile_%d.json
  8587. for(int j=1; j <= gunTotalNumber; j++)
  8588. {
  8589. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8590. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8591. if((access(fnametemp,F_OK))!=-1)
  8592. {
  8593. strcpy(chargingProfiles[i], fnametemp);
  8594. i = i + 1;
  8595. }
  8596. }
  8597. //Check TxProfile_%d.json
  8598. for(int j=1; j <= gunTotalNumber; j++)
  8599. {
  8600. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8601. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8602. if((access(fnametemp,F_OK))!=-1)
  8603. {
  8604. strcpy(chargingProfiles[i], fnametemp);
  8605. i = i + 1;
  8606. }
  8607. }
  8608. ChargeProfileCount = i;
  8609. }// End connectorIsNULL is TRUE
  8610. if(ChargeProfileCount == 0)
  8611. {
  8612. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8613. goto end;
  8614. }
  8615. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8616. {
  8617. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8618. goto end;
  8619. }
  8620. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8621. {
  8622. memset(str, 0, ARRAY_SIZE(str));
  8623. // clear temp file
  8624. sprintf(str,"rm -f %s",temp);
  8625. system(str);
  8626. for(int k=0; k < ChargeProfileCount; k++)
  8627. {
  8628. memset(str, 0, ARRAY_SIZE(str));
  8629. //clear file in C
  8630. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8631. system(str);
  8632. }
  8633. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8634. goto end;
  8635. }
  8636. else if(connectorIsNULL == TRUE)
  8637. {
  8638. for(int k=0; k < ChargeProfileCount; k++)
  8639. {
  8640. fptr1 = fopen(chargingProfiles[k], "r");
  8641. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  8642. //Check Charging Profile Count
  8643. while(fscanf(fptr1, "%s", word) != EOF)
  8644. {
  8645. //DEBUG_INFO("word=%s\n",word);
  8646. if(strstr(word, "chargingProfileId")!= NULL)
  8647. {
  8648. //DEBUG_INFO("test chargingProfileId \n");
  8649. n_chargingProfile = n_chargingProfile + 1;
  8650. //DEBUG_INFO("chargingProfileId Found\n");
  8651. }
  8652. }
  8653. rewind(fptr1);
  8654. //search Charging Profile Element
  8655. //int i= 0;
  8656. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8657. {
  8658. json_object *tmpProfilee;
  8659. tmpProfilee = json_tokener_parse(sLineWord);
  8660. if(!is_error(tmpProfilee))
  8661. {
  8662. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8663. {
  8664. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8665. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8666. }
  8667. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8668. {
  8669. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8670. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8671. }
  8672. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8673. {
  8674. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8675. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8676. }
  8677. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8678. {
  8679. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8680. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8681. }
  8682. }
  8683. json_object_put(tmpProfilee);
  8684. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8685. {
  8686. //------- not write to fptr2-------//
  8687. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8688. //clearflag = TRUE;
  8689. }
  8690. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8691. {
  8692. //------- not write to fptr2-------//
  8693. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8694. }
  8695. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8696. {
  8697. //------- not write to fptr2-------//
  8698. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8699. }
  8700. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8701. {
  8702. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8703. }
  8704. else
  8705. {
  8706. fprintf(fptr2, sLineWord);//writing data into file
  8707. }
  8708. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8709. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8710. if(clearflag == TRUE)
  8711. {
  8712. fclose(fptr1);
  8713. fclose(fptr2);
  8714. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8715. system(str);
  8716. // clear temp file
  8717. sprintf(str,"rm -f %s",temp);
  8718. system(str);
  8719. }
  8720. else
  8721. {
  8722. fclose(fptr1);
  8723. fclose(fptr2);
  8724. memset(str, 0, ARRAY_SIZE(str));
  8725. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8726. system(str);
  8727. resultRename = rename(temp, chargingProfiles[k]);
  8728. if(resultRename == 0)
  8729. {
  8730. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8731. }
  8732. else
  8733. {
  8734. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8735. }
  8736. if(comfirmstr[0]== 0)
  8737. {
  8738. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8739. }
  8740. //Check chargingProfile is empty file
  8741. /*------ Read the file ----------------*/
  8742. fptr1=fopen(chargingProfiles[k],"r");
  8743. ch=fgetc(fptr1);
  8744. rewind(fptr1);
  8745. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8746. if(ch!=EOF)
  8747. {
  8748. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8749. {
  8750. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8751. if(sLineWord[0]=='\0')
  8752. {
  8753. isEmptyFile = TRUE;
  8754. break;
  8755. }
  8756. else
  8757. {
  8758. isEmptyFile = FALSE;
  8759. break;
  8760. }
  8761. }
  8762. }
  8763. else
  8764. isEmptyFile = TRUE;
  8765. fclose(fptr1);
  8766. if(isEmptyFile == TRUE)
  8767. {
  8768. memset(str, 0, ARRAY_SIZE(str));
  8769. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8770. system(str);
  8771. }
  8772. }
  8773. }// End of while(int k=0; k < ChargePointCount; k++)
  8774. }
  8775. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8776. {
  8777. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8778. for(int k=0; k < ChargeProfileCount; k++)
  8779. {
  8780. fptr1 = fopen(chargingProfiles[k], "r");
  8781. fptr2 = fopen(temp, "w+");
  8782. //Check Charging Profile Count
  8783. while(fscanf(fptr1, "%s", word) != EOF)
  8784. {
  8785. //DEBUG_INFO("word=%s\n",word);
  8786. if(strstr(word, "chargingProfileId")!= NULL)
  8787. {
  8788. n_chargingProfile = n_chargingProfile + 1;
  8789. }
  8790. }
  8791. rewind(fptr1);
  8792. //search Charging Profile Element
  8793. //int i= 0;
  8794. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8795. {
  8796. json_object *tmpProfilee;
  8797. tmpProfilee = json_tokener_parse(sLineWord);
  8798. if(!is_error(tmpProfilee))
  8799. {
  8800. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8801. {
  8802. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8803. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8804. }
  8805. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8806. {
  8807. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8808. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8809. }
  8810. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8811. {
  8812. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8813. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8814. }
  8815. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8816. {
  8817. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8818. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8819. }
  8820. }
  8821. json_object_put(tmpProfilee);
  8822. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8823. {
  8824. //------- not write to fptr2-------//
  8825. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8826. //clearflag = TRUE;
  8827. }
  8828. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8829. {
  8830. //------- not write to fptr2-------//
  8831. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8832. }
  8833. else if(stackLevelIsNULL == TRUE)
  8834. {
  8835. //Clear Whole File
  8836. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8837. clearflag = TRUE;
  8838. break;
  8839. }
  8840. else
  8841. {
  8842. fprintf(fptr2, sLineWord);//writing data into file
  8843. }
  8844. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8845. }
  8846. if(clearflag == TRUE)
  8847. {
  8848. fclose(fptr1);
  8849. fclose(fptr2);
  8850. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8851. system(str);
  8852. // clear temp file
  8853. sprintf(str,"rm -f %s",temp);
  8854. system(str);
  8855. }
  8856. else
  8857. {
  8858. fclose(fptr1);
  8859. fclose(fptr2);
  8860. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8861. system(str);
  8862. resultRename = rename(temp, chargingProfiles[k]);
  8863. if(resultRename == 0)
  8864. {
  8865. DEBUG_INFO("File ChargingProfile renamed successfully");
  8866. }
  8867. else
  8868. {
  8869. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8870. }
  8871. if(comfirmstr[0]== 0)
  8872. {
  8873. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8874. }
  8875. //Check chargingProfile is empty file
  8876. /*------ Read the file ----------------*/
  8877. fptr1=fopen(chargingProfiles[k],"r");
  8878. ch=fgetc(fptr1);
  8879. rewind(fptr1);
  8880. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8881. if(ch!=EOF)
  8882. {
  8883. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8884. {
  8885. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8886. if(sLineWord[0]=='\0')
  8887. {
  8888. isEmptyFile = TRUE;
  8889. break;
  8890. }
  8891. else
  8892. {
  8893. isEmptyFile = FALSE;
  8894. break;
  8895. }
  8896. }
  8897. }
  8898. else
  8899. isEmptyFile = TRUE;
  8900. fclose(fptr1);
  8901. if(isEmptyFile == TRUE)
  8902. {
  8903. memset(str, 0, ARRAY_SIZE(str));
  8904. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8905. system(str);
  8906. }
  8907. /*------- End of reading ---------------*/
  8908. }
  8909. } // while(int k=0; k < ChargeProfileCount; k++)
  8910. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8911. end:
  8912. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8913. {
  8914. if(connectorIdInt == 0)
  8915. {
  8916. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8917. {
  8918. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  8919. }
  8920. }
  8921. else
  8922. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  8923. }
  8924. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8925. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8926. return result;
  8927. }
  8928. void createFirmwareVersionByDataTransfer(void)
  8929. {
  8930. json_object *FirmwareDataTransfer = json_object_new_object();
  8931. // AC & DC model
  8932. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8933. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8934. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8935. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8936. // DC model
  8937. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8938. {
  8939. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8940. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8941. (gunType[3] != GUN_TYPE_UNKNOWN))
  8942. {
  8943. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8944. }
  8945. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8946. {
  8947. // DS DM DW
  8948. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8949. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8950. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8951. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8952. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8953. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8954. }
  8955. else
  8956. {
  8957. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8958. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8959. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8960. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8961. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8962. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8963. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8964. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8965. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8966. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8967. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8968. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8969. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8970. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8971. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8972. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8973. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8974. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8975. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8976. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8977. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8978. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8979. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8980. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8981. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8982. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8983. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8984. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8985. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8986. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8987. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8988. }
  8989. }
  8990. // 4G model
  8991. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8992. {
  8993. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8994. }
  8995. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8996. json_object_put(FirmwareDataTransfer);
  8997. }
  8998. int handleDataTransferRequest(char *uuid, char *payload)
  8999. {
  9000. mtrace();
  9001. json_object *response = json_object_new_object();
  9002. int result = FAIL;
  9003. char tempvendorId[255]={0};
  9004. char tempmessageId[50]={0};
  9005. char tempdata[512]={0};
  9006. char message[2048]={0};
  9007. DEBUG_INFO("handleDataTransferRequest...\n");
  9008. if((uuid != NULL) && (payload != NULL))
  9009. {
  9010. json_object *DataTransfer;
  9011. DataTransfer = json_tokener_parse(payload);
  9012. if(!is_error(DataTransfer))
  9013. {
  9014. // Required data
  9015. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9016. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9017. // Optional data
  9018. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9019. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9020. if(json_object_object_get(DataTransfer, "data") != NULL)
  9021. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9022. result = PASS;
  9023. }
  9024. json_object_put(DataTransfer);
  9025. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9026. {
  9027. // Send all moudle firmware version on EVSE
  9028. createFirmwareVersionByDataTransfer();
  9029. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9030. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9031. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9032. json_object_put(response);
  9033. }
  9034. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9035. {
  9036. system("/usr/bin/run_tmate_restart.sh &");
  9037. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9038. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9039. json_object_put(response);
  9040. }
  9041. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9042. {
  9043. json_object *data;
  9044. data = json_tokener_parse(tempdata);
  9045. if(!is_error(data))
  9046. {
  9047. 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))
  9048. {
  9049. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9050. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9051. if(json_object_object_get(data, "SOC") != NULL)
  9052. {
  9053. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9054. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9055. }
  9056. if(json_object_object_get(data, "Energy") != NULL)
  9057. {
  9058. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9059. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9060. }
  9061. if(json_object_object_get(data, "Duration") != NULL)
  9062. {
  9063. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9064. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9065. }
  9066. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9067. }
  9068. else
  9069. {
  9070. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9071. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9072. }
  9073. }
  9074. else
  9075. {
  9076. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9077. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9078. }
  9079. json_object_put(data);
  9080. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9081. json_object_put(response);
  9082. }
  9083. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9084. {
  9085. json_object *data;
  9086. data = json_tokener_parse(tempdata);
  9087. if(!is_error(data))
  9088. {
  9089. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9090. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9091. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9092. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9093. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9094. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9095. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9096. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9097. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9098. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9099. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9100. }
  9101. else
  9102. {
  9103. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9104. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9105. }
  9106. json_object_put(data);
  9107. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9108. json_object_put(response);
  9109. }
  9110. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9111. {
  9112. json_object *data;
  9113. data = json_tokener_parse(tempdata);
  9114. if(!is_error(data))
  9115. {
  9116. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9117. if(json_object_object_get(data, "idToken") != NULL)
  9118. {
  9119. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9120. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9121. }
  9122. if(json_object_object_get(data, "price") != NULL)
  9123. {
  9124. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9125. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9126. }
  9127. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9128. }
  9129. else
  9130. {
  9131. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9132. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9133. }
  9134. json_object_put(data);
  9135. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9136. json_object_put(response);
  9137. }
  9138. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9139. {
  9140. json_object *data;
  9141. data = json_tokener_parse(tempdata);
  9142. if(!is_error(data))
  9143. {
  9144. if(json_object_object_get(data, "txId") != NULL)
  9145. {
  9146. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9147. for(int idx = 0;idx<gunTotalNumber;idx++)
  9148. {
  9149. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9150. {
  9151. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9152. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9153. if(json_object_object_get(data, "description") != NULL)
  9154. {
  9155. // California pricing V1.0
  9156. DEBUG_INFO("California pricing V1.0\n");
  9157. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9158. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9159. }
  9160. else
  9161. {
  9162. // California pricing V1.1
  9163. DEBUG_INFO("California pricing V1.1\n");
  9164. if(json_object_object_get(data, "timestamp") != NULL)
  9165. {
  9166. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9167. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9168. }
  9169. if(json_object_object_get(data, "meterValue") != NULL)
  9170. {
  9171. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9172. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9173. }
  9174. if(json_object_object_get(data, "cost") != NULL)
  9175. {
  9176. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9177. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9178. }
  9179. if(json_object_object_get(data, "state") != NULL)
  9180. {
  9181. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9182. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9183. }
  9184. if(json_object_object_get(data, "chargingPrice") != NULL)
  9185. {
  9186. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9187. {
  9188. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9189. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9190. }
  9191. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9192. {
  9193. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9194. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9195. }
  9196. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9197. {
  9198. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9199. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9200. }
  9201. }
  9202. if(json_object_object_get(data, "idlePrice") != NULL)
  9203. {
  9204. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9205. {
  9206. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9207. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9208. }
  9209. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9210. {
  9211. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9212. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9213. }
  9214. }
  9215. if(json_object_object_get(data, "nextPeriod") != NULL)
  9216. {
  9217. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9218. {
  9219. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9220. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9221. }
  9222. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9223. {
  9224. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9225. {
  9226. 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")));
  9227. 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"));
  9228. }
  9229. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9230. {
  9231. 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")));
  9232. 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"));
  9233. }
  9234. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9235. {
  9236. 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")));
  9237. 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"));
  9238. }
  9239. }
  9240. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9241. {
  9242. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9243. {
  9244. 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")));
  9245. 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"));
  9246. }
  9247. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9248. {
  9249. 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")));
  9250. 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"));
  9251. }
  9252. }
  9253. }
  9254. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9255. {
  9256. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9257. {
  9258. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9259. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9260. }
  9261. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9262. {
  9263. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9264. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9265. }
  9266. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9267. {
  9268. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9269. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9270. }
  9271. }
  9272. }
  9273. }
  9274. }
  9275. }
  9276. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9277. }
  9278. else
  9279. {
  9280. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9281. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9282. }
  9283. json_object_put(data);
  9284. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9285. json_object_put(response);
  9286. }
  9287. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9288. {
  9289. json_object *data;
  9290. data = json_tokener_parse(tempdata);
  9291. if(!is_error(data))
  9292. {
  9293. if(json_object_object_get(data, "txId") != NULL)
  9294. {
  9295. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9296. for(int idx = 0;idx<gunTotalNumber;idx++)
  9297. {
  9298. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9299. {
  9300. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9301. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9302. if(json_object_object_get(data, "description") != NULL)
  9303. {
  9304. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9305. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9306. }
  9307. }
  9308. }
  9309. }
  9310. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9311. }
  9312. else
  9313. {
  9314. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9315. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9316. }
  9317. json_object_put(data);
  9318. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9319. json_object_put(response);
  9320. }
  9321. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9322. {
  9323. json_object *data;
  9324. data = json_tokener_parse(tempdata);
  9325. if(!is_error(data))
  9326. {
  9327. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9328. if(json_object_object_get(data, "Content_Type") != NULL)
  9329. {
  9330. 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))
  9331. {
  9332. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9333. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9334. {
  9335. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9336. }
  9337. }
  9338. else
  9339. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9340. }
  9341. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9342. }
  9343. else
  9344. {
  9345. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9346. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9347. }
  9348. json_object_put(data);
  9349. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9350. json_object_put(response);
  9351. }
  9352. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  9353. {
  9354. json_object *data;
  9355. data = json_tokener_parse(tempdata);
  9356. if(!is_error(data))
  9357. {
  9358. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9359. if(json_object_object_get(data, "Page_Index") != NULL)
  9360. {
  9361. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9362. }
  9363. if(json_object_object_get(data, "Duration") != NULL)
  9364. {
  9365. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9366. }
  9367. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  9368. }
  9369. else
  9370. {
  9371. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9372. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9373. }
  9374. json_object_put(data);
  9375. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9376. json_object_put(response);
  9377. }
  9378. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9379. {
  9380. json_object *data;
  9381. data = json_tokener_parse(tempdata);
  9382. if(!is_error(data))
  9383. {
  9384. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9385. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9386. {
  9387. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9388. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9389. else
  9390. {
  9391. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9392. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9393. }
  9394. }
  9395. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9396. {
  9397. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9398. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9399. else
  9400. {
  9401. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9402. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9403. }
  9404. }
  9405. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9406. {
  9407. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9408. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9409. else
  9410. {
  9411. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9412. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9413. }
  9414. }
  9415. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9416. {
  9417. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9418. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9419. else
  9420. {
  9421. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9422. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9423. }
  9424. }
  9425. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9426. {
  9427. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9428. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9429. else
  9430. {
  9431. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9432. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9433. }
  9434. }
  9435. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9436. {
  9437. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9438. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9439. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9440. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9441. else
  9442. {
  9443. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9444. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9445. }
  9446. }
  9447. if(json_object_object_get(data, "isAuthentication") != NULL)
  9448. {
  9449. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9450. {
  9451. case 0:
  9452. case 1:
  9453. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9454. break;
  9455. default:
  9456. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9457. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9458. break;
  9459. }
  9460. }
  9461. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9462. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9463. }
  9464. else
  9465. {
  9466. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9467. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9468. }
  9469. json_object_put(data);
  9470. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9471. json_object_put(response);
  9472. }
  9473. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  9474. {
  9475. json_object *data;
  9476. data = json_tokener_parse(tempdata);
  9477. if(!is_error(data))
  9478. {
  9479. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9480. {
  9481. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  9482. {
  9483. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9484. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9485. }
  9486. else
  9487. {
  9488. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9489. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  9490. }
  9491. }
  9492. else
  9493. {
  9494. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9495. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9496. }
  9497. }
  9498. else
  9499. {
  9500. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9501. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9502. }
  9503. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9504. json_object_put(response);
  9505. }
  9506. else
  9507. {
  9508. // Can not find valid message id
  9509. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9510. }
  9511. }
  9512. else
  9513. {
  9514. // Payload is null
  9515. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9516. }
  9517. LWS_Send(message);
  9518. return result;
  9519. }
  9520. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9521. {
  9522. mtrace();
  9523. int result = FAIL;
  9524. int connectorIdInt, durationInt;
  9525. char chargingRateUnitStr[4]={0};
  9526. char comfirmstr[20];
  9527. int confirmPeriods = 0;
  9528. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9529. json_object *GetCompositeSchedule;
  9530. GetCompositeSchedule = json_tokener_parse(payload);
  9531. if(!is_error(GetCompositeSchedule))
  9532. {
  9533. // Required data
  9534. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9535. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9536. else
  9537. connectorIdInt = -1;
  9538. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9539. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9540. else
  9541. durationInt = 86400;
  9542. // Optional data
  9543. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9544. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9545. }
  9546. json_object_put(GetCompositeSchedule);
  9547. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9548. if((connectorIdInt == 0) ||
  9549. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9550. {
  9551. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9552. struct StructChargingProfile tmpProfile[1];
  9553. if(strstr(chargingRateUnitStr, "W") != NULL)
  9554. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9555. else
  9556. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9557. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9558. {
  9559. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9560. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9561. }
  9562. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9563. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9564. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9565. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9566. {
  9567. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9568. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9569. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9570. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9571. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9572. {
  9573. confirmPeriods = idx;
  9574. break;
  9575. }
  9576. }
  9577. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9578. {
  9579. confirmPeriods += 1;
  9580. }
  9581. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9582. }
  9583. else
  9584. {
  9585. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9586. }
  9587. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9588. return result;
  9589. }
  9590. int handleGetConfigurationRequest(char *uuid, char *payload)
  9591. {
  9592. mtrace();
  9593. int result = FAIL;
  9594. int MaxKeySupported = 0;
  9595. int n_keys = 0;
  9596. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9597. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9598. json_object *GetConfiguration;
  9599. GetConfiguration = json_tokener_parse(payload);
  9600. if(!is_error(GetConfiguration))
  9601. {
  9602. // Optional data
  9603. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9604. {
  9605. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9606. {
  9607. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9608. n_keys = idx + 1;
  9609. }
  9610. }
  9611. }
  9612. json_object_put(GetConfiguration);
  9613. UnknownKeynum = 0;
  9614. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9615. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9616. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9617. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9618. if(n_keys != 0)
  9619. {
  9620. for(int i=0;i<n_keys;i++)
  9621. {
  9622. getKeyValue(requestKey[i]);
  9623. }
  9624. }
  9625. else
  9626. {
  9627. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9628. getKeyValue("");
  9629. }
  9630. processUnkownKey();
  9631. sendGetConfigurationConfirmation(uuid);
  9632. return result;
  9633. }
  9634. static char fnamePlusPath[100]={0};
  9635. static char fnamePWithNoPath[60]={0};
  9636. void checkUploadLog(void)
  9637. {
  9638. FILE *fp;
  9639. /* Open the command for reading. */
  9640. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9641. if (fp == NULL) {
  9642. DEBUG_WARN("Failed to run command\n" );
  9643. exit(1);
  9644. }
  9645. int ftppathlen = 0;
  9646. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9647. int i = 0;
  9648. /* Read the output a line at a time - output it. */
  9649. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9650. if(i==0)
  9651. {
  9652. ftppathlen = strlen(fnamePlusPath);
  9653. DEBUG_INFO("%s\n", fnamePlusPath);
  9654. fnamePlusPath[ftppathlen]='\0';
  9655. break;
  9656. }
  9657. i= i+1;
  9658. }
  9659. /* close */
  9660. pclose(fp);
  9661. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9662. {
  9663. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9664. {
  9665. fnamePlusPath[k]='\0';
  9666. }
  9667. }
  9668. i=1;
  9669. //char fname[60]={0};
  9670. while(i < ftppathlen)
  9671. {
  9672. int len=ftppathlen-i;
  9673. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9674. {
  9675. DEBUG_INFO("compare '/' all right\n");
  9676. break;
  9677. }
  9678. i=i+1;
  9679. }
  9680. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9681. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9682. fnamePWithNoPath[i+1] = '\0';
  9683. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9684. {
  9685. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9686. {
  9687. fnamePWithNoPath[j]='\0';
  9688. }
  9689. }
  9690. FILE* fp1 = fopen(fnamePlusPath, "r");
  9691. if (fp1)
  9692. {
  9693. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9694. // file exists
  9695. fclose(fp1);
  9696. }
  9697. else
  9698. {
  9699. // file doesn't exist
  9700. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9701. }
  9702. }
  9703. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9704. {
  9705. mtrace();
  9706. int result = FAIL;
  9707. time_t CurrentTime;
  9708. struct tm *tm;
  9709. pthread_t th_Status;
  9710. CurrentTime = time(NULL);
  9711. tm = localtime(&CurrentTime);
  9712. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  9713. 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);
  9714. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9715. if(!interLock.isGetDiagnosticGoing)
  9716. {
  9717. interLock.isGetDiagnosticGoing = 1;
  9718. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9719. sleep(1);
  9720. }
  9721. else
  9722. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9723. return result;
  9724. }
  9725. void* GetDiagnosticsProcess(void* data)
  9726. {
  9727. pthread_detach(pthread_self());
  9728. mtrace();
  9729. int retriesInt=0, retryIntervalInt=0;
  9730. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9731. 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};
  9732. int port=0;
  9733. int isSuccess = FALSE;
  9734. char cmdBuf[2048];
  9735. struct tm *tmNow;
  9736. time_t CurrentTime;
  9737. struct tm tmStart;
  9738. struct tm tmStop;
  9739. CurrentTime = time(NULL);
  9740. tmNow=localtime(&CurrentTime);
  9741. uint16_t targetYear, targetMonth;
  9742. json_object *GetDiagnostics;
  9743. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9744. GetDiagnostics = json_tokener_parse(data);
  9745. if(!is_error(GetDiagnostics))
  9746. {
  9747. // Required data
  9748. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9749. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9750. // Optional data
  9751. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9752. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9753. else
  9754. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9755. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9756. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9757. else
  9758. retryIntervalInt = 30;
  9759. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9760. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9761. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9762. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9763. }
  9764. json_object_put(GetDiagnostics);
  9765. // Pack log to compress file
  9766. 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) &&
  9767. (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))
  9768. {
  9769. // Pack system log
  9770. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9771. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9772. targetYear = tmStart.tm_year;
  9773. targetMonth = tmStart.tm_mon;
  9774. do
  9775. {
  9776. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9777. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9778. if(targetMonth+1>=13)
  9779. {
  9780. targetYear += 1;
  9781. targetMonth = 1;
  9782. }
  9783. else
  9784. {
  9785. targetMonth += 1;
  9786. }
  9787. }while((targetYear < (tmNow->tm_year+1900)) ||
  9788. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9789. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9790. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9791. system(cmdBuf);
  9792. // Pack charging & event log
  9793. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9794. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9795. targetYear = tmStart.tm_year;
  9796. targetMonth = tmStart.tm_mon;
  9797. do
  9798. {
  9799. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9800. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9801. if(targetMonth+1>=13)
  9802. {
  9803. targetYear += 1;
  9804. targetMonth = 1;
  9805. }
  9806. else
  9807. {
  9808. targetMonth += 1;
  9809. }
  9810. }while((targetYear < (tmNow->tm_year+1900)) ||
  9811. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9812. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9813. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9814. system(cmdBuf);
  9815. // Combine log file
  9816. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9817. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9818. }
  9819. else
  9820. {
  9821. system("exec /root/logPackTools 'log' 6");
  9822. }
  9823. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9824. system(cmdBuf);
  9825. checkUploadLog();
  9826. //****************location*******************/
  9827. if(strcmp(locationstr,"")==0)
  9828. {
  9829. DEBUG_INFO("location is <Empty>!\n");
  9830. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9831. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9832. goto end;
  9833. }
  9834. memset(protocol, 0, ARRAY_SIZE(protocol));
  9835. memset(user, 0, ARRAY_SIZE(user) );
  9836. memset(password, 0, ARRAY_SIZE(password));
  9837. memset(host, 0, ARRAY_SIZE(host));
  9838. memset(path, 0, ARRAY_SIZE(path));
  9839. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9840. memset(host1, 0, ARRAY_SIZE(host1));
  9841. memset(path1, 0, ARRAY_SIZE(path1));
  9842. /*location: ftp://user:password@host:port/path*/
  9843. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9844. if((access(fnamePlusPath,F_OK))!=-1)
  9845. {
  9846. DEBUG_INFO("fnamePlusPath exist.\n");
  9847. }
  9848. else
  9849. {
  9850. DEBUG_INFO("fnamePlusPath not exist!\n");
  9851. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9852. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9853. goto end;
  9854. }
  9855. if(strchr(locationstr,'@')==NULL)
  9856. {
  9857. sscanf(locationstr,
  9858. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9859. protocol, host, &port, path);
  9860. strcpy(user,"anonymous");
  9861. strcpy(password,"");
  9862. }
  9863. else
  9864. {
  9865. //DEBUG_INFO("pch=%s\n", pch);
  9866. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9867. protocol, user, password, host, &port, path);
  9868. }
  9869. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9870. {
  9871. DEBUG_INFO("protocol is not ftp/http ! \n");
  9872. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9873. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9874. goto end;
  9875. }
  9876. if(strncmp(locationstr,"http", 4) == 0)
  9877. {
  9878. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9879. sprintf(ftppath,"/%s", path);
  9880. do
  9881. {
  9882. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9883. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9884. sleep(3);
  9885. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9886. if(!isSuccess)
  9887. {
  9888. DEBUG_INFO("Diagnostics fail.\n");
  9889. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9890. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9891. sleep(retryIntervalInt);
  9892. }
  9893. else
  9894. {
  9895. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9896. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9897. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9898. }
  9899. retriesInt--;
  9900. }while((isSuccess == 0)&&(retriesInt >= 0));
  9901. }
  9902. else
  9903. {
  9904. sscanf(host,"%[^/]%s",host1, path1);
  9905. if(strlen(path) > 0)
  9906. sprintf(ftppath,"/%s", path);
  9907. else
  9908. sprintf(ftppath,"/%s", path1);
  9909. int ftppathlen=strlen(ftppath);
  9910. int i=1;
  9911. char filenametemp[50];
  9912. while(i < ftppathlen)
  9913. {
  9914. int len=ftppathlen-i;
  9915. if(ftppath[len]== 47) // '/' ascll code: 47
  9916. {
  9917. DEBUG_INFO("find '/' all right\n");
  9918. break;
  9919. }
  9920. i=i+1;
  9921. }
  9922. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9923. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9924. filenametemp[i+1] = 0;
  9925. if(port == 0)
  9926. port = 21;
  9927. do
  9928. {
  9929. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9930. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9931. sleep(3);
  9932. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9933. if(!isSuccess)
  9934. {
  9935. DEBUG_INFO("Diagnostics fail.\n");
  9936. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9937. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9938. sleep(retryIntervalInt);
  9939. }
  9940. else
  9941. {
  9942. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9943. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9944. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9945. }
  9946. retriesInt--;
  9947. }while((!isSuccess)&&(retriesInt >= 0));
  9948. }
  9949. end:
  9950. system("rm -f /mnt/*");
  9951. sleep(5);
  9952. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9953. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9954. interLock.isGetDiagnosticGoing = 0;
  9955. pthread_exit(NULL);
  9956. }
  9957. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9958. {
  9959. mtrace();
  9960. int result = FAIL;
  9961. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9962. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9963. {
  9964. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9965. locallistVersion = -1;
  9966. }
  9967. else
  9968. {
  9969. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9970. OCPP_getListVerion();
  9971. }
  9972. //from db.OCPP_getListVerion
  9973. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9974. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  9975. sendGetLocalListVersionConfirmation(uuid,"");
  9976. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  9977. return result;
  9978. }
  9979. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  9980. {
  9981. mtrace();
  9982. int result = FAIL;
  9983. int connectorIdInt=-1;
  9984. int tempIndex = 0;
  9985. int connectorIdIsNULL, chargingProfileIsNULL;
  9986. char comfirmstr[20]={0};
  9987. char cmdBuf[512];
  9988. json_object *RemoteStartTransaction;
  9989. FILE *fp;
  9990. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9991. if(server_pending == TRUE)
  9992. {
  9993. return 0;
  9994. }
  9995. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9996. RemoteStartTransaction = json_tokener_parse(payload);
  9997. if(!is_error(RemoteStartTransaction))
  9998. {
  9999. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10000. {
  10001. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10002. }
  10003. else
  10004. {
  10005. connectorIdIsNULL = TRUE;
  10006. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10007. {
  10008. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10009. {
  10010. connectorIdIsNULL = FALSE;
  10011. connectorIdInt = (gun_index+1);
  10012. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10013. break;
  10014. }
  10015. }
  10016. }
  10017. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10018. {
  10019. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10020. // Required data
  10021. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10022. // Optional data
  10023. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10024. {
  10025. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10026. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10027. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10028. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10029. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10030. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10031. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10032. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10033. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10034. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10035. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10036. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10037. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10038. {
  10039. 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")));
  10040. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10041. 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"));
  10042. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10043. 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"));
  10044. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10045. 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")));
  10046. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10047. {
  10048. 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++)
  10049. {
  10050. 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"));
  10051. 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"));
  10052. 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)
  10053. 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"));
  10054. }
  10055. }
  10056. }
  10057. }
  10058. else
  10059. {
  10060. chargingProfileIsNULL = TRUE;
  10061. }
  10062. }
  10063. }
  10064. else
  10065. {
  10066. connectorIdIsNULL = TRUE;
  10067. }
  10068. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10069. {
  10070. DEBUG_WARN("Connector id is NULL\n.");
  10071. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10072. goto end;
  10073. }
  10074. /*
  10075. enum _SYSTEM_STATUS
  10076. {
  10077. S_BOOTING = 0,
  10078. S_IDLE, = 1
  10079. S_AUTHORIZING, = 2
  10080. S_REASSIGN_CHECK, = 3
  10081. S_REASSIGN, = 4
  10082. S_PRECHARGE, = 5
  10083. S_PREPARING_FOR_EV, = 6
  10084. S_PREPARING_FOR_EVSE, = 7
  10085. S_CHARGING, = 8
  10086. S_TERMINATING, = 9
  10087. S_COMPLETE, = 10
  10088. S_ALARM, = 11
  10089. S_FAULT = 12
  10090. }
  10091. */
  10092. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10093. {
  10094. //check Transaction active
  10095. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10096. {
  10097. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10098. {
  10099. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10100. }
  10101. else
  10102. {
  10103. tempIndex = connectorIdInt -1;
  10104. }
  10105. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10106. {
  10107. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10108. {
  10109. 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))
  10110. {
  10111. //Reserved
  10112. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10113. }
  10114. 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))
  10115. {
  10116. //Reserved
  10117. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10118. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10119. goto end;
  10120. }
  10121. else
  10122. {
  10123. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10124. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10125. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10126. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10127. {
  10128. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10129. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10130. goto end;
  10131. }
  10132. }//END FOR ELSE
  10133. }
  10134. }// END FOR CHAdeMO_QUANTITY
  10135. }
  10136. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10137. {
  10138. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10139. {
  10140. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10141. }
  10142. else
  10143. {
  10144. tempIndex = connectorIdInt -1;
  10145. }
  10146. for (int index = 0; index < CCS_QUANTITY; index++)
  10147. {
  10148. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10149. {
  10150. 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))
  10151. {
  10152. //Reserved
  10153. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10154. }
  10155. 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))
  10156. {
  10157. //Reserved
  10158. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10159. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10160. goto end;
  10161. }
  10162. else
  10163. {
  10164. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10165. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10166. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10167. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10168. {
  10169. DEBUG_WARN("CCS connector not allow start\n.");
  10170. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10171. goto end;
  10172. }
  10173. }// END FOR ELSE
  10174. }
  10175. }// END FOR CCS_QUANTITY
  10176. }
  10177. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10178. {
  10179. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10180. {
  10181. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10182. }
  10183. else
  10184. {
  10185. tempIndex = connectorIdInt -1;
  10186. }
  10187. for (int index = 0; index < GB_QUANTITY; index++)
  10188. {
  10189. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10190. {
  10191. 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))
  10192. {
  10193. //Reserved
  10194. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10195. }
  10196. 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))
  10197. {
  10198. //Reserved
  10199. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10200. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10201. goto end;
  10202. }
  10203. else
  10204. {
  10205. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10206. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10207. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10208. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10209. {
  10210. DEBUG_WARN("GB connector not allow start\n.");
  10211. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10212. goto end;
  10213. }
  10214. }// END FOR ELSE
  10215. }
  10216. } // END FOR GB_QUANTITY
  10217. }
  10218. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10219. {
  10220. tempIndex = connectorIdInt -1;
  10221. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10222. {
  10223. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10224. {
  10225. 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))
  10226. {
  10227. //Reserved
  10228. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10229. }
  10230. 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))
  10231. {
  10232. //Reserved
  10233. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10234. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10235. goto end;
  10236. }
  10237. else
  10238. {
  10239. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10240. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10241. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10242. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10243. {
  10244. DEBUG_WARN("GB connector not allow start\n.");
  10245. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10246. goto end;
  10247. }
  10248. }// END FOR ELSE
  10249. }
  10250. } // END FOR GB_QUANTITY
  10251. }
  10252. else
  10253. {
  10254. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10255. {
  10256. tempIndex = 2;
  10257. }
  10258. else
  10259. {
  10260. tempIndex = connectorIdInt -1;
  10261. }
  10262. for (int index = 0; index < AC_QUANTITY; index++)
  10263. {
  10264. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10265. {
  10266. 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))
  10267. {
  10268. //Reserved
  10269. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10270. }
  10271. 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))
  10272. {
  10273. //Reserved
  10274. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10275. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10276. goto end;
  10277. }
  10278. else
  10279. {
  10280. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10281. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10282. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10283. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10284. {
  10285. DEBUG_WARN("AC connector not allow start\n.");
  10286. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10287. goto end;
  10288. }
  10289. }//END FOR ELSE
  10290. }
  10291. }// END FOR AC_QUANTITY
  10292. }
  10293. if(chargingProfileIsNULL == FALSE)
  10294. {
  10295. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10296. {
  10297. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10298. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10299. //memset idTag
  10300. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10301. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10302. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10303. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10304. // Save profile to file
  10305. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10306. system(cmdBuf);
  10307. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10308. fp = fopen(cmdBuf, "w");
  10309. 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));
  10310. fclose(fp);
  10311. }
  10312. else
  10313. {
  10314. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10315. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10316. }
  10317. }
  10318. else
  10319. {
  10320. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10321. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10322. //memset idTag
  10323. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10324. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10325. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10326. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10327. }
  10328. }
  10329. else
  10330. {
  10331. DEBUG_WARN("Connector id over\n.");
  10332. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10333. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10334. }
  10335. end:
  10336. json_object_put(RemoteStartTransaction);
  10337. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10338. {
  10339. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10340. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10341. }
  10342. //OCPP send RemoteStartConfirmation by first.
  10343. sendRemoteStartConfirmation(uuid, comfirmstr);
  10344. return result;
  10345. }
  10346. int handleRemoteStartRequest(char *uuid, char *payload)
  10347. {
  10348. mtrace();
  10349. int result = PASS;
  10350. int connectorIdInt=-1;
  10351. int tempIndex = 0;
  10352. char comfirmstr[20]={0};
  10353. char cmdBuf[512];
  10354. json_object *RemoteStartTransaction;
  10355. FILE *fp;
  10356. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10357. if(server_pending == TRUE)
  10358. {
  10359. result = FAIL;
  10360. }
  10361. RemoteStartTransaction = json_tokener_parse(payload);
  10362. if(!is_error(RemoteStartTransaction))
  10363. {
  10364. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10365. {
  10366. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10367. }
  10368. else
  10369. {
  10370. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10371. {
  10372. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10373. {
  10374. connectorIdInt = (gun_index+1);
  10375. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10376. break;
  10377. }
  10378. }
  10379. }
  10380. if(connectorIdInt == 0)
  10381. {
  10382. DEBUG_WARN("Connector id shall not equal 0.\n");
  10383. result = FAIL;
  10384. }
  10385. else if(connectorIdInt == -1)
  10386. {
  10387. DEBUG_INFO("Connector id does not specific.\n");
  10388. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10389. {
  10390. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10391. // Required data
  10392. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10393. // Optional data
  10394. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10395. {
  10396. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10397. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10398. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10399. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10400. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10401. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10402. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10403. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10404. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10405. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10406. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10407. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10408. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10409. {
  10410. 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")));
  10411. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10412. 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"));
  10413. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10414. 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"));
  10415. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10416. 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")));
  10417. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10418. {
  10419. 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++)
  10420. {
  10421. 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"));
  10422. 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"));
  10423. 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)
  10424. 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"));
  10425. }
  10426. }
  10427. }
  10428. }
  10429. else
  10430. {
  10431. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10432. }
  10433. }
  10434. }
  10435. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10436. {
  10437. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10438. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10439. // Required data
  10440. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10441. // Optional data
  10442. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10443. {
  10444. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10445. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10446. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10447. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10448. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10449. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10450. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10451. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10452. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10453. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10454. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10455. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10456. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10457. {
  10458. 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")));
  10459. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10460. 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"));
  10461. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10462. 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"));
  10463. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10464. 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")));
  10465. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10466. {
  10467. 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++)
  10468. {
  10469. 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"));
  10470. 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"));
  10471. 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)
  10472. 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"));
  10473. }
  10474. }
  10475. }
  10476. }
  10477. else
  10478. {
  10479. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10480. }
  10481. }
  10482. else
  10483. {
  10484. DEBUG_WARN("Connector id is over maximun value.\n");
  10485. result = FAIL;
  10486. }
  10487. }
  10488. if(result == PASS)
  10489. {
  10490. if(connectorIdInt > 0)
  10491. {
  10492. //check Transaction active
  10493. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10494. {
  10495. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10496. {
  10497. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10498. }
  10499. else
  10500. {
  10501. tempIndex = connectorIdInt -1;
  10502. }
  10503. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10504. {
  10505. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10506. {
  10507. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10508. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10509. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10510. {
  10511. //Reserved
  10512. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10513. }
  10514. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10515. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10516. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10517. {
  10518. //Reserved
  10519. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10520. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10521. goto end;
  10522. }
  10523. else
  10524. {
  10525. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10526. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10527. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10528. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10529. {
  10530. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10531. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10532. goto end;
  10533. }
  10534. }//END FOR ELSE
  10535. }
  10536. }// END FOR CHAdeMO_QUANTITY
  10537. }
  10538. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10539. {
  10540. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10541. {
  10542. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10543. }
  10544. else
  10545. {
  10546. tempIndex = connectorIdInt -1;
  10547. }
  10548. for (int index = 0; index < CCS_QUANTITY; index++)
  10549. {
  10550. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10551. {
  10552. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10553. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10554. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10555. {
  10556. //Reserved
  10557. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10558. }
  10559. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10560. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10561. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10562. {
  10563. //Reserved
  10564. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10565. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10566. goto end;
  10567. }
  10568. else
  10569. {
  10570. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10571. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10572. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10573. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10574. {
  10575. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10576. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10577. goto end;
  10578. }
  10579. }// END FOR ELSE
  10580. }
  10581. }// END FOR CCS_QUANTITY
  10582. }
  10583. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10584. {
  10585. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10586. {
  10587. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10588. }
  10589. else
  10590. {
  10591. tempIndex = connectorIdInt -1;
  10592. }
  10593. for (int index = 0; index < GB_QUANTITY; index++)
  10594. {
  10595. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10596. {
  10597. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10598. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10599. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10600. {
  10601. //Reserved
  10602. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10603. }
  10604. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10605. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10606. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10607. {
  10608. //Reserved
  10609. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10610. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10611. goto end;
  10612. }
  10613. else
  10614. {
  10615. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10616. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10617. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10618. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10619. {
  10620. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10621. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10622. goto end;
  10623. }
  10624. }// END FOR ELSE
  10625. }
  10626. } // END FOR GB_QUANTITY
  10627. }
  10628. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10629. {
  10630. tempIndex = connectorIdInt -1;
  10631. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10632. {
  10633. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10634. {
  10635. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10636. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10637. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10638. {
  10639. //Reserved
  10640. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10641. }
  10642. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10643. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10644. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10645. {
  10646. //Reserved
  10647. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10648. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10649. goto end;
  10650. }
  10651. else
  10652. {
  10653. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10654. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10655. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10656. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10657. {
  10658. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10659. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10660. goto end;
  10661. }
  10662. }// END FOR ELSE
  10663. }
  10664. } // END FOR GB_QUANTITY
  10665. }
  10666. else
  10667. {
  10668. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10669. {
  10670. tempIndex = 2;
  10671. }
  10672. else
  10673. {
  10674. tempIndex = connectorIdInt -1;
  10675. }
  10676. for (int index = 0; index < AC_QUANTITY; index++)
  10677. {
  10678. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10679. {
  10680. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10681. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10682. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10683. {
  10684. //Reserved
  10685. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10686. }
  10687. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10688. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10689. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10690. {
  10691. //Reserved
  10692. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10693. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10694. goto end;
  10695. }
  10696. else
  10697. {
  10698. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10699. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10700. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10701. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10702. {
  10703. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10704. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10705. goto end;
  10706. }
  10707. }//END FOR ELSE
  10708. }
  10709. }// END FOR AC_QUANTITY
  10710. }
  10711. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10712. {
  10713. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10714. {
  10715. // Save profile to file
  10716. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10717. system(cmdBuf);
  10718. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10719. fp = fopen(cmdBuf, "w");
  10720. 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));
  10721. fclose(fp);
  10722. }
  10723. else
  10724. {
  10725. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10726. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10727. goto end;
  10728. }
  10729. }
  10730. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10731. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10732. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10733. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10734. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10735. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10736. }
  10737. else
  10738. {
  10739. uint8_t isHasIdleConnector = FALSE;
  10740. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10741. {
  10742. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10743. {
  10744. isHasIdleConnector = TRUE;
  10745. break;
  10746. }
  10747. }
  10748. if(isHasIdleConnector == TRUE)
  10749. {
  10750. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10751. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10752. {
  10753. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10754. {
  10755. // Save profile to file
  10756. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  10757. system(cmdBuf);
  10758. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  10759. fp = fopen(cmdBuf, "w");
  10760. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10761. fclose(fp);
  10762. refreshStartTimer(&clientTime.RemoteStartWait);
  10763. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  10764. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10765. }
  10766. else
  10767. {
  10768. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10769. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10770. }
  10771. }
  10772. }
  10773. else
  10774. {
  10775. DEBUG_INFO("There is not any connector is idle.\n");
  10776. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10777. }
  10778. }
  10779. }
  10780. else
  10781. {
  10782. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10783. }
  10784. end:
  10785. json_object_put(RemoteStartTransaction);
  10786. sendRemoteStartConfirmation(uuid, comfirmstr);
  10787. return result;
  10788. }
  10789. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10790. {
  10791. mtrace();
  10792. int result = FAIL;
  10793. int match = FALSE;
  10794. int GunNO = 0;
  10795. int tempIndex = 0;
  10796. int transactionIdInt=0;
  10797. int transactionIdIsNULL= TRUE;
  10798. char comfirmstr[20];
  10799. json_object *RemoteStopTransaction;
  10800. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10801. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10802. if(server_pending == TRUE)
  10803. {
  10804. return 0;
  10805. }
  10806. RemoteStopTransaction = json_tokener_parse(payload);
  10807. if(!is_error(RemoteStopTransaction))
  10808. {
  10809. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10810. {
  10811. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10812. transactionIdIsNULL = FALSE;
  10813. }
  10814. }
  10815. json_object_put(RemoteStopTransaction);
  10816. if(transactionIdIsNULL == FALSE)
  10817. {
  10818. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10819. {
  10820. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10821. {
  10822. //check Transaction active
  10823. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10824. {
  10825. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10826. {
  10827. tempIndex = ((gun_index==2) ? 1: 0);
  10828. }
  10829. else
  10830. {
  10831. tempIndex = gun_index;
  10832. }
  10833. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10834. {
  10835. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10836. {
  10837. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10838. {
  10839. match = TRUE;
  10840. GunNO = gun_index;
  10841. }
  10842. }
  10843. }// END FOR CHAdeMO_QUANTITY
  10844. }
  10845. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10846. {
  10847. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10848. {
  10849. tempIndex = ((gun_index==2) ? 1: 0);
  10850. }
  10851. else
  10852. {
  10853. tempIndex = gun_index;
  10854. }
  10855. for (int index = 0; index < CCS_QUANTITY; index++)
  10856. {
  10857. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10858. {
  10859. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10860. {
  10861. match = TRUE;
  10862. GunNO = gun_index;
  10863. }
  10864. }
  10865. }// END FOR CCS_QUANTITY
  10866. }
  10867. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10868. {
  10869. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10870. {
  10871. tempIndex = ((gun_index==2) ? 1: 0);
  10872. }
  10873. else
  10874. {
  10875. tempIndex = gun_index;
  10876. }
  10877. for (int index = 0; index < GB_QUANTITY; index++)
  10878. {
  10879. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10880. {
  10881. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10882. {
  10883. match = TRUE;
  10884. GunNO = gun_index;
  10885. }
  10886. }
  10887. }// END FOR GB_QUANTITY
  10888. }
  10889. else if(gunType[gun_index] == GUN_TYPE_DO)
  10890. {
  10891. tempIndex = gun_index;
  10892. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10893. {
  10894. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10895. {
  10896. 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
  10897. {
  10898. match = TRUE;
  10899. GunNO = gun_index;
  10900. }
  10901. }
  10902. }// END FOR GB_QUANTITY
  10903. }
  10904. else
  10905. {
  10906. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10907. {
  10908. tempIndex = 2;
  10909. }
  10910. else
  10911. {
  10912. tempIndex = gun_index;
  10913. }
  10914. for (int index = 0; index < AC_QUANTITY; index++)
  10915. {
  10916. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10917. {
  10918. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10919. {
  10920. match = TRUE;
  10921. GunNO = gun_index;
  10922. }
  10923. }
  10924. }// END FOR CHAdeMO_QUANTITY
  10925. } // END FOR AC ELSE
  10926. }// CHECK IF ResponseTransactionId == transactionIdInt
  10927. }//END FOR
  10928. if( match == TRUE)
  10929. {
  10930. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  10931. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10932. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  10933. }
  10934. else
  10935. {
  10936. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10937. }
  10938. }
  10939. else
  10940. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10941. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  10942. return result;
  10943. }
  10944. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  10945. {
  10946. mtrace();
  10947. int result = FAIL;
  10948. int connectorIdInt=0, reservationIdInt=0;
  10949. int tempIndex = 0;
  10950. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  10951. char comfirmstr[20]={0};
  10952. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  10953. int c = 0;
  10954. char *loc;
  10955. //char *ptr;
  10956. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  10957. strcpy(sstrtemp, stringtrimspace(payload));
  10958. //***(1)connectorId ****/
  10959. c=0;
  10960. loc = strstr(sstrtemp, "connectorId");
  10961. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10962. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  10963. {
  10964. sstr[c] = loc[strlen("connectorId")+2+c];
  10965. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10966. c++;
  10967. }
  10968. sstr[c] = '\0';
  10969. connectorIdInt = atoi(sstr);
  10970. //***(2)expiryDate ****/
  10971. loc = strstr(sstrtemp, "expiryDate");
  10972. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10973. c = 0;
  10974. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  10975. {
  10976. sstr[c] = loc[3+strlen("expiryDate")+c];
  10977. c++;
  10978. }
  10979. sstr[c] = '\0';
  10980. strcpy(expiryDatestr, sstr);
  10981. //***(3)idTag ****/
  10982. loc = strstr(sstrtemp, "idTag");
  10983. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10984. c = 0;
  10985. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  10986. {
  10987. sstr[c] = loc[3+strlen("idTag")+c];
  10988. c++;
  10989. }
  10990. sstr[c] = '\0';
  10991. strcpy(idTagstr, sstr);
  10992. //***(4)parentIdTag ****/
  10993. loc = strstr(sstrtemp, "parentIdTag");
  10994. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10995. c = 0;
  10996. if(loc == NULL)
  10997. {
  10998. strcpy(parentIdTagstr, "");
  10999. }
  11000. else
  11001. {
  11002. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11003. {
  11004. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11005. c++;
  11006. }
  11007. sstr[c] = '\0';
  11008. strcpy(parentIdTagstr, sstr);
  11009. }
  11010. //***(5)reservationId ****/
  11011. c=0;
  11012. loc = strstr(sstrtemp, "reservationId");
  11013. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11014. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11015. {
  11016. sstr[c] = loc[strlen("reservationId")+2+c];
  11017. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11018. c++;
  11019. }
  11020. sstr[c] = '\0';
  11021. reservationIdInt = atoi(sstr);
  11022. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11023. /*
  11024. enum SYSTEM_STATUS
  11025. {
  11026. SYS_MODE_BOOTING = 0,
  11027. SYS_MODE_IDLE = 1,
  11028. SYS_MODE_AUTHORIZING = 2,
  11029. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11030. SYS_MODE_REASSIGN = 4,
  11031. SYS_MODE_PREPARING = 5,
  11032. SYS_MODE_PREPARE_FOR_EV = 6,
  11033. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11034. SYS_MODE_CHARGING = 8,
  11035. SYS_MODE_TERMINATING = 9,
  11036. SYS_MODE_COMPLETE = 10,
  11037. SYS_MODE_ALARM = 11,
  11038. SYS_MODE_FAULT = 12,
  11039. SYS_MODE_RESERVATION = 13,
  11040. SYS_MODE_BOOKING = 14,
  11041. SYS_MODE_MAINTAIN = 15,
  11042. SYS_MODE_DEBUG = 16,
  11043. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11044. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11045. SYS_MODE_UPDATE = 19
  11046. };
  11047. */
  11048. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11049. {
  11050. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11051. goto end;
  11052. }
  11053. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11054. {
  11055. //check Transaction active
  11056. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11057. {
  11058. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11059. {
  11060. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11061. }
  11062. else
  11063. {
  11064. tempIndex = connectorIdInt -1;
  11065. }
  11066. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11067. {
  11068. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11069. {
  11070. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11071. {
  11072. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11073. {
  11074. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11075. {
  11076. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11077. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11078. }
  11079. 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'))
  11080. {
  11081. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11082. }
  11083. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11084. {
  11085. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11086. }
  11087. else
  11088. {
  11089. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11090. }
  11091. }
  11092. 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
  11093. {
  11094. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11095. }
  11096. }
  11097. else
  11098. {
  11099. //replace reservation
  11100. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11101. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11102. }
  11103. }
  11104. } // END FOR CHAdeMO_QUANTITY
  11105. }
  11106. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11107. {
  11108. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11109. {
  11110. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11111. }
  11112. else
  11113. {
  11114. tempIndex = connectorIdInt -1;
  11115. }
  11116. for (int index = 0; index < CCS_QUANTITY; index++)
  11117. {
  11118. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11119. {
  11120. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11121. {
  11122. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11123. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11124. {
  11125. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11126. {
  11127. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11128. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11129. }
  11130. 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'))
  11131. {
  11132. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11133. }
  11134. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11135. {
  11136. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11137. }
  11138. else
  11139. {
  11140. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11141. }
  11142. }
  11143. 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
  11144. {
  11145. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11146. }
  11147. }
  11148. else
  11149. {
  11150. //replace reservation
  11151. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11152. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11153. }
  11154. }
  11155. } // END FOR CCS_QUANTITY
  11156. }
  11157. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11158. {
  11159. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11160. {
  11161. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11162. }
  11163. else
  11164. {
  11165. tempIndex = connectorIdInt -1;
  11166. }
  11167. for (int index = 0; index < GB_QUANTITY; index++)
  11168. {
  11169. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11170. {
  11171. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11172. {
  11173. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11174. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11175. {
  11176. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11177. {
  11178. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11179. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11180. }
  11181. 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'))
  11182. {
  11183. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11184. }
  11185. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11186. {
  11187. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11188. }
  11189. else
  11190. {
  11191. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11192. }
  11193. }
  11194. 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
  11195. {
  11196. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11197. }
  11198. }
  11199. else
  11200. {
  11201. //replace reservation
  11202. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11203. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11204. }
  11205. }
  11206. }// END FOR GB_QUANTITY
  11207. }
  11208. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11209. {
  11210. tempIndex = connectorIdInt -1;
  11211. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11212. {
  11213. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11214. {
  11215. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11216. {
  11217. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11218. 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
  11219. {
  11220. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11221. {
  11222. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11223. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11224. }
  11225. 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'))
  11226. {
  11227. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11228. }
  11229. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11230. {
  11231. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11232. }
  11233. else
  11234. {
  11235. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11236. }
  11237. }
  11238. 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
  11239. {
  11240. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11241. }
  11242. }
  11243. else
  11244. {
  11245. //replace reservation
  11246. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11247. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11248. }
  11249. }
  11250. }// END FOR GB_QUANTITY
  11251. }
  11252. else
  11253. {
  11254. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11255. {
  11256. tempIndex = 2;
  11257. }
  11258. else
  11259. {
  11260. tempIndex = (connectorIdInt -1);
  11261. }
  11262. for (int index = 0; index < AC_QUANTITY; index++)
  11263. {
  11264. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11265. {
  11266. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11267. {
  11268. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11269. {
  11270. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11271. {
  11272. 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))
  11273. {
  11274. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11275. }
  11276. else
  11277. {
  11278. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11279. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11280. }
  11281. }
  11282. 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'))
  11283. {
  11284. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11285. }
  11286. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11287. {
  11288. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11289. }
  11290. else
  11291. {
  11292. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11293. }
  11294. }
  11295. 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
  11296. {
  11297. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11298. }
  11299. }
  11300. else
  11301. {
  11302. //replace reservation
  11303. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11304. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11305. }
  11306. }
  11307. } // END FOR AC_QUANTITY
  11308. }
  11309. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11310. }
  11311. else if(connectorIdInt == 0)
  11312. {
  11313. //check Transaction active
  11314. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11315. {
  11316. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11317. {
  11318. 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'))
  11319. {
  11320. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11321. goto end;
  11322. }
  11323. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11324. {
  11325. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11326. goto end;
  11327. }
  11328. 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
  11329. {
  11330. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11331. goto end;
  11332. }
  11333. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11334. {
  11335. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11336. goto end;
  11337. }
  11338. }
  11339. }// END FOR CHAdeMO_QUANTITY
  11340. for (int index = 0; index < CCS_QUANTITY; index++)
  11341. {
  11342. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11343. {
  11344. 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'))
  11345. {
  11346. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11347. goto end;
  11348. }
  11349. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11350. {
  11351. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11352. goto end;
  11353. }
  11354. 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
  11355. {
  11356. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11357. goto end;
  11358. }
  11359. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11360. {
  11361. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11362. goto end;
  11363. }
  11364. }
  11365. } // END FOR CCS_QUANTITY
  11366. for (int index = 0; index < GB_QUANTITY; index++)
  11367. {
  11368. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11369. {
  11370. 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'))
  11371. {
  11372. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11373. goto end;
  11374. }
  11375. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11376. {
  11377. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11378. goto end;
  11379. }
  11380. 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
  11381. {
  11382. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11383. goto end;
  11384. }
  11385. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11386. {
  11387. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11388. goto end;
  11389. }
  11390. }
  11391. } // END FOR GB_QUANTITY
  11392. for (int index = 0; index < AC_QUANTITY; index++)
  11393. {
  11394. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11395. {
  11396. 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'))
  11397. {
  11398. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11399. goto end;
  11400. }
  11401. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11402. {
  11403. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11404. goto end;
  11405. }
  11406. 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
  11407. {
  11408. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11409. goto end;
  11410. }
  11411. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11412. {
  11413. 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))
  11414. {
  11415. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11416. goto end;
  11417. }
  11418. }
  11419. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11420. {
  11421. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11422. goto end;
  11423. }
  11424. }
  11425. }// END FOR AC_QUANTITY
  11426. //The connectorId is 0
  11427. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  11428. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11429. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11430. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  11431. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11432. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  11433. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11434. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  11435. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  11436. result = TRUE;
  11437. return result;
  11438. }
  11439. else
  11440. {
  11441. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11442. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11443. }
  11444. if(strcmp(comfirmstr,"Accepted") == 0)
  11445. {
  11446. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11447. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11448. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11449. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11450. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11451. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  11452. result = TRUE;
  11453. return result;
  11454. }
  11455. end:
  11456. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11457. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11458. return result;
  11459. }
  11460. int handleResetRequest(char *uuid, char *payload)
  11461. {
  11462. mtrace();
  11463. int result = FAIL;
  11464. char sstr[10]={0},sstrtemp[30]={ 0 };
  11465. char typestr[10]={0};
  11466. char comfirmstr[20]={0};
  11467. int c = 0;
  11468. char *loc;
  11469. DEBUG_INFO("handleResetRequest...\n");
  11470. strcpy(sstrtemp, stringtrimspace(payload));
  11471. loc = strstr(sstrtemp, "type");
  11472. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11473. c = 0;
  11474. while (loc[3+strlen("type")+c] != '\"')
  11475. {
  11476. sstr[c] = loc[3+strlen("type")+c];
  11477. c++;
  11478. }
  11479. sstr[c] = '\0';
  11480. strcpy(typestr,sstr);
  11481. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11482. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11483. {
  11484. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11485. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  11486. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11487. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11488. }
  11489. else
  11490. {
  11491. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11492. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11493. result = PASS;
  11494. }
  11495. sendResetConfirmation(uuid, comfirmstr);
  11496. return result;
  11497. }
  11498. int handleSendLocalListRequest(char *uuid, char *payload)
  11499. {
  11500. mtrace();
  11501. int result = FAIL;
  11502. char comfirmstr[20];
  11503. int checkState_Faulted = FALSE;
  11504. json_object *SendLocalList;
  11505. DEBUG_INFO("handleSendLocalListRequest...\n");
  11506. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11507. {
  11508. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11509. goto end;
  11510. }
  11511. //check Charge Point state
  11512. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11513. {
  11514. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11515. {
  11516. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11517. }
  11518. }
  11519. for (int index = 0; index < CCS_QUANTITY; index++)
  11520. {
  11521. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11522. {
  11523. checkState_Faulted = TRUE; //OCPP Status
  11524. }
  11525. }
  11526. for (int index = 0; index < GB_QUANTITY; index++)
  11527. {
  11528. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11529. {
  11530. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11531. }
  11532. }
  11533. //check Charge Point state
  11534. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11535. {
  11536. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11537. {
  11538. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11539. }
  11540. }
  11541. //check Charge Point state
  11542. for (int index = 0; index < AC_QUANTITY; index++)
  11543. {
  11544. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11545. {
  11546. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11547. }
  11548. }
  11549. if(checkState_Faulted == TRUE)
  11550. {
  11551. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11552. goto end;
  11553. }
  11554. // Parsing payload
  11555. SendLocalList = json_tokener_parse(payload);
  11556. if(!is_error(SendLocalList))
  11557. {
  11558. // Required data
  11559. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11560. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11561. // Optional data
  11562. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11563. {
  11564. //Check UpdateType
  11565. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11566. {
  11567. //Local list full update
  11568. DEBUG_INFO("Local list full update.\n");
  11569. OCPP_getListVerion();
  11570. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11571. {
  11572. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11573. goto end;
  11574. }
  11575. OCPP_cleanLocalList();
  11576. }
  11577. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11578. {
  11579. //Local list different update
  11580. DEBUG_INFO("Local list different update.\n");
  11581. OCPP_getListVerion();
  11582. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11583. {
  11584. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11585. goto end;
  11586. }
  11587. }
  11588. else
  11589. {
  11590. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11591. goto end;
  11592. }
  11593. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11594. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11595. {
  11596. 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")));
  11597. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11598. {
  11599. 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")));
  11600. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11601. 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")));
  11602. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11603. 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")));
  11604. }
  11605. // Add to db
  11606. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11607. {
  11608. //Local list full update
  11609. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11610. idx,
  11611. ShmOCPP16Data->SendLocalList.ListVersion,
  11612. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11613. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11614. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11615. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11616. // update list
  11617. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11618. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11619. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11620. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11621. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11622. }
  11623. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11624. {
  11625. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11626. idx,
  11627. ShmOCPP16Data->SendLocalList.ListVersion,
  11628. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11629. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11630. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11631. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11632. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11633. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11634. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11635. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11636. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11637. }
  11638. }
  11639. }
  11640. else
  11641. {
  11642. //Check UpdateType
  11643. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11644. {
  11645. //Local list full update
  11646. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11647. OCPP_cleanLocalList();
  11648. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11649. goto end;
  11650. }
  11651. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11652. {
  11653. //Local list different update
  11654. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11655. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11656. goto end;
  11657. }
  11658. }
  11659. result = PASS;
  11660. }
  11661. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11662. end:
  11663. json_object_put(SendLocalList);
  11664. sendSendLocalListConfirmation(uuid, comfirmstr);
  11665. return result;
  11666. }
  11667. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11668. {
  11669. mtrace();
  11670. int result = FAIL;
  11671. struct StructSetChargingProfile SetProfileReq = {0};
  11672. int tempchargingProfileIdInt;
  11673. int chargingSchedulePeriodCount = 0;
  11674. char comfirmstr[20]={0};
  11675. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  11676. char rmFileCmd[128]={0};
  11677. int profileQuantity = 0;
  11678. json_object *SetChargingProfile;
  11679. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11680. SetChargingProfile = json_tokener_parse(payload);
  11681. if(!is_error(SetChargingProfile))
  11682. {
  11683. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11684. {
  11685. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11686. }
  11687. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11688. {
  11689. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11690. {
  11691. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11692. }
  11693. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11694. {
  11695. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11696. }
  11697. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11698. {
  11699. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11700. }
  11701. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11702. {
  11703. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11704. }
  11705. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11706. {
  11707. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11708. }
  11709. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11710. {
  11711. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11712. }
  11713. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11714. {
  11715. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11716. }
  11717. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11718. {
  11719. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11720. }
  11721. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11722. {
  11723. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11724. {
  11725. 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")));
  11726. }
  11727. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11728. {
  11729. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11730. }
  11731. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11732. {
  11733. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11734. }
  11735. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11736. {
  11737. 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")));
  11738. }
  11739. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11740. {
  11741. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11742. if(chargingSchedulePeriodCount <= 10)
  11743. {
  11744. 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++)
  11745. {
  11746. 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)
  11747. {
  11748. 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"));
  11749. }
  11750. 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)
  11751. {
  11752. 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"));
  11753. }
  11754. 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)
  11755. {
  11756. 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"));
  11757. }
  11758. }
  11759. }
  11760. }
  11761. }
  11762. }
  11763. }
  11764. // Profile periods quantity check
  11765. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11766. {
  11767. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11768. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11769. goto end;
  11770. }
  11771. // Check invalid limit
  11772. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11773. {
  11774. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11775. {
  11776. 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)))) ||
  11777. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11778. {
  11779. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11780. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11781. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11782. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11783. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11784. goto end;
  11785. }
  11786. }
  11787. }
  11788. else
  11789. {
  11790. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11791. {
  11792. if((SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:modelnameInfo.ParsingInfo[0].Current)))
  11793. {
  11794. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11795. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11796. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11797. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11798. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11799. goto end;
  11800. }
  11801. }
  11802. }
  11803. // Profile purpose info check
  11804. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11805. {
  11806. FILE *fp;
  11807. char dataLine[4096]={0};
  11808. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11809. if(SetProfileReq.ConnectorId != 0)
  11810. {
  11811. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11812. DEBUG_WARN("Profile connector id is not 0.\n");
  11813. goto end;
  11814. }
  11815. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11816. if (!fp)
  11817. {
  11818. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11819. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11820. }
  11821. else
  11822. {
  11823. while(fscanf(fp, "%s", dataLine) != EOF)
  11824. {
  11825. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11826. {
  11827. profileQuantity += 1;
  11828. }
  11829. }
  11830. }
  11831. fclose(fp);
  11832. }
  11833. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11834. {
  11835. FILE *fp;
  11836. char dataLine[4096]={0};
  11837. char filename[128]={0};
  11838. int tmpProfileQuantity;
  11839. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11840. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11841. {
  11842. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11843. DEBUG_WARN("Profile connector id is over max gun number.\n");
  11844. goto end;
  11845. }
  11846. if(SetProfileReq.ConnectorId == 0)
  11847. {
  11848. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  11849. {
  11850. tmpProfileQuantity = 0;
  11851. memset(filename, 0, ARRAY_SIZE(filename));
  11852. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  11853. fp = fopen(filename, "r");
  11854. if (!fp)
  11855. {
  11856. DEBUG_INFO("%s does not create.\n", filename);
  11857. fp = fopen(filename, "w+");
  11858. }
  11859. else
  11860. {
  11861. while(fscanf(fp, "%s", dataLine) != EOF)
  11862. {
  11863. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11864. {
  11865. tmpProfileQuantity += 1;
  11866. }
  11867. }
  11868. }
  11869. fclose(fp);
  11870. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  11871. }
  11872. }
  11873. else
  11874. {
  11875. memset(filename, 0, ARRAY_SIZE(filename));
  11876. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11877. fp = fopen(filename, "r");
  11878. if (!fp)
  11879. {
  11880. DEBUG_INFO("%s does not create.\n", filename);
  11881. fp = fopen(filename, "w+");
  11882. }
  11883. else
  11884. {
  11885. while(fscanf(fp, "%s", dataLine) != EOF)
  11886. {
  11887. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11888. {
  11889. profileQuantity += 1;
  11890. }
  11891. }
  11892. }
  11893. fclose(fp);
  11894. }
  11895. }
  11896. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11897. {
  11898. int isMatchTransactiodId= FALSE;
  11899. FILE *fp;
  11900. char dataLine[4096]={0};
  11901. char filename[128]={0};
  11902. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  11903. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  11904. if(SetProfileReq.ConnectorId == 0)
  11905. {
  11906. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11907. DEBUG_WARN("Profile connector id is 0.\n");
  11908. goto end;
  11909. }
  11910. int tempIndex = 0;
  11911. //check Transaction active
  11912. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  11913. {
  11914. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11915. {
  11916. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11917. }
  11918. else
  11919. {
  11920. tempIndex = SetProfileReq.ConnectorId -1;
  11921. }
  11922. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11923. {
  11924. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11925. {
  11926. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11927. {
  11928. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11929. {
  11930. isMatchTransactiodId = TRUE;
  11931. break;
  11932. }
  11933. }
  11934. }
  11935. }
  11936. }
  11937. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  11938. {
  11939. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11940. {
  11941. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11942. }
  11943. else
  11944. {
  11945. tempIndex = SetProfileReq.ConnectorId -1;
  11946. }
  11947. for (int index = 0; index < CCS_QUANTITY; index++)
  11948. {
  11949. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11950. {
  11951. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  11952. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11953. {
  11954. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11955. {
  11956. isMatchTransactiodId = TRUE;
  11957. break;
  11958. }
  11959. }
  11960. }
  11961. }
  11962. }
  11963. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  11964. {
  11965. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11966. {
  11967. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11968. }
  11969. else
  11970. {
  11971. tempIndex = SetProfileReq.ConnectorId -1;
  11972. }
  11973. for (int index = 0; index < GB_QUANTITY; index++)
  11974. {
  11975. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11976. {
  11977. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11978. {
  11979. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11980. {
  11981. isMatchTransactiodId = TRUE;
  11982. break;
  11983. }
  11984. }
  11985. }
  11986. }
  11987. }
  11988. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  11989. {
  11990. tempIndex = SetProfileReq.ConnectorId -1;
  11991. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11992. {
  11993. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11994. {
  11995. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  11996. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11997. {
  11998. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11999. {
  12000. isMatchTransactiodId = TRUE;
  12001. break;
  12002. }
  12003. }
  12004. }
  12005. }
  12006. }
  12007. else
  12008. {
  12009. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12010. {
  12011. tempIndex = 2;
  12012. }
  12013. else
  12014. {
  12015. tempIndex = (SetProfileReq.ConnectorId -1);
  12016. }
  12017. for (int index = 0; index < AC_QUANTITY; index++)
  12018. {
  12019. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12020. {
  12021. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12022. {
  12023. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12024. {
  12025. isMatchTransactiodId = TRUE;
  12026. break;
  12027. }
  12028. }
  12029. }
  12030. }
  12031. }
  12032. //check Transaction active
  12033. if(isMatchTransactiodId == FALSE)
  12034. {
  12035. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12036. DEBUG_WARN("Tx profile transaction id is not match.\n");
  12037. goto end;
  12038. }
  12039. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12040. {
  12041. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12042. DEBUG_WARN("Connector id is over max gun number.\n");
  12043. goto end;
  12044. }
  12045. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12046. fp = fopen(filename, "r");
  12047. if (!fp)
  12048. {
  12049. DEBUG_INFO("%s does not create.\n", filename);
  12050. fp = fopen(filename, "w+");
  12051. }
  12052. else
  12053. {
  12054. //Check Charging Profile Count
  12055. while(fscanf(fp, "%s", dataLine) != EOF)
  12056. {
  12057. //DEBUG_INFO("word=%s\n",word);
  12058. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12059. {
  12060. profileQuantity += 1;
  12061. }
  12062. }
  12063. }
  12064. fclose(fp);
  12065. }
  12066. // Check ChargeProfileMaxStackLevel
  12067. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12068. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12069. {
  12070. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12071. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12072. goto end;
  12073. }
  12074. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12075. {
  12076. FILE *fp;
  12077. char dataLine[4096]={0};
  12078. char fnametemp[128]={0};
  12079. int tmpProfileQuantity;
  12080. //Check ChargePointMaxProfile.json exit
  12081. profileQuantity = 0;
  12082. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12083. {
  12084. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  12085. //Check Charging Profile Count
  12086. tmpProfileQuantity = 0;
  12087. while(fscanf(fp, "%s", dataLine) != EOF)
  12088. {
  12089. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12090. {
  12091. profileQuantity += 1;
  12092. tmpProfileQuantity += 1;
  12093. }
  12094. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12095. }
  12096. fclose(fp);
  12097. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12098. }
  12099. //Check TxDefaultProfile_%d.json
  12100. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12101. {
  12102. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12103. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12104. if((access(fnametemp,F_OK))!=-1)
  12105. {
  12106. fp = fopen(fnametemp, "r");
  12107. //Check Charging Profile Count
  12108. tmpProfileQuantity = 0;
  12109. while(fscanf(fp, "%s", dataLine) != EOF)
  12110. {
  12111. //DEBUG_INFO("word=%s\n",word);
  12112. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12113. {
  12114. profileQuantity += 1;
  12115. tmpProfileQuantity += 1;
  12116. }
  12117. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12118. }
  12119. fclose(fp);
  12120. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12121. }
  12122. }
  12123. //Check TxProfile_%d.json
  12124. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12125. {
  12126. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12127. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  12128. if((access(fnametemp,F_OK))!=-1)
  12129. {
  12130. fp = fopen(fnametemp, "r");
  12131. //Check Charging Profile Count
  12132. tmpProfileQuantity = 0;
  12133. while(fscanf(fp, "%s", dataLine) != EOF)
  12134. {
  12135. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12136. {
  12137. profileQuantity += 1;
  12138. tmpProfileQuantity += 1;
  12139. }
  12140. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12141. }
  12142. fclose(fp);
  12143. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12144. }
  12145. }
  12146. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12147. if(profileQuantity > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12148. {
  12149. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12150. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12151. goto end;
  12152. }
  12153. }
  12154. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12155. //**********************************Write to File********************************************************/
  12156. {
  12157. FILE *infile;
  12158. FILE *outfile;
  12159. char dataLine[4096]={0};
  12160. char filename[128]={0};
  12161. int chkChar=0;
  12162. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12163. {
  12164. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12165. {
  12166. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12167. }
  12168. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12169. {
  12170. if(SetProfileReq.ConnectorId==0)
  12171. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12172. else
  12173. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12174. }
  12175. else
  12176. {
  12177. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12178. }
  12179. infile = fopen (filename, "r");
  12180. outfile = fopen (tempfile, "w");
  12181. chkChar = fgetc(infile);
  12182. rewind(infile);
  12183. if(chkChar == EOF)
  12184. {
  12185. // Profile is empty
  12186. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12187. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12188. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12189. fclose(infile);
  12190. fclose(outfile);
  12191. sprintf(rmFileCmd,"rm -f %s",filename);
  12192. system(rmFileCmd);
  12193. rename(tempfile, filename);
  12194. }
  12195. else
  12196. {
  12197. // Profile is not empty
  12198. int ChargingProfileAdded = FALSE;
  12199. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12200. {
  12201. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12202. json_object *tmpChargingProfile;
  12203. tmpChargingProfile = json_tokener_parse(dataLine);
  12204. if(!is_error(SetChargingProfile))
  12205. {
  12206. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12207. {
  12208. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12209. {
  12210. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12211. }
  12212. }
  12213. }
  12214. json_object_put(tmpChargingProfile);
  12215. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12216. {
  12217. if(ChargingProfileAdded == FALSE)
  12218. {
  12219. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12220. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12221. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12222. ChargingProfileAdded = TRUE;
  12223. }
  12224. }
  12225. else
  12226. {
  12227. fprintf(outfile,"%s\n",dataLine);
  12228. if(ChargingProfileAdded == FALSE)
  12229. {
  12230. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12231. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12232. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12233. ChargingProfileAdded = TRUE;
  12234. }
  12235. }
  12236. } // end of while loop
  12237. fclose(infile);
  12238. fclose(outfile);
  12239. sprintf(rmFileCmd,"rm -f %s",filename);
  12240. system(rmFileCmd);
  12241. rename(tempfile, filename);
  12242. }
  12243. }
  12244. sleep(1);
  12245. result = TRUE;
  12246. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12247. }
  12248. end:
  12249. json_object_put(SetChargingProfile);
  12250. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12251. {
  12252. if(SetProfileReq.ConnectorId == 0)
  12253. {
  12254. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12255. {
  12256. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  12257. }
  12258. }
  12259. else
  12260. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12261. }
  12262. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12263. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12264. return result;
  12265. }
  12266. int handleTriggerMessageRequest(char *uuid, char *payload)
  12267. {
  12268. mtrace();
  12269. int result = FAIL;
  12270. int connectorIdIsNULL = FALSE;
  12271. int connectorIdInt =0;
  12272. char sstr[40]={0},sstrtemp[100]={ 0 };
  12273. char requestedMessagestr[40]={0};
  12274. char comfirmstr[20]={0};
  12275. int c = 0;
  12276. char *loc;
  12277. DEBUG_INFO("handleTriggerMessageRequest\n");
  12278. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12279. strcpy(sstrtemp, stringtrimspace(payload));
  12280. c = 0;
  12281. loc = strstr(sstrtemp, "requestedMessage");
  12282. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12283. {
  12284. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12285. c++;
  12286. }
  12287. sstr[c] = '\0';
  12288. strcpy(requestedMessagestr, sstr);
  12289. c = 0;
  12290. loc = strstr(sstrtemp, "connectorId");
  12291. if(loc == NULL)
  12292. {
  12293. connectorIdIsNULL = TRUE;
  12294. }
  12295. else
  12296. {
  12297. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12298. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12299. {
  12300. sstr[c] = loc[strlen("connectorId")+2+c];
  12301. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12302. c++;
  12303. }
  12304. sstr[c] = '\0';
  12305. connectorIdInt = atoi(sstr);
  12306. }
  12307. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12308. {
  12309. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12310. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12311. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12312. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12313. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12314. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12315. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12316. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12317. {
  12318. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12319. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12320. return TRUE;
  12321. }
  12322. else
  12323. {
  12324. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12325. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12326. }
  12327. }
  12328. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12329. {
  12330. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12331. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12332. return TRUE;
  12333. }
  12334. //==========================
  12335. // Trigger message
  12336. //==========================
  12337. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12338. {
  12339. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12340. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12341. {
  12342. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12343. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12344. }
  12345. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12346. }
  12347. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12348. {
  12349. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  12350. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12351. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12352. }
  12353. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12354. {
  12355. //sendBootNotificationRequest();
  12356. server_sign = FALSE;
  12357. }
  12358. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12359. {
  12360. refreshStartTimer(&clientTime.Heartbeat);
  12361. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  12362. }
  12363. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12364. {
  12365. if(connectorIdIsNULL == FALSE)
  12366. {
  12367. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12368. {
  12369. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12370. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12371. }
  12372. }
  12373. else
  12374. {
  12375. for(int idx=0;idx< gunTotalNumber;idx++)
  12376. {
  12377. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12378. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12379. }
  12380. }
  12381. }
  12382. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12383. {
  12384. if(connectorIdIsNULL == FALSE)
  12385. {
  12386. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  12387. {
  12388. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12389. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  12390. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12391. }
  12392. }
  12393. else
  12394. {
  12395. for(int idx=0;idx< gunTotalNumber;idx++)
  12396. {
  12397. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  12398. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12399. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12400. }
  12401. }
  12402. }
  12403. return result;
  12404. }
  12405. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12406. {
  12407. mtrace();
  12408. int result = FAIL;
  12409. int connectorIdInt =0;
  12410. char comfirmstr[20]={0};
  12411. int tempIndex = 0;
  12412. json_object *UnlockConnector;
  12413. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12414. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12415. UnlockConnector = json_tokener_parse(payload);
  12416. if(!is_error(UnlockConnector))
  12417. {
  12418. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12419. {
  12420. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12421. }
  12422. }
  12423. json_object_put(UnlockConnector);
  12424. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12425. if(gunTotalNumber == 0)
  12426. {
  12427. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12428. goto end;
  12429. }
  12430. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12431. {
  12432. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12433. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12434. goto end;
  12435. }
  12436. else
  12437. {
  12438. //check Transaction active
  12439. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12440. {
  12441. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12442. {
  12443. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12444. }
  12445. else
  12446. {
  12447. tempIndex = connectorIdInt -1;
  12448. }
  12449. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12450. {
  12451. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12452. {
  12453. //stop Transaction
  12454. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12455. }
  12456. }
  12457. }
  12458. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12459. {
  12460. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12461. {
  12462. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12463. }
  12464. else
  12465. {
  12466. tempIndex = connectorIdInt -1;
  12467. }
  12468. for (int index = 0; index < CCS_QUANTITY; index++)
  12469. {
  12470. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12471. {
  12472. //stop Transaction
  12473. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12474. }
  12475. }
  12476. }
  12477. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12478. {
  12479. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12480. {
  12481. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12482. }
  12483. else
  12484. {
  12485. tempIndex = connectorIdInt -1;
  12486. }
  12487. for (int index = 0; index < GB_QUANTITY; index++)
  12488. {
  12489. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12490. {
  12491. //stop Transaction
  12492. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12493. }
  12494. }
  12495. }
  12496. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12497. {
  12498. tempIndex = connectorIdInt -1;
  12499. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12500. {
  12501. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12502. {
  12503. //stop Transaction
  12504. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12505. }
  12506. }
  12507. }
  12508. else
  12509. {
  12510. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12511. {
  12512. tempIndex = 2;
  12513. }
  12514. else
  12515. {
  12516. tempIndex = connectorIdInt-1;
  12517. }
  12518. for (int index = 0; index < AC_QUANTITY; index++)
  12519. {
  12520. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12521. {
  12522. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12523. }
  12524. }
  12525. }
  12526. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12527. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  12528. result = TRUE;
  12529. return result;
  12530. }
  12531. end:
  12532. //json_object_put(obj); --- remove temporally
  12533. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12534. return result;
  12535. }
  12536. static char UpdateFirmwarepayloadData[300]={0};
  12537. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12538. {
  12539. mtrace();
  12540. int result = FAIL;
  12541. pthread_t t;
  12542. sendUpdateFirmwareConfirmation(uuid);
  12543. memset(UpdateFirmwarepayloadData, 0, 300);
  12544. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12545. if(!interLock.isUpdateFirmwareGoing)
  12546. {
  12547. interLock.isUpdateFirmwareGoing = 1;
  12548. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12549. sleep(1);
  12550. }
  12551. else
  12552. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12553. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  12554. return result;
  12555. }
  12556. void *UpdateFirmwareProcess(void *data)
  12557. {
  12558. pthread_detach(pthread_self());
  12559. mtrace();
  12560. int retriesInt =0, retryIntervalInt=0;
  12561. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  12562. int port=0;
  12563. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  12564. int isSuccess = 0;
  12565. char ftpbuf[1024];
  12566. char temp[1024];
  12567. char * pch;
  12568. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12569. json_object *UpdateFirmware;
  12570. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12571. if(!is_error(UpdateFirmware))
  12572. {
  12573. // Required data
  12574. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12575. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12576. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12577. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12578. // Optional data
  12579. if(json_object_object_get(UpdateFirmware, "retries"))
  12580. {
  12581. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12582. }
  12583. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12584. {
  12585. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12586. }
  12587. }
  12588. json_object_put(UpdateFirmware);
  12589. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12590. memset(path, 0, ARRAY_SIZE(path));
  12591. // Wait retrieveData
  12592. if(strlen(retrieveDatestr) > 10)
  12593. {
  12594. do
  12595. {
  12596. sleep(1);
  12597. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12598. }
  12599. // Ready to download
  12600. system("rm -f /mnt/*");
  12601. if(strncmp(locationstr,"http", 4) == 0)
  12602. {
  12603. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12604. sprintf(ftppath,"/%s", path);
  12605. DEBUG_INFO("locationstr: %s\n", locationstr);
  12606. DEBUG_INFO("protocol: %s\n",protocol);
  12607. DEBUG_INFO("host: %s\n",host);
  12608. DEBUG_INFO("path: %s\n",path);
  12609. DEBUG_INFO("ftppath: %s\n",ftppath);
  12610. int ftppathlen=strlen(ftppath);
  12611. int i=1;
  12612. char filenametemp[50];
  12613. while(i < ftppathlen)
  12614. {
  12615. int len=ftppathlen-i;
  12616. if(ftppath[len]== 47) // '/' ascll code: 47
  12617. {
  12618. DEBUG_INFO("compare '/' all right\n");
  12619. break;
  12620. }
  12621. i=i+1;
  12622. }
  12623. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12624. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12625. filenametemp[i+1] = 0;
  12626. do
  12627. {
  12628. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12629. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12630. sleep(1);
  12631. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12632. if(!isSuccess)
  12633. {
  12634. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12635. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12636. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12637. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12638. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12639. }
  12640. else
  12641. {
  12642. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12643. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12644. }
  12645. retriesInt--;
  12646. }while((isSuccess == 0)&&(retriesInt >= 0));
  12647. }
  12648. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12649. {
  12650. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12651. memset(temp, 0, ARRAY_SIZE(temp));
  12652. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12653. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12654. int ftppathlen=strlen(ftpbuf);
  12655. int i=1;
  12656. char filenametemp[50];
  12657. while(i < ftppathlen)
  12658. {
  12659. int len=ftppathlen-i;
  12660. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12661. {
  12662. DEBUG_INFO(" compare '/' all right\n");
  12663. break;
  12664. }
  12665. i=i+1;
  12666. }
  12667. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12668. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12669. filenametemp[i+1] = 0;
  12670. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12671. pch=strchr(temp,'@');
  12672. if(pch==NULL)
  12673. {
  12674. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12675. protocol, host, &port, path);
  12676. strcpy(user,"anonymous");
  12677. strcpy(password,"");
  12678. }
  12679. else
  12680. {
  12681. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12682. protocol, user, password, host, &port, path);
  12683. }
  12684. sscanf(host,"%[^/]%s",host1, path1);
  12685. sprintf(ftppath,"%s", path1);
  12686. //DEBUG_INFO("protocol =%s\n",protocol);
  12687. //DEBUG_INFO("user =%s\n",user);
  12688. //DEBUG_INFO("password =%s\n",password);
  12689. //DEBUG_INFO("host1 =%s\n",host1);
  12690. //DEBUG_INFO("port =%d\n",port);
  12691. //DEBUG_INFO("path1 =%s\n",path1);
  12692. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12693. //ftpFile(host, user, password, port, ftppath, fname);
  12694. //download firmware pthred
  12695. if(port == 0)
  12696. {
  12697. port = 21;
  12698. }
  12699. do
  12700. {
  12701. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12702. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12703. sleep(1);
  12704. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12705. if(!isSuccess)
  12706. {
  12707. //BulldogUtil.sleepMs(interval*1000);
  12708. DEBUG_INFO("Update firmware request and download file fail.\n");
  12709. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12710. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12711. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12712. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12713. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12714. }
  12715. else
  12716. {
  12717. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12718. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12719. }
  12720. retriesInt--;
  12721. }while((!isSuccess)&&(retriesInt >= 0));
  12722. }
  12723. else
  12724. {
  12725. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12726. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12727. sleep(1);
  12728. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12729. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12730. }
  12731. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12732. interLock.isUpdateFirmwareGoing = 0;
  12733. pthread_exit(NULL);
  12734. }
  12735. int handleCertificateSignedRequest(char *uuid, char *payload)
  12736. {
  12737. mtrace();
  12738. int result = PASS;
  12739. json_object *CertificateSigned;
  12740. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12741. CertificateSigned = json_tokener_parse(payload);
  12742. if(!is_error(CertificateSigned))
  12743. {
  12744. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  12745. }
  12746. json_object_put(CertificateSigned);
  12747. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  12748. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  12749. fclose(fp);
  12750. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12751. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  12752. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  12753. sendCertificateSignedConfirmation(uuid);
  12754. return result;
  12755. }
  12756. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12757. {
  12758. mtrace();
  12759. int result = PASS;
  12760. json_object *DeleteCertificate;
  12761. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12762. DeleteCertificate = json_tokener_parse(payload);
  12763. if(!is_error(DeleteCertificate))
  12764. {
  12765. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12766. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12767. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12768. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12769. }
  12770. json_object_put(DeleteCertificate);
  12771. /*
  12772. * TODO: Delete certificateSigned process
  12773. */
  12774. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  12775. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  12776. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  12777. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  12778. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  12779. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  12780. sendDeleteCertificateConfirmation(uuid);
  12781. return result;
  12782. }
  12783. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12784. {
  12785. mtrace();
  12786. int result = PASS;
  12787. json_object *ExtendedTriggerMessage;
  12788. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12789. ExtendedTriggerMessage = json_tokener_parse(payload);
  12790. if(!is_error(ExtendedTriggerMessage))
  12791. {
  12792. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12793. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12794. {
  12795. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12796. }
  12797. else
  12798. {
  12799. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  12800. }
  12801. }
  12802. json_object_put(ExtendedTriggerMessage);
  12803. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  12804. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  12805. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  12806. {
  12807. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  12808. }
  12809. else
  12810. {
  12811. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  12812. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  12813. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12814. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  12815. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  12816. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  12817. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  12818. {
  12819. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12820. }
  12821. else
  12822. {
  12823. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12824. }
  12825. }
  12826. sendExtendedTriggerMessageConfirmation(uuid);
  12827. //==========================
  12828. // Trigger message
  12829. //==========================
  12830. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  12831. {
  12832. //sendBootNotificationRequest();
  12833. server_sign = FALSE;
  12834. }
  12835. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  12836. {
  12837. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  12838. }
  12839. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12840. {
  12841. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12842. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12843. {
  12844. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12845. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12846. }
  12847. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12848. }
  12849. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  12850. {
  12851. refreshStartTimer(&clientTime.Heartbeat);
  12852. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  12853. }
  12854. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  12855. {
  12856. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12857. {
  12858. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  12859. }
  12860. else
  12861. {
  12862. for(int idx=0;idx< gunTotalNumber;idx++)
  12863. {
  12864. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12865. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12866. }
  12867. }
  12868. }
  12869. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  12870. {
  12871. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  12872. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  12873. {
  12874. 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\" &");
  12875. }
  12876. }
  12877. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  12878. {
  12879. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12880. {
  12881. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  12882. }
  12883. else
  12884. {
  12885. for(int idx=0;idx< gunTotalNumber;idx++)
  12886. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  12887. }
  12888. }
  12889. return result;
  12890. }
  12891. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  12892. {
  12893. mtrace();
  12894. int result = PASS;
  12895. json_object *GetInstalledCertificateIds;
  12896. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  12897. GetInstalledCertificateIds = json_tokener_parse(payload);
  12898. if(!is_error(GetInstalledCertificateIds))
  12899. {
  12900. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  12901. }
  12902. json_object_put(GetInstalledCertificateIds);
  12903. /*
  12904. * TODO: Return installed certificate process
  12905. */
  12906. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  12907. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  12908. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  12909. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  12910. sendGetInstalledCertificateIdsConfirmation(uuid);
  12911. return result;
  12912. }
  12913. int handleGetLogRequest(char *uuid, char *payload)
  12914. {
  12915. mtrace();
  12916. int result = PASS;
  12917. json_object *GetLog;
  12918. DEBUG_INFO("handleGetLogRequest...\n");
  12919. GetLog = json_tokener_parse(payload);
  12920. if(!is_error(GetLog))
  12921. {
  12922. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  12923. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  12924. if(json_object_object_get(GetLog, "retries") != NULL)
  12925. {
  12926. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  12927. }
  12928. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  12929. {
  12930. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  12931. }
  12932. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  12933. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  12934. {
  12935. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  12936. }
  12937. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  12938. {
  12939. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  12940. }
  12941. }
  12942. json_object_put(GetLog);
  12943. /*
  12944. * TODO: Upload log process
  12945. */
  12946. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  12947. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  12948. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  12949. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  12950. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  12951. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  12952. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  12953. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  12954. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  12955. sendGetLogConfirmation(uuid);
  12956. return result;
  12957. }
  12958. int handleInstallCertificateRequest(char *uuid, char *payload)
  12959. {
  12960. mtrace();
  12961. int result = PASS;
  12962. json_object *InstallCertificate;
  12963. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12964. InstallCertificate = json_tokener_parse(payload);
  12965. if(!is_error(InstallCertificate))
  12966. {
  12967. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12968. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12969. /*
  12970. * TODO: Install certificate process
  12971. */
  12972. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  12973. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  12974. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  12975. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  12976. sendInstallCertificateConfirmation(uuid);
  12977. }
  12978. json_object_put(InstallCertificate);
  12979. return result;
  12980. }
  12981. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12982. {
  12983. mtrace();
  12984. int result = PASS;
  12985. json_object *SignedUpdateFirmware;
  12986. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12987. SignedUpdateFirmware = json_tokener_parse(payload);
  12988. if(!is_error(SignedUpdateFirmware))
  12989. {
  12990. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12991. {
  12992. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12993. }
  12994. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12995. {
  12996. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12997. }
  12998. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12999. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13000. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13001. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13002. {
  13003. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13004. }
  13005. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13006. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13007. }
  13008. json_object_put(SignedUpdateFirmware);
  13009. /*
  13010. * TODO: Upgrade firmware process
  13011. */
  13012. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13013. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  13014. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  13015. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  13016. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  13017. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  13018. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  13019. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  13020. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  13021. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  13022. sendInstallCertificateConfirmation(uuid);
  13023. return result;
  13024. }
  13025. int handleUnknownRequest(char *uuid, char *payload)
  13026. {
  13027. mtrace();
  13028. int result = PASS;
  13029. DEBUG_INFO("handleUnknownRequest...\n");
  13030. sendUnknownConfirmation(uuid);
  13031. result = PASS;
  13032. return result;
  13033. }
  13034. //==========================================
  13035. // Handle server response routine
  13036. //==========================================
  13037. void handleAuthorizeResponse(char *payload, int gun_index)
  13038. {
  13039. mtrace();
  13040. char expiryDatestr[30]={0};
  13041. char parentIdTagstr[20]={0};
  13042. char statusstr[20]={0};
  13043. int expiryDateISNULL=FALSE;
  13044. int parentIdTagISNULL=FALSE;
  13045. DEBUG_INFO("handleAuthorizeResponse...\n");
  13046. json_object *Authorize;
  13047. Authorize = json_tokener_parse(payload);
  13048. if(!is_error(Authorize))
  13049. {
  13050. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13051. {
  13052. // Required data
  13053. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13054. // Optional data
  13055. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13056. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13057. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13058. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13059. }
  13060. }
  13061. json_object_put(Authorize);
  13062. if(expiryDateISNULL == FALSE)
  13063. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13064. if(parentIdTagISNULL == FALSE)
  13065. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13066. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  13067. //Update idTag information to authorization cache if supproted
  13068. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13069. {
  13070. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13071. }
  13072. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  13073. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13074. authorizeRetryTimes = 0;
  13075. }
  13076. void handleBootNotificationResponse(char *payload, int gun_index)
  13077. {
  13078. mtrace();
  13079. char statusStr[12]={0};
  13080. char currentTimeStr[30]={0};
  13081. int intervalInt = 0;
  13082. DEBUG_INFO("handleBootNotificationResponse...\n");
  13083. json_object *BootNotification;
  13084. BootNotification = json_tokener_parse(payload);
  13085. if(!is_error(BootNotification))
  13086. {
  13087. // Required data
  13088. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13089. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13090. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13091. }
  13092. json_object_put(BootNotification);
  13093. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13094. BootNotificationInterval = intervalInt;
  13095. //write back to ShmOCPP16Data->BootNotification
  13096. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  13097. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13098. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  13099. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13100. {
  13101. if((intervalInt == 0) || (intervalInt >= 10))
  13102. {
  13103. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13104. HeartBeatWaitTime = intervalInt;
  13105. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13106. }
  13107. server_sign = TRUE;
  13108. server_pending =FALSE;
  13109. }
  13110. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13111. {
  13112. server_pending = TRUE;
  13113. }
  13114. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  13115. srand(time(NULL));
  13116. refreshStartTimer(&clientTime.Heartbeat);
  13117. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13118. SetOcppConnStatus(TRUE);
  13119. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  13120. }
  13121. void handleDataTransferResponse(char *payload, int gun_index)
  13122. {
  13123. char sstr[160]={0};//sstr[200]={ 0 };
  13124. int c = 0;
  13125. char *loc;
  13126. DEBUG_INFO("handleDataTransferResponse ...\n");
  13127. loc = strstr(payload, "status");
  13128. c = 0;
  13129. while (loc[3+strlen("status")+c] != '\"')
  13130. {
  13131. sstr[c] = loc[3+strlen("status")+c];
  13132. c++;
  13133. }
  13134. sstr[c] = '\0';
  13135. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  13136. }
  13137. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13138. {
  13139. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13140. //struct json_object *obj;
  13141. // obj = json_tokener_parse(payload);
  13142. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13143. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13144. //No fields are defined.
  13145. }
  13146. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13147. {
  13148. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13149. //struct json_object *obj;
  13150. // obj = json_tokener_parse(payload);
  13151. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13152. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13153. //No fields are defined.
  13154. }
  13155. void handleHeartbeatResponse(char *payload, int gun_index)
  13156. {
  13157. mtrace();
  13158. DEBUG_INFO("handleHeartbeatResponse...\n");
  13159. json_object *Heartbeat;
  13160. Heartbeat = json_tokener_parse(payload);
  13161. if(!is_error(Heartbeat))
  13162. {
  13163. // Required data
  13164. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13165. }
  13166. json_object_put(Heartbeat);
  13167. if(FirstHeartBeat == 0)
  13168. {
  13169. FirstHeartBeat = 1;
  13170. DEBUG_INFO("FirstHeartBeat \n");
  13171. }
  13172. HeartBeatWithNOResponse = 0;
  13173. refreshStartTimer(&clientTime.Heartbeat);
  13174. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  13175. }
  13176. void handleMeterValuesResponse(char *payload, int gun_index)
  13177. {
  13178. mtrace();
  13179. DEBUG_INFO("handleMeterValuesResponse...\n");
  13180. isQueueSendable = 1;
  13181. }
  13182. void handleStartTransactionResponse(char *payload, int gun_index)
  13183. {
  13184. mtrace();
  13185. //int transactionIdInt = 0;
  13186. FILE *outfile;
  13187. char data[100]={0};
  13188. DEBUG_INFO("handleStartTransactionResponse...\n");
  13189. json_object *StartTransaction;
  13190. StartTransaction = json_tokener_parse(payload);
  13191. if(!is_error(StartTransaction))
  13192. {
  13193. // Required data
  13194. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13195. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13196. // Optional data
  13197. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13198. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13199. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13200. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13201. }
  13202. json_object_put(StartTransaction);
  13203. isQueueSendable = 1;
  13204. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13205. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13206. //-----------Start : write to the Queue TransactionId file -----------------//
  13207. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  13208. {}
  13209. else
  13210. {
  13211. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  13212. if(log == NULL)
  13213. {
  13214. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13215. return ;
  13216. }
  13217. else
  13218. {
  13219. fclose(log);
  13220. }
  13221. }
  13222. // open file for writing
  13223. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13224. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  13225. {
  13226. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  13227. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13228. fputs(data, outfile);
  13229. fclose (outfile);
  13230. }
  13231. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13232. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13233. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13234. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  13235. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13236. }
  13237. void handleStatusNotificationResponse(char *payload, int gun_index)
  13238. {
  13239. mtrace();
  13240. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13241. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13242. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13243. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13244. }
  13245. void handleStopTransactionnResponse(char *payload, int gun_index)
  13246. {
  13247. mtrace();
  13248. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13249. json_object *StopTransaction;
  13250. StopTransaction = json_tokener_parse(payload);
  13251. if(!is_error(StopTransaction))
  13252. {
  13253. // Optional data
  13254. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13255. {
  13256. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13257. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13258. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13259. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13260. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13261. }
  13262. }
  13263. json_object_put(StopTransaction);
  13264. isQueueSendable = 1;
  13265. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13266. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13267. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13268. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13269. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13270. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13271. }
  13272. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13273. {
  13274. mtrace();
  13275. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13276. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  13277. }
  13278. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13279. {
  13280. mtrace();
  13281. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13282. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  13283. }
  13284. void handleSignCertificateResponse(char *payload, int gun_index)
  13285. {
  13286. mtrace();
  13287. DEBUG_INFO("handleSignCertificateResponse...\n");
  13288. json_object *SignCertificate;
  13289. SignCertificate = json_tokener_parse(payload);
  13290. if(!is_error(SignCertificate))
  13291. {
  13292. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13293. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  13294. }
  13295. json_object_put(SignCertificate);
  13296. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  13297. }
  13298. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13299. {
  13300. mtrace();
  13301. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13302. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13303. }
  13304. //==========================================
  13305. // Handle Error routine
  13306. //==========================================
  13307. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13308. {
  13309. mtrace();
  13310. #ifdef SystemLogMessage
  13311. DEBUG_INFO("errorCode: %s\n", errorCode);
  13312. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13313. DEBUG_INFO("errorDetails: %s\n", payload);
  13314. #endif
  13315. }
  13316. //===============================================
  13317. // Common routine
  13318. //===============================================
  13319. int initialConfigurationTable(void)
  13320. {
  13321. //clock_t start_t, end_t, total_t;
  13322. FILE *fp;
  13323. FILE *outfile;
  13324. char str[512]={0};
  13325. char sstr[256]={0};
  13326. int c = 0;
  13327. char *loc;
  13328. int confVersion = 11;
  13329. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13330. //start_t = clock();
  13331. //printf("Starting of the program, start_t = %ld\n", start_t);
  13332. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13333. // Check configuration file size is correct
  13334. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  13335. {
  13336. struct stat st;
  13337. stat("/Storage/OCPP/OCPPConfiguration", &st);
  13338. if(st.st_size < 3100)
  13339. {
  13340. system("rm -f /Storage/OCPP/OCPPConfiguration");
  13341. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13342. }
  13343. }
  13344. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  13345. {
  13346. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13347. if(outfile == NULL)
  13348. {
  13349. DEBUG_INFO("Error opening file\n");
  13350. return FALSE;
  13351. }
  13352. /*Core Profile*/
  13353. //AllowOfflineTxForUnknownId
  13354. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13357. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13358. //AuthorizationCacheEnabled
  13359. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13362. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13363. //AuthorizeRemoteTxRequests
  13364. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13367. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13368. //BlinkRepeat
  13369. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13372. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13373. //ClockAlignedDataInterval
  13374. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13375. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13377. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13378. //ConnectionTimeOut
  13379. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13382. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13383. //GetConfigurationMaxKeys
  13384. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13386. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13387. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13388. // HeartbeatInterval
  13389. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13392. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13393. // LightIntensity
  13394. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13397. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13398. // LocalAuthorizeOffline
  13399. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13402. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13403. // LocalPreAuthorize
  13404. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13407. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13408. // MaxEnergyOnInvalidId
  13409. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13412. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13413. // MeterValuesAlignedData
  13414. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13416. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13417. 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" );
  13418. else
  13419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13420. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13421. // MeterValuesAlignedDataMaxLength
  13422. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13423. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13424. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13426. else
  13427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13428. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13429. // MeterValuesSampledData
  13430. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13432. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13433. 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" );
  13434. else
  13435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13436. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13437. // MeterValuesSampledDataMaxLength
  13438. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13440. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13442. else
  13443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13444. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13445. // MeterValueSampleInterval
  13446. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13449. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13450. // MinimumStatusDuration
  13451. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13452. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13453. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13454. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13455. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13456. // NumberOfConnectors
  13457. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13459. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13460. {
  13461. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13462. }
  13463. else
  13464. {
  13465. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13466. }
  13467. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13468. // ResetRetries
  13469. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13470. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13471. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13472. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13473. // ConnectorPhaseRotation
  13474. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13475. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13477. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13478. // ConnectorPhaseRotationMaxLength
  13479. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13480. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13481. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13482. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13483. // StopTransactionOnEVSideDisconnect
  13484. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13485. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13486. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13487. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13488. // StopTransactionOnInvalidId
  13489. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13491. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13492. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13493. // StopTxnAlignedData
  13494. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13495. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13497. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13498. // StopTxnAlignedDataMaxLength
  13499. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13500. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13502. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13503. // StopTxnSampledData
  13504. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13505. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13506. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13508. else
  13509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13510. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13511. // StopTxnSampledDataMaxLength
  13512. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13513. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13514. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13515. {
  13516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13517. }
  13518. else
  13519. {
  13520. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13521. }
  13522. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13523. // SupportedFeatureProfiles
  13524. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13527. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13528. // SupportedFeatureProfilesMaxLength
  13529. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13530. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13532. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13533. // TransactionMessageAttempts
  13534. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13537. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13538. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13539. // TransactionMessageRetryInterval
  13540. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13543. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13544. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13545. // UnlockConnectorOnEVSideDisconnect
  13546. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13549. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13550. // WebSocketPingInterval
  13551. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13554. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13555. // QueueOffLineMeterValues
  13556. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13559. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13560. // AuthorizationKey
  13561. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  13564. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13565. // SecurityProfile
  13566. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13568. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  13569. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13570. // DefaultPrice
  13571. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13574. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13575. // CustomDisplayCostAndPrice
  13576. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13579. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13580. // CustomIdleFeeAfterStop
  13581. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13584. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13585. // TimeOffset
  13586. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  13589. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13590. // NextTimeOffsetTransitionDateTime
  13591. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13592. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13593. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  13594. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13595. // TimeOffsetNextTransition
  13596. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  13599. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13600. // SystemUptimeSec
  13601. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13604. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13605. // FreeVend
  13606. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13607. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "Free-FreeVend");
  13608. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13609. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13610. // OcppServer
  13611. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13613. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13614. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13615. // MaintainServer
  13616. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13618. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13619. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13620. // Configuration Version
  13621. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13623. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13624. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13625. //* Local Auth List Management Profile*/
  13626. #if 0
  13627. //For OCTT Test Case
  13628. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13629. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13631. #endif
  13632. #if 1
  13633. //LocalAuthListEnabled
  13634. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13637. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13638. #endif
  13639. //LocalAuthListMaxLength
  13640. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  13643. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13644. //SendLocalListMaxLength
  13645. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13648. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13649. //ReserveConnectorZeroSupported
  13650. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13654. //* Smart Charging Profile */
  13655. //ChargeProfileMaxStackLevel
  13656. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13659. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13660. // ChargingScheduleAllowedChargingRateUnit
  13661. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13663. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13664. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13665. // ChargingScheduleMaxPeriods
  13666. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13669. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13670. // ConnectorSwitch3to1PhaseSupported
  13671. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13674. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13675. // MaxChargingProfilesInstalled
  13676. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13679. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13680. fclose(outfile);
  13681. }
  13682. else
  13683. {
  13684. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  13685. char keystr[60]={0};
  13686. char readonlystr[10]={0};
  13687. char valuestr[256]={0};
  13688. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  13689. if(fp == NULL) {
  13690. DEBUG_INFO("Error opening file");
  13691. return FALSE;
  13692. }
  13693. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13694. {
  13695. //DEBUG_INFO("Get Configuration \n");
  13696. if(strlen(str) > 0)
  13697. {
  13698. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13699. //*************************key*********************************/
  13700. if(strstr(str, "key") != NULL)
  13701. {
  13702. loc = strstr(str, "key");
  13703. c = 0;
  13704. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13705. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13706. {
  13707. sstr[c] = loc[strlen("key")+3+c];
  13708. c++;
  13709. }
  13710. sstr[c] = '\0';
  13711. strcpy(keystr,sstr);
  13712. }
  13713. //*************************readonly*********************************/
  13714. if(strstr(str, "readonly") != NULL)
  13715. {
  13716. loc = strstr(str, "readonly");
  13717. c = 0;
  13718. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13719. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13720. {
  13721. sstr[c] = loc[strlen("readonly")+2+c];
  13722. c++;
  13723. }
  13724. sstr[c] = '\0';
  13725. strcpy(readonlystr,sstr);
  13726. }
  13727. //*************************value*********************************/
  13728. if(strstr(str, "value") != NULL)
  13729. {
  13730. loc = strstr(str, "value");
  13731. c = 0;
  13732. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13733. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13734. {
  13735. sstr[c] = loc[strlen("value")+3+c];
  13736. c++;
  13737. }
  13738. sstr[c] = '\0';
  13739. strcpy(valuestr,sstr);
  13740. }
  13741. // DEBUG_INFO("keystr=%s\n",keystr);
  13742. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13743. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13744. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13745. {
  13746. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13747. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13748. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13749. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13750. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13751. }
  13752. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13753. {
  13754. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13755. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13756. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13757. }
  13758. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13759. {
  13760. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13761. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13762. }
  13763. if(strcmp(keystr, "BlinkRepeat") == 0)
  13764. {
  13765. //Charger.BlinkRepeat = Integer.parseInt(value);
  13766. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13767. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13768. }
  13769. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13770. {
  13771. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13772. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13773. }
  13774. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13775. {
  13776. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13777. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13778. }
  13779. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13780. {
  13781. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13782. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13783. }
  13784. if(strcmp(keystr, "HeartbeatInterval") == 0)
  13785. {
  13786. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13787. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  13788. HeartBeatWaitTime = atoi(valuestr);
  13789. }
  13790. if(strcmp(keystr, "LightIntensity") == 0)
  13791. {
  13792. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13793. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  13794. }
  13795. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  13796. {
  13797. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13798. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  13799. }
  13800. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  13801. {
  13802. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13803. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  13804. }
  13805. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  13806. {
  13807. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13808. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  13809. }
  13810. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  13811. {
  13812. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13813. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  13814. }
  13815. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  13816. {
  13817. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13818. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  13819. }
  13820. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  13821. {
  13822. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13823. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  13824. }
  13825. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  13826. {
  13827. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13828. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  13829. }
  13830. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  13831. {
  13832. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13833. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  13834. }
  13835. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  13836. {
  13837. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13838. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  13839. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  13840. }
  13841. if(strcmp(keystr, "NumberOfConnectors") == 0)
  13842. {
  13843. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13844. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  13845. }
  13846. if(strcmp(keystr, "ResetRetries") == 0)
  13847. {
  13848. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13849. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  13850. }
  13851. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  13852. {
  13853. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13854. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  13855. }
  13856. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  13857. {
  13858. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13859. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  13860. }
  13861. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  13862. {
  13863. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13864. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  13865. }
  13866. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  13867. {
  13868. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13869. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  13870. }
  13871. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  13872. {
  13873. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13874. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  13875. }
  13876. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  13877. {
  13878. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13879. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13880. }
  13881. if(strcmp(keystr, "StopTxnSampledData") == 0)
  13882. {
  13883. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13884. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  13885. }
  13886. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  13887. {
  13888. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13889. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13890. }
  13891. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  13892. {
  13893. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13894. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  13895. }
  13896. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  13897. {
  13898. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13899. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  13900. }
  13901. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  13902. {
  13903. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13904. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  13905. TransactionMessageAttemptsValue = atoi(valuestr);
  13906. }
  13907. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  13908. {
  13909. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13910. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  13911. TransactionMessageRetryIntervalValue = atoi(valuestr);
  13912. }
  13913. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  13914. {
  13915. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13916. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  13917. }
  13918. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  13919. {
  13920. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13921. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  13922. }
  13923. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  13924. {
  13925. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13926. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  13927. }
  13928. if(strcmp(keystr, "AuthorizationKey") == 0)
  13929. {
  13930. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13931. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  13932. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  13933. }
  13934. if(strcmp(keystr, "SecurityProfile") == 0)
  13935. {
  13936. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13937. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  13938. }
  13939. if(strcmp(keystr, "DefaultPrice") == 0)
  13940. {
  13941. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13942. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  13943. }
  13944. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  13945. {
  13946. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13947. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  13948. }
  13949. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  13950. {
  13951. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13952. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  13953. }
  13954. if(strcmp(keystr, "TimeOffset") == 0)
  13955. {
  13956. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13957. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  13958. }
  13959. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  13960. {
  13961. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13962. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  13963. }
  13964. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  13965. {
  13966. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13967. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  13968. }
  13969. if(strcmp(keystr, "SystemUptimeSec") == 0)
  13970. {
  13971. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13972. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  13973. }
  13974. if(strcmp(keystr, "FreeVend") == 0)
  13975. {
  13976. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13977. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  13978. }
  13979. if(strcmp(keystr, "OcppServer") == 0)
  13980. {
  13981. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13982. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13983. }
  13984. if(strcmp(keystr, "MaintainServer") == 0)
  13985. {
  13986. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13987. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  13988. }
  13989. if(strcmp(keystr, "ConfigurationVersion") == 0)
  13990. {
  13991. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13992. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  13993. }
  13994. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  13995. {
  13996. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13997. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  13998. }
  13999. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14000. {
  14001. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14002. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14003. }
  14004. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14005. {
  14006. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14007. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14008. }
  14009. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14010. {
  14011. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14013. }
  14014. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14015. {
  14016. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14017. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14018. }
  14019. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14020. {
  14021. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14022. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14023. }
  14024. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14025. {
  14026. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14027. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14028. }
  14029. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14030. {
  14031. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14032. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14033. }
  14034. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14035. {
  14036. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14037. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14038. }
  14039. }
  14040. }
  14041. fclose(fp);
  14042. }
  14043. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14044. {
  14045. return PASS;
  14046. }
  14047. else
  14048. {
  14049. return FAIL;
  14050. }
  14051. }
  14052. void StoreConfigurationTable(void)
  14053. {
  14054. FILE *outfile;
  14055. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14056. if(outfile == NULL)
  14057. {
  14058. DEBUG_INFO("Error opening file");
  14059. return ;
  14060. }
  14061. /*Core Profile*/
  14062. //AllowOfflineTxForUnknownId
  14063. /*
  14064. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14065. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14067. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14068. */
  14069. //DEBUG_INFO("data=%s\n",data);
  14070. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14071. //AuthorizationCacheEnabled
  14072. /*
  14073. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14076. */
  14077. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14078. //AuthorizeRemoteTxRequests
  14079. /*
  14080. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14083. */
  14084. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14085. //BlinkRepeat
  14086. /*
  14087. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14090. */
  14091. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14092. //ClockAlignedDataInterval
  14093. /*
  14094. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14097. */
  14098. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14099. //ConnectionTimeOut
  14100. /*
  14101. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14104. */
  14105. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14106. //GetConfigurationMaxKeys
  14107. /*
  14108. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14111. */
  14112. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14113. // HeartbeatInterval
  14114. /*
  14115. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14118. */
  14119. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14120. // LightIntensity
  14121. /*
  14122. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14125. */
  14126. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14127. // LocalAuthorizeOffline
  14128. /*
  14129. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14132. */
  14133. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14134. // LocalPreAuthorize
  14135. /*
  14136. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14139. */
  14140. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14141. // MaxEnergyOnInvalidId
  14142. /*
  14143. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14144. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14145. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14146. */
  14147. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14148. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14149. // MeterValuesAlignedData
  14150. /*
  14151. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14154. */
  14155. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14156. // MeterValuesAlignedDataMaxLength
  14157. /*
  14158. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14159. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14161. */
  14162. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14163. // MeterValuesSampledData
  14164. /*
  14165. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14168. */
  14169. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14170. // MeterValuesSampledDataMaxLength
  14171. /*
  14172. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14175. */
  14176. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14177. // MeterValueSampleInterval
  14178. /*
  14179. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14182. */
  14183. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14184. // MinimumStatusDuration
  14185. /*
  14186. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14189. */
  14190. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14191. // NumberOfConnectors
  14192. /*
  14193. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14194. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14195. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14196. {
  14197. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14198. }
  14199. else
  14200. {
  14201. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14202. }
  14203. */
  14204. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14205. // ResetRetries
  14206. /*
  14207. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14210. */
  14211. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14212. // ConnectorPhaseRotation
  14213. /*
  14214. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14217. */
  14218. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14219. // ConnectorPhaseRotationMaxLength
  14220. /*
  14221. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14222. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14224. */
  14225. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14226. // StopTransactionOnEVSideDisconnect
  14227. /*
  14228. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14229. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14231. */
  14232. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14233. // StopTransactionOnInvalidId
  14234. /*
  14235. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14236. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14238. */
  14239. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14240. // StopTxnAlignedData
  14241. /*
  14242. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14245. */
  14246. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14247. // StopTxnAlignedDataMaxLength
  14248. /*
  14249. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14252. */
  14253. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14254. // StopTxnSampledData
  14255. /*
  14256. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14257. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14259. */
  14260. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14261. // StopTxnSampledDataMaxLength
  14262. /*
  14263. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14266. */
  14267. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14268. // SupportedFeatureProfiles
  14269. /*
  14270. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14271. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14273. */
  14274. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14275. // SupportedFeatureProfilesMaxLength
  14276. /*
  14277. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14280. */
  14281. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14282. // TransactionMessageAttempts
  14283. /*
  14284. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14287. */
  14288. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14289. // TransactionMessageRetryInterval
  14290. /*
  14291. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14294. */
  14295. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14296. // UnlockConnectorOnEVSideDisconnect
  14297. /*
  14298. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14301. */
  14302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14303. // WebSocketPingInterval
  14304. /*
  14305. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14308. */
  14309. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14310. // QueueOffLineMeterValues
  14311. /*
  14312. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14313. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14315. */
  14316. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14317. // AuthorizationKey
  14318. /*
  14319. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14322. */
  14323. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14324. // SecurityProfile
  14325. /*
  14326. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14329. */
  14330. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14331. // DefaultPrice
  14332. /*
  14333. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14336. */
  14337. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14338. // CustomDisplayCostAndPrice
  14339. /*
  14340. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14341. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14343. */
  14344. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14345. // CustomIdleFeeAfterStop
  14346. /*
  14347. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14350. */
  14351. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14352. // TimeOffset
  14353. /*
  14354. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  14357. */
  14358. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14359. // NextTimeOffsetTransitionDateTime
  14360. /*
  14361. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  14364. */
  14365. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14366. // TimeOffsetNextTransition
  14367. /*
  14368. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14369. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  14371. */
  14372. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14373. // SystemUptimeSec
  14374. /*
  14375. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14378. */
  14379. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14380. // FreeVend
  14381. /*
  14382. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14385. */
  14386. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14387. // OcppServer
  14388. /*
  14389. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14392. */
  14393. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14394. // MaintainServer
  14395. /*
  14396. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14399. */
  14400. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14401. // ConfigurationVersion
  14402. /*
  14403. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14404. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14406. */
  14407. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14408. //* Local Auth List Management Profile*/
  14409. //LocalAuthListEnabled
  14410. /*
  14411. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14413. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14414. */
  14415. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14416. //LocalAuthListMaxLength
  14417. /*
  14418. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14421. */
  14422. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14423. //SendLocalListMaxLength
  14424. /*
  14425. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14428. */
  14429. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14430. //ReserveConnectorZeroSupported
  14431. /*
  14432. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14435. */
  14436. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14437. //* Smart Charging Profile */
  14438. //ChargeProfileMaxStackLevel
  14439. /*
  14440. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14442. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14443. */
  14444. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14445. // ChargingScheduleAllowedChargingRateUnit
  14446. /*
  14447. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14450. */
  14451. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14452. // ChargingScheduleMaxPeriods
  14453. /*
  14454. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14456. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14457. */
  14458. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14459. // ConnectorSwitch3to1PhaseSupported
  14460. /*
  14461. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14463. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14464. */
  14465. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14466. // MaxChargingProfilesInstalled
  14467. /*
  14468. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14469. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14470. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14471. */
  14472. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14473. fclose(outfile);
  14474. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14475. }
  14476. void getKeyValue(char *keyReq)
  14477. {
  14478. int isEmpty = FALSE;
  14479. int isKnowKey = FALSE;
  14480. DEBUG_INFO("keyReq = %s\n", keyReq);
  14481. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14482. isEmpty = TRUE;
  14483. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14484. {
  14485. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14487. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14488. {
  14489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14490. }
  14491. else
  14492. {
  14493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14494. }
  14495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14496. isKnowKey = TRUE;
  14497. }
  14498. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14499. {
  14500. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14502. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14503. {
  14504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14505. }
  14506. else
  14507. {
  14508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14509. }
  14510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14511. isKnowKey = TRUE;
  14512. }
  14513. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14514. {
  14515. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14517. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14518. {
  14519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14520. }
  14521. else
  14522. {
  14523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14524. }
  14525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14526. isKnowKey = TRUE;
  14527. }
  14528. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14529. {
  14530. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14532. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14533. {
  14534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14535. }
  14536. else
  14537. {
  14538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14539. }
  14540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14541. isKnowKey = TRUE;
  14542. }
  14543. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14544. {
  14545. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14547. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14548. {
  14549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14550. }
  14551. else
  14552. {
  14553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14554. }
  14555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14556. isKnowKey = TRUE;
  14557. }
  14558. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14559. {
  14560. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14562. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14563. {
  14564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14565. }
  14566. else
  14567. {
  14568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14569. }
  14570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14571. isKnowKey = TRUE;
  14572. }
  14573. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14574. {
  14575. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14577. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14578. {
  14579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14580. }
  14581. else
  14582. {
  14583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14584. }
  14585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14586. isKnowKey = TRUE;
  14587. }
  14588. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14589. {
  14590. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14592. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14593. {
  14594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14595. }
  14596. else
  14597. {
  14598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14599. }
  14600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14601. isKnowKey = TRUE;
  14602. }
  14603. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14604. {
  14605. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14607. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14608. {
  14609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14610. }
  14611. else
  14612. {
  14613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14614. }
  14615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14616. isKnowKey = TRUE;
  14617. }
  14618. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14619. {
  14620. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14622. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14623. {
  14624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14625. }
  14626. else
  14627. {
  14628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14629. }
  14630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14631. isKnowKey = TRUE;
  14632. }
  14633. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14634. {
  14635. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14637. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14638. {
  14639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14640. }
  14641. else
  14642. {
  14643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14644. }
  14645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14646. isKnowKey = TRUE;
  14647. }
  14648. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14649. {
  14650. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14651. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14652. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14653. {
  14654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14655. }
  14656. else
  14657. {
  14658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14659. }
  14660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14661. isKnowKey = TRUE;
  14662. }
  14663. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14664. {
  14665. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14667. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14668. {
  14669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14670. }
  14671. else
  14672. {
  14673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14674. }
  14675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14676. isKnowKey = TRUE;
  14677. }
  14678. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14679. {
  14680. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14681. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14682. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14683. {
  14684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14685. }
  14686. else
  14687. {
  14688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14689. }
  14690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14691. isKnowKey = TRUE;
  14692. }
  14693. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14694. {
  14695. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14696. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14697. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14698. {
  14699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14700. }
  14701. else
  14702. {
  14703. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14704. }
  14705. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14706. isKnowKey = TRUE;
  14707. }
  14708. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14709. {
  14710. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14711. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14712. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14713. {
  14714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14715. }
  14716. else
  14717. {
  14718. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14719. }
  14720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14721. isKnowKey = TRUE;
  14722. }
  14723. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14724. {
  14725. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14726. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14727. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14728. {
  14729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14730. }
  14731. else
  14732. {
  14733. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14734. }
  14735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14736. isKnowKey = TRUE;
  14737. }
  14738. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14739. {
  14740. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14742. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14743. {
  14744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14745. }
  14746. else
  14747. {
  14748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14749. }
  14750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  14751. isKnowKey = TRUE;
  14752. }
  14753. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14754. {
  14755. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14757. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14758. {
  14759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14760. }
  14761. else
  14762. {
  14763. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14764. }
  14765. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  14766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  14767. isKnowKey = TRUE;
  14768. }
  14769. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  14770. {
  14771. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  14772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  14773. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14774. {
  14775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  14776. }
  14777. else
  14778. {
  14779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  14780. }
  14781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  14782. isKnowKey = TRUE;
  14783. }
  14784. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  14785. {
  14786. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  14787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  14788. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14789. {
  14790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  14791. }
  14792. else
  14793. {
  14794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  14795. }
  14796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  14797. isKnowKey = TRUE;
  14798. }
  14799. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  14800. {
  14801. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  14802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  14803. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14804. {
  14805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14806. }
  14807. else
  14808. {
  14809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14810. }
  14811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  14812. isKnowKey = TRUE;
  14813. }
  14814. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  14815. {
  14816. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  14817. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  14818. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14819. {
  14820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14821. }
  14822. else
  14823. {
  14824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14825. }
  14826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  14827. isKnowKey = TRUE;
  14828. }
  14829. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  14830. {
  14831. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  14832. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  14833. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14834. {
  14835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14836. }
  14837. else
  14838. {
  14839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14840. }
  14841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  14842. isKnowKey = TRUE;
  14843. }
  14844. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  14845. {
  14846. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  14847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  14848. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14849. {
  14850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14851. }
  14852. else
  14853. {
  14854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14855. }
  14856. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  14857. isKnowKey = TRUE;
  14858. }
  14859. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  14860. {
  14861. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  14862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  14863. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14864. {
  14865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14866. }
  14867. else
  14868. {
  14869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14870. }
  14871. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  14872. isKnowKey = TRUE;
  14873. }
  14874. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  14875. {
  14876. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  14877. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  14878. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14879. {
  14880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  14881. }
  14882. else
  14883. {
  14884. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  14885. }
  14886. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  14887. isKnowKey = TRUE;
  14888. }
  14889. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  14890. {
  14891. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  14892. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  14893. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14894. {
  14895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14896. }
  14897. else
  14898. {
  14899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14900. }
  14901. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  14902. isKnowKey = TRUE;
  14903. }
  14904. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  14905. {
  14906. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  14907. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  14908. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14909. {
  14910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  14911. }
  14912. else
  14913. {
  14914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  14915. }
  14916. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  14917. isKnowKey = TRUE;
  14918. }
  14919. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  14920. {
  14921. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  14922. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  14923. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14924. {
  14925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14926. }
  14927. else
  14928. {
  14929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14930. }
  14931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  14932. isKnowKey = TRUE;
  14933. }
  14934. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  14935. {
  14936. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  14937. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  14938. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14939. {
  14940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  14941. }
  14942. else
  14943. {
  14944. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  14945. }
  14946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  14947. isKnowKey = TRUE;
  14948. }
  14949. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  14950. {
  14951. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  14952. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  14953. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14954. {
  14955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  14956. }
  14957. else
  14958. {
  14959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  14960. }
  14961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  14962. isKnowKey = TRUE;
  14963. }
  14964. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  14965. {
  14966. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  14967. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  14968. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14969. {
  14970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14971. }
  14972. else
  14973. {
  14974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14975. }
  14976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  14977. isKnowKey = TRUE;
  14978. }
  14979. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  14980. {
  14981. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  14982. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  14983. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14984. {
  14985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  14986. }
  14987. else
  14988. {
  14989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  14990. }
  14991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  14992. isKnowKey = TRUE;
  14993. }
  14994. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  14995. {
  14996. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  14997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  14998. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14999. {
  15000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15001. }
  15002. else
  15003. {
  15004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15005. }
  15006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15007. isKnowKey = TRUE;
  15008. }
  15009. /*
  15010. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15011. {
  15012. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15014. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15015. {
  15016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15017. }
  15018. else
  15019. {
  15020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15021. }
  15022. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15023. isKnowKey = TRUE;
  15024. }*/
  15025. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15026. {
  15027. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15029. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15030. {
  15031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15032. }
  15033. else
  15034. {
  15035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15036. }
  15037. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15038. isKnowKey = TRUE;
  15039. }
  15040. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15041. {
  15042. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15044. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15045. {
  15046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15047. }
  15048. else
  15049. {
  15050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15051. }
  15052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15053. isKnowKey = TRUE;
  15054. }
  15055. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15056. {
  15057. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15059. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15060. {
  15061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15062. }
  15063. else
  15064. {
  15065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15066. }
  15067. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15068. isKnowKey = TRUE;
  15069. }
  15070. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15071. {
  15072. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15074. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15075. {
  15076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15077. }
  15078. else
  15079. {
  15080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15081. }
  15082. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15083. isKnowKey = TRUE;
  15084. }
  15085. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  15086. {
  15087. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  15088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  15089. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15090. {
  15091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  15092. }
  15093. else
  15094. {
  15095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  15096. }
  15097. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  15098. isKnowKey = TRUE;
  15099. }
  15100. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  15101. {
  15102. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  15103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  15104. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15105. {
  15106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  15107. }
  15108. else
  15109. {
  15110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  15111. }
  15112. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  15113. isKnowKey = TRUE;
  15114. }
  15115. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  15116. {
  15117. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  15118. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  15119. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15120. {
  15121. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  15122. }
  15123. else
  15124. {
  15125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  15126. }
  15127. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  15128. isKnowKey = TRUE;
  15129. }
  15130. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15131. {
  15132. struct sysinfo s_info;
  15133. int error = sysinfo(&s_info);
  15134. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15135. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15136. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15137. {
  15138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15139. }
  15140. else
  15141. {
  15142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15143. }
  15144. if(error != 0)
  15145. {
  15146. DEBUG_WARN("System uptime get error: %d\n", error);
  15147. }
  15148. else
  15149. {
  15150. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15151. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15152. }
  15153. isKnowKey = TRUE;
  15154. }
  15155. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15156. {
  15157. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15159. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15160. {
  15161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15162. }
  15163. else
  15164. {
  15165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15166. }
  15167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  15168. isKnowKey = TRUE;
  15169. }
  15170. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15171. {
  15172. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15174. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15175. {
  15176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15177. }
  15178. else
  15179. {
  15180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15181. }
  15182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15183. isKnowKey = TRUE;
  15184. }
  15185. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15186. {
  15187. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15189. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15190. {
  15191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15192. }
  15193. else
  15194. {
  15195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15196. }
  15197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15198. isKnowKey = TRUE;
  15199. }
  15200. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15201. {
  15202. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15204. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15205. {
  15206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15207. }
  15208. else
  15209. {
  15210. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15211. }
  15212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15213. isKnowKey = TRUE;
  15214. }
  15215. #if 1
  15216. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15217. {
  15218. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15220. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15221. {
  15222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15223. }
  15224. else
  15225. {
  15226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15227. }
  15228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15229. isKnowKey = TRUE;
  15230. }
  15231. #endif
  15232. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15233. {
  15234. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15236. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15237. {
  15238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15239. }
  15240. else
  15241. {
  15242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15243. }
  15244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15245. isKnowKey = TRUE;
  15246. }
  15247. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15248. {
  15249. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15251. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15252. {
  15253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15254. }
  15255. else
  15256. {
  15257. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15258. }
  15259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15260. isKnowKey = TRUE;
  15261. }
  15262. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15263. {
  15264. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15266. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15267. {
  15268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15269. }
  15270. else
  15271. {
  15272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15273. }
  15274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15275. isKnowKey = TRUE;
  15276. }
  15277. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15278. {
  15279. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15281. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15282. {
  15283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15284. }
  15285. else
  15286. {
  15287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15288. }
  15289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15290. isKnowKey = TRUE;
  15291. }
  15292. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15293. {
  15294. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15296. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15297. {
  15298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15299. }
  15300. else
  15301. {
  15302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15303. }
  15304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15305. isKnowKey = TRUE;
  15306. }
  15307. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15308. {
  15309. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15311. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15312. {
  15313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15314. }
  15315. else
  15316. {
  15317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15318. }
  15319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15320. isKnowKey = TRUE;
  15321. }
  15322. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15323. {
  15324. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15326. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15327. {
  15328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15329. }
  15330. else
  15331. {
  15332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15333. }
  15334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15335. isKnowKey = TRUE;
  15336. }
  15337. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15338. {
  15339. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15341. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15342. {
  15343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15344. }
  15345. else
  15346. {
  15347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15348. }
  15349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15350. isKnowKey = TRUE;
  15351. }
  15352. //=========================================================
  15353. if(!isEmpty && !isKnowKey)
  15354. {
  15355. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15356. strcpy(unknownkey[UnknownKeynum], keyReq);
  15357. UnknownKeynum = UnknownKeynum + 1;
  15358. }
  15359. }
  15360. void processUnkownKey(void)
  15361. {
  15362. DEBUG_INFO("processUnkownKey...\n");
  15363. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15364. for(int index=0; index < UnknownKeynum; index++)
  15365. {
  15366. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15367. {
  15368. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15369. }
  15370. }
  15371. }
  15372. int setKeyValue(char *key, char *value)
  15373. {
  15374. int isSuccess = NotSupported;
  15375. int check_ascii=0;
  15376. char str[501]={0};
  15377. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15378. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15379. {
  15380. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15381. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15382. {
  15383. strcpy(str, (const char*)value);
  15384. for(int i = 0; str[i]; i++){
  15385. str[i] = tolower(str[i]);
  15386. }
  15387. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15388. isSuccess = ConfigurationStatus_Accepted;
  15389. }
  15390. else
  15391. {
  15392. isSuccess = ConfigurationStatus_Rejected;
  15393. }
  15394. }
  15395. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15396. {
  15397. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15398. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15399. {
  15400. strcpy(str, (const char*)value);
  15401. for(int i = 0; str[i]; i++){
  15402. str[i] = tolower(str[i]);
  15403. }
  15404. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15405. isSuccess = ConfigurationStatus_Accepted;
  15406. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  15407. }
  15408. else
  15409. {
  15410. isSuccess = ConfigurationStatus_Rejected;
  15411. }
  15412. }
  15413. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15414. {
  15415. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15416. {
  15417. strcpy(str, (const char*)value);
  15418. for(int i = 0; str[i]; i++)
  15419. {
  15420. str[i] = tolower(str[i]);
  15421. }
  15422. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15423. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15424. isSuccess = ConfigurationStatus_Accepted;
  15425. }
  15426. else
  15427. {
  15428. isSuccess = ConfigurationStatus_Rejected;
  15429. }
  15430. }
  15431. if(strcmp(key, "BlinkRepeat") == 0)
  15432. {
  15433. //Charger.BlinkRepeat = Integer.parseInt(value);
  15434. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15435. {
  15436. check_ascii = value[0];
  15437. if( (check_ascii < 48) || (check_ascii > 57) )
  15438. {
  15439. isSuccess = ConfigurationStatus_Rejected;
  15440. }
  15441. else
  15442. {
  15443. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15444. isSuccess = ConfigurationStatus_Accepted;
  15445. }
  15446. }
  15447. else
  15448. {
  15449. isSuccess = ConfigurationStatus_Rejected;
  15450. }
  15451. }
  15452. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15453. {
  15454. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15455. {
  15456. check_ascii = value[0];
  15457. if( (check_ascii < 48) || (check_ascii > 57) )
  15458. {
  15459. isSuccess = ConfigurationStatus_Rejected;
  15460. }
  15461. else
  15462. {
  15463. if((atoi(value) == 0) || (atoi(value) >= 5))
  15464. {
  15465. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15466. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15467. isSuccess = ConfigurationStatus_Accepted;
  15468. }
  15469. else
  15470. isSuccess = ConfigurationStatus_Rejected;
  15471. }
  15472. }
  15473. else
  15474. {
  15475. isSuccess = ConfigurationStatus_Rejected;
  15476. }
  15477. }
  15478. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15479. {
  15480. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15481. {
  15482. check_ascii = value[0];
  15483. if( (check_ascii < 48) || (check_ascii > 57) )
  15484. {
  15485. isSuccess = ConfigurationStatus_Rejected;
  15486. }
  15487. else
  15488. {
  15489. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15490. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15491. isSuccess = ConfigurationStatus_Accepted;
  15492. }
  15493. }
  15494. else
  15495. {
  15496. isSuccess = ConfigurationStatus_Rejected;
  15497. }
  15498. }
  15499. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15500. {
  15501. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15502. {
  15503. check_ascii = value[0];
  15504. if( (check_ascii < 48) || (check_ascii > 57) )
  15505. {
  15506. isSuccess = ConfigurationStatus_Rejected;
  15507. }
  15508. else
  15509. {
  15510. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15511. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15512. isSuccess = ConfigurationStatus_Accepted;
  15513. }
  15514. }
  15515. else
  15516. {
  15517. isSuccess = ConfigurationStatus_Rejected;
  15518. }
  15519. }
  15520. if(strcmp(key, "HeartbeatInterval") == 0)
  15521. {
  15522. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15523. {
  15524. check_ascii = value[0];
  15525. if( (check_ascii < 48) || (check_ascii > 57) )
  15526. {
  15527. isSuccess = ConfigurationStatus_Rejected;
  15528. }
  15529. else
  15530. {
  15531. if((atoi(value) == 0) || (atoi(value) >= 10))
  15532. {
  15533. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15534. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15535. HeartBeatWaitTime = atoi(value);
  15536. isSuccess = ConfigurationStatus_Accepted;
  15537. }
  15538. else
  15539. {
  15540. isSuccess = ConfigurationStatus_Rejected;
  15541. }
  15542. }
  15543. }
  15544. else
  15545. {
  15546. isSuccess = ConfigurationStatus_Rejected;
  15547. }
  15548. }
  15549. if(strcmp(key, "LightIntensity") == 0)
  15550. {
  15551. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15552. {
  15553. check_ascii = value[0];
  15554. if( (check_ascii < 48) || (check_ascii > 57) )
  15555. {
  15556. isSuccess = ConfigurationStatus_Rejected;
  15557. }
  15558. else
  15559. {
  15560. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15561. isSuccess = ConfigurationStatus_Accepted;
  15562. }
  15563. }
  15564. else
  15565. {
  15566. isSuccess = ConfigurationStatus_Rejected;
  15567. }
  15568. }
  15569. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15570. {
  15571. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15572. {
  15573. strcpy(str, (const char*)value);
  15574. for(int i = 0; str[i]; i++)
  15575. {
  15576. str[i] = tolower(str[i]);
  15577. }
  15578. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15579. isSuccess = ConfigurationStatus_Accepted;
  15580. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15581. }
  15582. else
  15583. {
  15584. isSuccess = ConfigurationStatus_Rejected;
  15585. }
  15586. }
  15587. if(strcmp(key, "LocalPreAuthorize") == 0)
  15588. {
  15589. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15590. {
  15591. strcpy(str, (const char*)value);
  15592. for(int i = 0; str[i]; i++)
  15593. {
  15594. str[i] = tolower(str[i]);
  15595. }
  15596. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15597. isSuccess = ConfigurationStatus_Accepted;
  15598. }
  15599. else
  15600. {
  15601. isSuccess = ConfigurationStatus_Rejected;
  15602. }
  15603. }
  15604. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15605. {
  15606. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15607. {
  15608. check_ascii = value[0];
  15609. if( (check_ascii < 48) || (check_ascii > 57) )
  15610. {
  15611. isSuccess = ConfigurationStatus_Rejected;
  15612. }
  15613. else
  15614. {
  15615. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15616. isSuccess = ConfigurationStatus_Accepted;
  15617. }
  15618. }
  15619. else
  15620. {
  15621. isSuccess = ConfigurationStatus_Rejected;
  15622. }
  15623. }
  15624. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15625. {
  15626. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15627. {
  15628. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15629. isSuccess = ConfigurationStatus_Accepted;
  15630. }
  15631. else
  15632. {
  15633. isSuccess = ConfigurationStatus_Rejected;
  15634. }
  15635. }
  15636. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15637. {
  15638. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15639. {
  15640. check_ascii = value[0];
  15641. if( (check_ascii < 48) || (check_ascii > 57) )
  15642. {
  15643. isSuccess = ConfigurationStatus_Rejected;
  15644. }
  15645. else
  15646. {
  15647. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15648. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15649. isSuccess = ConfigurationStatus_Accepted;
  15650. }
  15651. }
  15652. else
  15653. {
  15654. isSuccess = ConfigurationStatus_Rejected;
  15655. }
  15656. }
  15657. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15658. {
  15659. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15660. {
  15661. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15662. isSuccess = ConfigurationStatus_Accepted;
  15663. }
  15664. else
  15665. {
  15666. isSuccess = ConfigurationStatus_Rejected;
  15667. }
  15668. }
  15669. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15670. {
  15671. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15672. {
  15673. check_ascii = value[0];
  15674. if( (check_ascii < 48) || (check_ascii > 57) )
  15675. {
  15676. isSuccess = ConfigurationStatus_Rejected;
  15677. }
  15678. else
  15679. {
  15680. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15681. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15682. isSuccess = ConfigurationStatus_Accepted;
  15683. }
  15684. }
  15685. else
  15686. {
  15687. isSuccess = ConfigurationStatus_Rejected;
  15688. }
  15689. }
  15690. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15691. {
  15692. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15693. {
  15694. check_ascii = value[0];
  15695. if( (check_ascii < 48) || (check_ascii > 57) )
  15696. {
  15697. isSuccess = ConfigurationStatus_Rejected;
  15698. }
  15699. else
  15700. {
  15701. if((atoi(value) == 0) || (atoi(value) >= 5))
  15702. {
  15703. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15704. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15705. isSuccess = ConfigurationStatus_Accepted;
  15706. }
  15707. else
  15708. {
  15709. isSuccess = ConfigurationStatus_Rejected;
  15710. }
  15711. }
  15712. }
  15713. else
  15714. {
  15715. isSuccess = ConfigurationStatus_Rejected;
  15716. }
  15717. }
  15718. if(strcmp(key, "MinimumStatusDuration") == 0)
  15719. {
  15720. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15721. {
  15722. check_ascii = value[0];
  15723. if( (check_ascii < 48) || (check_ascii > 57) )
  15724. {
  15725. isSuccess = ConfigurationStatus_Rejected;
  15726. }
  15727. else
  15728. {
  15729. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15730. {
  15731. isSuccess = ConfigurationStatus_Rejected;
  15732. }
  15733. else
  15734. {
  15735. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  15736. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  15737. server_cycle_Status = atoi(value); //StatusNotification Cycle
  15738. isSuccess = ConfigurationStatus_Accepted;
  15739. }
  15740. }
  15741. }
  15742. else
  15743. {
  15744. isSuccess = ConfigurationStatus_Rejected;
  15745. }
  15746. }
  15747. if(strcmp(key, "NumberOfConnectors") == 0)
  15748. {
  15749. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15750. {
  15751. check_ascii = value[0];
  15752. if( (check_ascii < 48) || (check_ascii > 57) )
  15753. {
  15754. isSuccess = ConfigurationStatus_Rejected;
  15755. }
  15756. else
  15757. {
  15758. //Charger.ResetRetries = Integer.parseInt(value);
  15759. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  15760. isSuccess = ConfigurationStatus_Accepted;
  15761. }
  15762. }
  15763. else
  15764. {
  15765. isSuccess = ConfigurationStatus_Rejected;
  15766. }
  15767. }
  15768. if(strcmp(key, "ResetRetries") == 0)
  15769. {
  15770. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15771. {
  15772. check_ascii = value[0];
  15773. if( (check_ascii < 48) || (check_ascii > 57) )
  15774. {
  15775. isSuccess = ConfigurationStatus_Rejected;
  15776. }
  15777. else
  15778. {
  15779. //Charger.ResetRetries = Integer.parseInt(value);
  15780. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  15781. isSuccess = ConfigurationStatus_Accepted;
  15782. }
  15783. }
  15784. else
  15785. {
  15786. isSuccess = ConfigurationStatus_Rejected;
  15787. }
  15788. }
  15789. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  15790. {
  15791. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15792. {
  15793. strcpy(str, (const char*)value);
  15794. for(int i = 0; str[i]; i++)
  15795. {
  15796. str[i] = tolower(str[i]);
  15797. }
  15798. if(strcmp(str, "notapplicable")== 0)
  15799. {
  15800. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  15801. isSuccess = ConfigurationStatus_Accepted;
  15802. }
  15803. else if(strcmp(str, "unknown")== 0)
  15804. {
  15805. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  15806. isSuccess = ConfigurationStatus_Accepted;
  15807. }
  15808. else if(strcmp(str, "rst")== 0)
  15809. {
  15810. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  15811. isSuccess = ConfigurationStatus_Accepted;
  15812. }
  15813. else if(strcmp(str, "rts")== 0)
  15814. {
  15815. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  15816. isSuccess = ConfigurationStatus_Accepted;
  15817. }
  15818. else if(strcmp(str, "srt")== 0)
  15819. {
  15820. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  15821. isSuccess = ConfigurationStatus_Accepted;
  15822. }
  15823. else if(strcmp(str, "str")== 0)
  15824. {
  15825. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  15826. isSuccess = ConfigurationStatus_Accepted;
  15827. }
  15828. else if(strcmp(str, "trs")== 0)
  15829. {
  15830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  15831. isSuccess = ConfigurationStatus_Accepted;
  15832. }
  15833. else if(strcmp(str, "tsr")== 0)
  15834. {
  15835. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  15836. isSuccess = ConfigurationStatus_Accepted;
  15837. }
  15838. else
  15839. {
  15840. isSuccess = ConfigurationStatus_Rejected;
  15841. }
  15842. }
  15843. else
  15844. {
  15845. isSuccess = ConfigurationStatus_Rejected;
  15846. }
  15847. }
  15848. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  15849. {
  15850. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15851. {
  15852. check_ascii = value[0];
  15853. if( (check_ascii < 48) || (check_ascii > 57) )
  15854. {
  15855. isSuccess = ConfigurationStatus_Rejected;
  15856. }
  15857. else
  15858. {
  15859. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  15860. isSuccess = ConfigurationStatus_Accepted;
  15861. }
  15862. }
  15863. else
  15864. {
  15865. isSuccess = ConfigurationStatus_Rejected;
  15866. }
  15867. }
  15868. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  15869. {
  15870. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15871. {
  15872. strcpy(str, (const char*)value);
  15873. for(int i = 0; str[i]; i++)
  15874. {
  15875. str[i] = tolower(str[i]);
  15876. }
  15877. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15878. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15879. isSuccess = ConfigurationStatus_Accepted;
  15880. }
  15881. else
  15882. {
  15883. isSuccess = ConfigurationStatus_Rejected;
  15884. }
  15885. }
  15886. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  15887. {
  15888. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15889. {
  15890. strcpy(str, (const char*)value);
  15891. for(int i = 0; str[i]; i++)
  15892. {
  15893. str[i] = tolower(str[i]);
  15894. }
  15895. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  15896. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15897. isSuccess = ConfigurationStatus_Accepted;
  15898. }
  15899. else
  15900. {
  15901. isSuccess = ConfigurationStatus_Rejected;
  15902. }
  15903. }
  15904. if(strcmp(key, "StopTxnAlignedData") == 0)
  15905. {
  15906. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15907. {
  15908. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  15909. isSuccess = ConfigurationStatus_Accepted;
  15910. }
  15911. else
  15912. {
  15913. isSuccess = ConfigurationStatus_Rejected;
  15914. }
  15915. }
  15916. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  15917. {
  15918. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15919. {
  15920. check_ascii = value[0];
  15921. if( (check_ascii < 48) || (check_ascii > 57) )
  15922. {
  15923. isSuccess = ConfigurationStatus_Rejected;
  15924. }
  15925. else
  15926. {
  15927. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  15928. isSuccess = ConfigurationStatus_Accepted;
  15929. }
  15930. }
  15931. else
  15932. {
  15933. isSuccess = ConfigurationStatus_Rejected;
  15934. }
  15935. }
  15936. if(strcmp(key, "StopTxnSampledData") == 0)
  15937. {
  15938. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15939. {
  15940. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  15941. isSuccess = ConfigurationStatus_Accepted;
  15942. }
  15943. else
  15944. {
  15945. isSuccess = ConfigurationStatus_Rejected;
  15946. }
  15947. }
  15948. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  15949. {
  15950. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15951. {
  15952. check_ascii = value[0];
  15953. if( (check_ascii < 48) || (check_ascii > 57) )
  15954. {
  15955. isSuccess = ConfigurationStatus_Rejected;
  15956. }
  15957. else
  15958. {
  15959. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  15960. isSuccess = ConfigurationStatus_Accepted;
  15961. }
  15962. }
  15963. else
  15964. {
  15965. isSuccess = ConfigurationStatus_Rejected;
  15966. }
  15967. }
  15968. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  15969. {
  15970. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15971. {
  15972. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  15973. isSuccess = ConfigurationStatus_Accepted;
  15974. }
  15975. else
  15976. {
  15977. isSuccess = ConfigurationStatus_Rejected;
  15978. }
  15979. }
  15980. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  15981. {
  15982. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15983. {
  15984. check_ascii = value[0];
  15985. if( (check_ascii < 48) || (check_ascii > 57) )
  15986. {
  15987. isSuccess = ConfigurationStatus_Rejected;
  15988. }
  15989. else
  15990. {
  15991. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  15992. isSuccess = ConfigurationStatus_Accepted;
  15993. }
  15994. }
  15995. else
  15996. {
  15997. isSuccess = ConfigurationStatus_Rejected;
  15998. }
  15999. }
  16000. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16001. {
  16002. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16003. {
  16004. check_ascii = value[0];
  16005. if( (check_ascii < 48) || (check_ascii > 57) )
  16006. {
  16007. isSuccess = ConfigurationStatus_Rejected;
  16008. }
  16009. else
  16010. {
  16011. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16013. TransactionMessageAttemptsValue = atoi(value);
  16014. isSuccess = ConfigurationStatus_Accepted;
  16015. }
  16016. }
  16017. else
  16018. {
  16019. isSuccess = ConfigurationStatus_Rejected;
  16020. }
  16021. }
  16022. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16023. {
  16024. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16025. {
  16026. check_ascii = value[0];
  16027. if( (check_ascii < 48) || (check_ascii > 57) )
  16028. {
  16029. isSuccess = ConfigurationStatus_Rejected;
  16030. }
  16031. else
  16032. {
  16033. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16034. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16035. TransactionMessageRetryIntervalValue = atoi(value);
  16036. isSuccess = ConfigurationStatus_Accepted;
  16037. }
  16038. }
  16039. else
  16040. {
  16041. isSuccess = ConfigurationStatus_Rejected;
  16042. }
  16043. }
  16044. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16045. {
  16046. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16047. {
  16048. strcpy(str, (const char*)value);
  16049. for(int i = 0; str[i]; i++)
  16050. {
  16051. str[i] = tolower(str[i]);
  16052. }
  16053. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16054. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16055. isSuccess = ConfigurationStatus_Accepted;
  16056. }
  16057. else
  16058. {
  16059. isSuccess = ConfigurationStatus_Rejected;
  16060. }
  16061. }
  16062. if(strcmp(key, "WebSocketPingInterval") == 0)
  16063. {
  16064. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16065. {
  16066. check_ascii = value[0];
  16067. if( (check_ascii < 48) || (check_ascii > 57) )
  16068. {
  16069. isSuccess = ConfigurationStatus_Rejected;
  16070. }
  16071. else
  16072. {
  16073. if((atoi(value) == 0) || (atoi(value) >= 10))
  16074. {
  16075. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16076. isSuccess = ConfigurationStatus_Accepted;
  16077. }
  16078. else
  16079. isSuccess = ConfigurationStatus_Rejected;
  16080. }
  16081. }
  16082. else
  16083. {
  16084. isSuccess = ConfigurationStatus_Rejected;
  16085. }
  16086. }
  16087. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16088. {
  16089. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16090. {
  16091. strcpy(str, (const char*)value);
  16092. for(int i = 0; str[i]; i++)
  16093. {
  16094. str[i] = tolower(str[i]);
  16095. }
  16096. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16097. isSuccess = ConfigurationStatus_Accepted;
  16098. }
  16099. else
  16100. {
  16101. isSuccess = ConfigurationStatus_Rejected;
  16102. }
  16103. }
  16104. if(strcmp(key, "AuthorizationKey") == 0)
  16105. {
  16106. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16107. {
  16108. strcpy(str, (const char*)value);
  16109. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16110. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16111. isSuccess = ConfigurationStatus_Accepted;
  16112. }
  16113. else
  16114. {
  16115. isSuccess = ConfigurationStatus_Rejected;
  16116. }
  16117. }
  16118. if(strcmp(key, "SecurityProfile") == 0)
  16119. {
  16120. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16121. {
  16122. check_ascii = value[0];
  16123. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16124. {
  16125. isSuccess = ConfigurationStatus_Rejected;
  16126. }
  16127. else if(check_ascii == 0x33)
  16128. {
  16129. isSuccess = NotSupported;
  16130. }
  16131. else
  16132. {
  16133. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16134. {
  16135. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16136. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  16137. isSuccess = ConfigurationStatus_Accepted;
  16138. }
  16139. else
  16140. isSuccess = ConfigurationStatus_Rejected;
  16141. }
  16142. }
  16143. else
  16144. {
  16145. isSuccess = ConfigurationStatus_Rejected;
  16146. }
  16147. }
  16148. if(strcmp(key, "DefaultPrice") == 0)
  16149. {
  16150. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16151. {
  16152. strcpy(str, (const char*)value);
  16153. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16154. isSuccess = ConfigurationStatus_Accepted;
  16155. }
  16156. else
  16157. {
  16158. isSuccess = ConfigurationStatus_Rejected;
  16159. }
  16160. }
  16161. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16162. {
  16163. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16164. {
  16165. strcpy(str, (const char*)value);
  16166. for(int i = 0; str[i]; i++)
  16167. {
  16168. str[i] = tolower(str[i]);
  16169. }
  16170. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16171. isSuccess = ConfigurationStatus_Accepted;
  16172. }
  16173. else
  16174. {
  16175. isSuccess = ConfigurationStatus_Rejected;
  16176. }
  16177. }
  16178. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16179. {
  16180. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16181. {
  16182. strcpy(str, (const char*)value);
  16183. for(int i = 0; str[i]; i++)
  16184. {
  16185. str[i] = tolower(str[i]);
  16186. }
  16187. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16188. isSuccess = ConfigurationStatus_Accepted;
  16189. }
  16190. else
  16191. {
  16192. isSuccess = ConfigurationStatus_Rejected;
  16193. }
  16194. }
  16195. if(strcmp(key, "TimeOffset") == 0)
  16196. {
  16197. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16198. {
  16199. strcpy(str, (const char*)value);
  16200. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  16201. isSuccess = ConfigurationStatus_Accepted;
  16202. }
  16203. else
  16204. {
  16205. isSuccess = ConfigurationStatus_Rejected;
  16206. }
  16207. }
  16208. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  16209. {
  16210. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  16211. {
  16212. strcpy(str, (const char*)value);
  16213. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  16214. isSuccess = ConfigurationStatus_Accepted;
  16215. }
  16216. else
  16217. {
  16218. isSuccess = ConfigurationStatus_Rejected;
  16219. }
  16220. }
  16221. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  16222. {
  16223. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  16224. {
  16225. strcpy(str, (const char*)value);
  16226. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  16227. isSuccess = ConfigurationStatus_Accepted;
  16228. }
  16229. else
  16230. {
  16231. isSuccess = ConfigurationStatus_Rejected;
  16232. }
  16233. }
  16234. if(strcmp(key, "SystemUptimeSec") == 0)
  16235. {
  16236. isSuccess = NotSupported;
  16237. }
  16238. if(strcmp(key, "FreeVend") == 0)
  16239. {
  16240. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16241. {
  16242. strcpy(str, (const char*)value);
  16243. for(int i = 0; str[i]; i++)
  16244. {
  16245. str[i] = tolower(str[i]);
  16246. }
  16247. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16248. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16249. isSuccess = ConfigurationStatus_Accepted;
  16250. }
  16251. else
  16252. {
  16253. isSuccess = ConfigurationStatus_Rejected;
  16254. }
  16255. }
  16256. if(strcmp(key, "OcppServer") == 0)
  16257. {
  16258. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16259. {
  16260. strcpy(str, (const char*)value);
  16261. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16262. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16263. isSuccess = ConfigurationStatus_Accepted;
  16264. }
  16265. else
  16266. {
  16267. isSuccess = ConfigurationStatus_Rejected;
  16268. }
  16269. }
  16270. if(strcmp(key, "MaintainServer") == 0)
  16271. {
  16272. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16273. {
  16274. strcpy(str, (const char*)value);
  16275. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16276. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16277. isSuccess = ConfigurationStatus_Accepted;
  16278. }
  16279. else
  16280. {
  16281. isSuccess = ConfigurationStatus_Rejected;
  16282. }
  16283. }
  16284. #if 0
  16285. //For OCPP Test Case
  16286. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16287. {
  16288. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16289. {
  16290. strcpy(str, (const char*)value);
  16291. for(int i = 0; str[i]; i++)
  16292. {
  16293. str[i] = tolower(str[i]);
  16294. }
  16295. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16296. isSuccess = ConfigurationStatus_Accepted;
  16297. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16298. }
  16299. else
  16300. {
  16301. isSuccess = ConfigurationStatus_Rejected;
  16302. }
  16303. }
  16304. #endif
  16305. #if 1
  16306. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16307. {
  16308. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16309. {
  16310. strcpy(str, (const char*)value);
  16311. for(int i = 0; str[i]; i++)
  16312. {
  16313. str[i] = tolower(str[i]);
  16314. }
  16315. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16316. isSuccess = ConfigurationStatus_Accepted;
  16317. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16318. }
  16319. else
  16320. {
  16321. isSuccess = ConfigurationStatus_Rejected;
  16322. }
  16323. }
  16324. #endif
  16325. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16326. {
  16327. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16328. {
  16329. check_ascii = value[0];
  16330. if( (check_ascii < 48) || (check_ascii > 57) )
  16331. {
  16332. isSuccess = ConfigurationStatus_Rejected;
  16333. }
  16334. else
  16335. {
  16336. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16337. isSuccess = ConfigurationStatus_Accepted;
  16338. }
  16339. }
  16340. else
  16341. {
  16342. isSuccess = ConfigurationStatus_Rejected;
  16343. }
  16344. }
  16345. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16346. {
  16347. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16348. {
  16349. check_ascii = value[0];
  16350. if( (check_ascii < 48) || (check_ascii > 57) )
  16351. {
  16352. isSuccess = ConfigurationStatus_Rejected;
  16353. }
  16354. else
  16355. {
  16356. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16357. isSuccess = ConfigurationStatus_Accepted;
  16358. }
  16359. }
  16360. else
  16361. {
  16362. isSuccess = ConfigurationStatus_Rejected;
  16363. }
  16364. }
  16365. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16366. {
  16367. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16368. {
  16369. strcpy(str, (const char*)value);
  16370. for(int i = 0; str[i]; i++)
  16371. {
  16372. str[i] = tolower(str[i]);
  16373. }
  16374. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16375. isSuccess = ConfigurationStatus_Accepted;
  16376. }
  16377. else
  16378. {
  16379. isSuccess = ConfigurationStatus_Rejected;
  16380. }
  16381. }
  16382. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16383. {
  16384. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16385. {
  16386. check_ascii = value[0];
  16387. if( (check_ascii < 48) || (check_ascii > 57) )
  16388. {
  16389. isSuccess = ConfigurationStatus_Rejected;
  16390. }
  16391. else
  16392. {
  16393. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16394. isSuccess = ConfigurationStatus_Accepted;
  16395. }
  16396. }
  16397. else
  16398. {
  16399. isSuccess = ConfigurationStatus_Rejected;
  16400. }
  16401. }
  16402. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16403. {
  16404. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16405. {
  16406. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16407. isSuccess = ConfigurationStatus_Accepted;
  16408. }
  16409. else
  16410. {
  16411. isSuccess = ConfigurationStatus_Rejected;
  16412. }
  16413. }
  16414. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16415. {
  16416. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16417. {
  16418. check_ascii = value[0];
  16419. if( (check_ascii < 48) || (check_ascii > 57) )
  16420. {
  16421. isSuccess = ConfigurationStatus_Rejected;
  16422. }
  16423. else
  16424. {
  16425. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16426. isSuccess = ConfigurationStatus_Accepted;
  16427. }
  16428. }
  16429. else
  16430. {
  16431. isSuccess = ConfigurationStatus_Rejected;
  16432. }
  16433. }
  16434. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16435. {
  16436. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16437. {
  16438. strcpy(str, (const char*)value);
  16439. for(int i = 0; str[i]; i++)
  16440. {
  16441. str[i] = tolower(str[i]);
  16442. }
  16443. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16444. isSuccess = ConfigurationStatus_Accepted;
  16445. }
  16446. else
  16447. {
  16448. isSuccess = ConfigurationStatus_Rejected;
  16449. }
  16450. }
  16451. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16452. {
  16453. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16454. {
  16455. check_ascii = value[0];
  16456. if( (check_ascii < 48) || (check_ascii > 57) )
  16457. {
  16458. isSuccess = ConfigurationStatus_Rejected;
  16459. }
  16460. else
  16461. {
  16462. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16463. isSuccess = ConfigurationStatus_Accepted;
  16464. }
  16465. }
  16466. else
  16467. {
  16468. isSuccess = ConfigurationStatus_Rejected;
  16469. }
  16470. }
  16471. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16472. return isSuccess;
  16473. }
  16474. int TransactionMessageAttemptsGet(void)
  16475. {
  16476. return TransactionMessageAttemptsValue;
  16477. }
  16478. int FirstHeartBeatResponse(void)
  16479. {
  16480. return FirstHeartBeat;
  16481. }
  16482. int TransactionMessageRetryIntervalGet(void)
  16483. {
  16484. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16485. }
  16486. int ReadHttpStatus(int sock)
  16487. {
  16488. //char c;
  16489. char buff[1024]="",*ptr=buff+1;
  16490. int bytes_received, status;
  16491. DEBUG_INFO("Begin Response ..\n");
  16492. while((bytes_received = recv(sock, ptr, 1, 0))){
  16493. if(bytes_received==-1){
  16494. perror("ReadHttpStatus");
  16495. exit(1);
  16496. }
  16497. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16498. ptr++;
  16499. }
  16500. *ptr=0;
  16501. ptr=buff+1;
  16502. sscanf(ptr,"%*s %d ", &status);
  16503. DEBUG_INFO("%s\n",ptr);
  16504. DEBUG_INFO("status=%d\n",status);
  16505. DEBUG_INFO("End Response ..\n");
  16506. return (bytes_received>0)?status:0;
  16507. }
  16508. //the only filed that it parsed is 'Content-Length'
  16509. int ParseHeader(int sock)
  16510. {
  16511. //char c;
  16512. char buff[1024]="",*ptr=buff+4;
  16513. int bytes_received;
  16514. DEBUG_INFO("Begin HEADER ..\n");
  16515. while((bytes_received = recv(sock, ptr, 1, 0))){
  16516. if(bytes_received==-1){
  16517. perror("Parse Header");
  16518. exit(1);
  16519. }
  16520. if(
  16521. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16522. (ptr[-1]=='\r') && (*ptr=='\n' )
  16523. ) break;
  16524. ptr++;
  16525. }
  16526. *ptr=0;
  16527. ptr=buff+4;
  16528. //printf("%s",ptr);
  16529. if(bytes_received){
  16530. ptr=strstr(ptr,"Content-Length:");
  16531. if(ptr){
  16532. sscanf(ptr,"%*s %d",&bytes_received);
  16533. }else
  16534. bytes_received=-1; //unknown size
  16535. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16536. }
  16537. DEBUG_INFO("End HEADER ..\n");
  16538. return bytes_received ;
  16539. }
  16540. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16541. {
  16542. int result = TRUE;
  16543. char rmFileCmd[100]={0};
  16544. char FilePath[100]={0};
  16545. char ftpbuf[200];
  16546. int systemresult;
  16547. sprintf(FilePath,"/mnt/%s",filename);
  16548. system("ping 8.8.8.8 &");
  16549. if((access(FilePath,F_OK))!=-1)
  16550. {
  16551. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16552. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16553. system(rmFileCmd);
  16554. }
  16555. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16556. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16557. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16558. systemresult = system(ftpbuf);
  16559. if(systemresult != 0)
  16560. {
  16561. DEBUG_INFO("http DownLoad error!\n");
  16562. result = FALSE;
  16563. }
  16564. system("pkill ping");
  16565. return result;
  16566. }
  16567. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16568. {
  16569. int result = TRUE;
  16570. char rmFileCmd[100]={0};
  16571. char FilePath[100]={0};
  16572. char ftpbuf[200];
  16573. int systemresult;
  16574. sprintf(FilePath,"/mnt/%s",filename);
  16575. system("ping 8.8.8.8 &");
  16576. if((access(FilePath,F_OK))!=-1)
  16577. {
  16578. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16579. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16580. system(rmFileCmd);
  16581. }
  16582. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16583. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16584. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16585. systemresult = system(ftpbuf);
  16586. if(systemresult != 0)
  16587. {
  16588. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16589. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16590. systemresult = system(ftpbuf);
  16591. if(systemresult != 0)
  16592. {
  16593. DEBUG_WARN("wget error!\n");
  16594. result = FALSE;
  16595. }
  16596. }
  16597. system("pkill ping");
  16598. return result;
  16599. }
  16600. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16601. {
  16602. char rmFileCmd[100]={0};
  16603. char FilePath[100]={0};
  16604. char buf[512];
  16605. int systemresult = 0;
  16606. //DEBUG_INFO("filename=%s\n",filename);
  16607. //DEBUG_INFO("url=%s\n",url);
  16608. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16609. if((access(FilePath,F_OK))!=-1)
  16610. {
  16611. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16612. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16613. system(rmFileCmd);
  16614. }
  16615. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16616. if(fp == NULL)
  16617. {
  16618. DEBUG_INFO("log is NULL\n");
  16619. return FALSE;
  16620. }
  16621. else
  16622. {
  16623. fprintf(fp, "%s\n", url);
  16624. fprintf(fp, "%s\n", filename);
  16625. fclose(fp);
  16626. }
  16627. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16628. if(phpFP == NULL)
  16629. {
  16630. DEBUG_INFO("PHP upload fail.\n");
  16631. return FALSE;
  16632. }
  16633. else
  16634. {
  16635. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16636. {
  16637. if(strstr(buf, "result") != NULL)
  16638. {
  16639. sscanf(buf, "result: %d", &systemresult);
  16640. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16641. }
  16642. }
  16643. pclose(phpFP);
  16644. }
  16645. if(systemresult != 1)
  16646. {
  16647. DEBUG_INFO("HTTP upload error!\n");
  16648. return FALSE;
  16649. }
  16650. return TRUE;
  16651. }
  16652. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16653. {
  16654. int result = FALSE;
  16655. char ftpbuf[200];
  16656. int systemresult;
  16657. /*
  16658. // Domaind name transfer to IP address
  16659. struct hostent* server;
  16660. char *IPbuffer;
  16661. server = gethostbyname(location);
  16662. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16663. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16664. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16665. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16666. systemresult = system(ftpbuf);
  16667. if(systemresult != 0)
  16668. {
  16669. DEBUG_INFO("ftpput error!\n");
  16670. }
  16671. else
  16672. {
  16673. result = TRUE;
  16674. DEBUG_INFO("ftpput OK!\n");
  16675. }
  16676. return result;
  16677. }
  16678. int GetOcppServerURL()
  16679. {
  16680. int result = FALSE;
  16681. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16682. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16683. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16684. struct yuarel url;
  16685. char urlStr[512];
  16686. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  16687. {
  16688. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  16689. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16690. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16691. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  16692. if(yuarel_parse(&url, urlStr) != -1)
  16693. {
  16694. sprintf(OcppProtocol, "%s", url.scheme);
  16695. sprintf(OcppHost, "%s", url.host);
  16696. if(url.path == NULL)
  16697. OcppTempPath[0] = '\0';
  16698. else
  16699. {
  16700. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  16701. {
  16702. sprintf(OcppTempPath, "%s/", url.path);
  16703. }
  16704. else
  16705. {
  16706. sprintf(OcppTempPath, "%s", url.path);
  16707. }
  16708. }
  16709. if(url.port == 0)
  16710. {
  16711. if(strcmp(OcppProtocol, "wss") == 0)
  16712. OcppPort = 443;
  16713. else
  16714. OcppPort = 80;
  16715. }
  16716. else
  16717. OcppPort = url.port;
  16718. result = TRUE;
  16719. }
  16720. }
  16721. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  16722. {
  16723. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  16724. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16725. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16726. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  16727. if(yuarel_parse(&url, urlStr) != -1)
  16728. {
  16729. sprintf(OcppProtocol, "%s", url.scheme);
  16730. sprintf(OcppHost, "%s", url.host);
  16731. if(url.path == NULL)
  16732. OcppTempPath[0] = '\0';
  16733. else
  16734. sprintf(OcppTempPath, "%s", url.path);
  16735. if(url.port == 0)
  16736. {
  16737. if(strcmp(OcppProtocol, "wss") == 0)
  16738. OcppPort = 443;
  16739. else
  16740. OcppPort = 80;
  16741. }
  16742. else
  16743. OcppPort = url.port;
  16744. result = TRUE;
  16745. }
  16746. }
  16747. else
  16748. {
  16749. strcpy(OcppHost,"");
  16750. }
  16751. return result;
  16752. }
  16753. int GetOcppPath()
  16754. {
  16755. int result = FALSE;
  16756. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  16757. {
  16758. if(OcppTempPath == NULL)
  16759. {
  16760. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16761. }
  16762. else
  16763. {
  16764. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16765. }
  16766. result = TRUE;
  16767. goto End;
  16768. }
  16769. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  16770. {
  16771. if(OcppTempPath == NULL)
  16772. {
  16773. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  16774. }
  16775. else
  16776. {
  16777. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  16778. }
  16779. result = TRUE;
  16780. goto End;
  16781. }
  16782. else
  16783. {
  16784. strcpy(OcppPath,"");
  16785. }
  16786. End:
  16787. return result;
  16788. }
  16789. int GetOcppPort()
  16790. {
  16791. return OcppPort;
  16792. }
  16793. int GetOcppConnStatus(void)
  16794. {
  16795. return ShmOCPP16Data->OcppConnStatus;
  16796. }
  16797. void SetOcppConnStatus(uint8_t status)
  16798. {
  16799. ShmOCPP16Data->OcppConnStatus = status;
  16800. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  16801. }
  16802. int GetHeartBeatWithNOResponse(void)
  16803. {
  16804. return HeartBeatWithNOResponse;
  16805. }
  16806. void SetHeartBeatWithNOResponse(void)
  16807. {
  16808. HeartBeatWithNOResponse = 0;
  16809. }
  16810. void GetStartTransactionIdTag(int gun_index)
  16811. {
  16812. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  16813. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  16814. }
  16815. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  16816. {
  16817. char ch;
  16818. FILE *fptr1;
  16819. int temptransactionId;
  16820. char str[100]={0};
  16821. temptransactionId = 0;
  16822. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  16823. {
  16824. DEBUG_INFO("IdTag is empty.\n");
  16825. return temptransactionId;
  16826. }
  16827. /*------ Read the file ----------------*/
  16828. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  16829. if (!fptr1)
  16830. {
  16831. DEBUG_INFO("QueueTransactionId file open error.\n");
  16832. //printf(" File not found or unable to open the input file!!\n");
  16833. return temptransactionId;
  16834. }
  16835. ch=fgetc(fptr1);
  16836. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  16837. rewind(fptr1);
  16838. if(ch!=EOF)
  16839. {
  16840. // printf("%c",ch);
  16841. while (fgets(str, 100, fptr1) != NULL)
  16842. {
  16843. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16844. if(str[0]=='\0')
  16845. {
  16846. break;
  16847. }
  16848. char *revbuf[8] = {0}; // Variable store string split
  16849. int num = 0;// Quantity after string split
  16850. DEBUG_INFO("Transaction queue data= %s\n", str);
  16851. splitstring(str,",",revbuf,&num); // String split
  16852. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  16853. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  16854. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  16855. DEBUG_INFO("------------------------------\n");
  16856. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  16857. {
  16858. if(isStopTransaction)
  16859. {
  16860. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  16861. {
  16862. temptransactionId = atoi(revbuf[2]);
  16863. //break;
  16864. }
  16865. }
  16866. else
  16867. {
  16868. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  16869. {
  16870. temptransactionId = atoi(revbuf[2]);
  16871. //break;
  16872. }
  16873. }
  16874. }
  16875. }
  16876. }
  16877. else
  16878. DEBUG_INFO("EOF\n");
  16879. fclose(fptr1);
  16880. /*------- End of reading ---------------*/
  16881. return temptransactionId;
  16882. }
  16883. void SetTransactionIdZero(int transactionId)
  16884. {
  16885. char ch;
  16886. FILE *fptr1, *fptr2;
  16887. int temptransactionId = 0;
  16888. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  16889. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  16890. if (!fptr1)
  16891. {
  16892. //printf(" File not found or unable to open the input file!!\n");
  16893. return ;
  16894. }
  16895. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  16896. if (!fptr2)
  16897. {
  16898. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  16899. fclose(fptr1);
  16900. return ;
  16901. }
  16902. ch=fgetc(fptr1);
  16903. rewind(fptr1);
  16904. if(ch!=EOF)
  16905. {
  16906. // copy all contents to the temporary file except the specific line
  16907. while (fgets(str, 100, fptr1) != NULL)
  16908. {
  16909. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16910. if(str[0]=='\0')
  16911. {
  16912. break;
  16913. }
  16914. char *revbuf[8] = {0};
  16915. int num = 0;
  16916. strcpy(strtemp, str);
  16917. splitstring(str,",",revbuf,&num);
  16918. if(revbuf[2][0] != '\0')
  16919. {
  16920. temptransactionId = atoi(revbuf[2]);
  16921. if(transactionId != temptransactionId)
  16922. {
  16923. fprintf(fptr2, "%s\n", strtemp);
  16924. }
  16925. }
  16926. }
  16927. }
  16928. fclose(fptr1);
  16929. fclose(fptr2);
  16930. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  16931. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  16932. /*------ Read the file ----------------*/
  16933. }
  16934. int InternetDisconnect(void)
  16935. {
  16936. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  16937. }
  16938. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  16939. void storeTempStopTransaction(int gun_index)
  16940. {
  16941. char guid[37]={0};
  16942. int tempIndex = 0;
  16943. char TempStopTransaction[256];
  16944. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  16945. DEBUG_INFO("storeTempStopTransaction...\n");
  16946. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  16947. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  16948. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  16949. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16950. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16951. {
  16952. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16953. {
  16954. tempIndex = ((gun_index==2) ? 1: 0);
  16955. }
  16956. else
  16957. {
  16958. tempIndex = gun_index;
  16959. }
  16960. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16961. {
  16962. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16963. {
  16964. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  16965. }
  16966. }// END OF CHAdeMO_QUANTITY
  16967. }
  16968. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16969. {
  16970. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16971. {
  16972. tempIndex = ((gun_index==2) ? 1: 0);
  16973. }
  16974. else
  16975. {
  16976. tempIndex = gun_index;
  16977. }
  16978. for (int index = 0; index < CCS_QUANTITY; index++)
  16979. {
  16980. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16981. {
  16982. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  16983. }
  16984. }// END OF CCS_QUANTITY
  16985. }
  16986. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16987. {
  16988. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16989. {
  16990. tempIndex = ((gun_index==2) ? 1: 0);
  16991. }
  16992. else
  16993. {
  16994. tempIndex = gun_index;
  16995. }
  16996. for (int index = 0; index < GB_QUANTITY; index++)
  16997. {
  16998. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16999. {
  17000. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17001. }
  17002. }// END OF GB_QUANTITY
  17003. }
  17004. else if(gunType[gun_index] == GUN_TYPE_DO)
  17005. {
  17006. tempIndex = gun_index;
  17007. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17008. {
  17009. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17010. {
  17011. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17012. }
  17013. }
  17014. }
  17015. else
  17016. {
  17017. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17018. {
  17019. tempIndex = 2;
  17020. }
  17021. else
  17022. {
  17023. tempIndex = gun_index;
  17024. }
  17025. for (int index = 0; index < AC_QUANTITY; index++)
  17026. {
  17027. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17028. {
  17029. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17030. }
  17031. }// END OF AC_QUANTITY
  17032. }
  17033. //Stop Transaction Time
  17034. struct timeval tmnow;
  17035. struct tm *tm;
  17036. char buf[28];//, usec_buf[6];
  17037. gettimeofday(&tmnow, NULL);
  17038. time_t t;
  17039. t = time(NULL);
  17040. /*UTC time and date*/
  17041. tm = gmtime(&t);
  17042. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17043. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  17044. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  17045. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17046. random_uuid(guid);
  17047. /***********************************transactionData******************************************************/
  17048. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17049. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17050. //=================================
  17051. //1. Transaction_Begin
  17052. //=================================
  17053. //============================== Energy.Active.Import.Interval ===========================================
  17054. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17055. {
  17056. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  17057. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17058. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  17059. 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*/]);
  17060. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17061. 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))
  17062. {
  17063. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  17064. }
  17065. else
  17066. {
  17067. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  17068. }
  17069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  17070. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17071. }
  17072. //=================================
  17073. //2. Transaction_End
  17074. //=================================
  17075. //2.1====================================== Current.Import L1 ==============================================
  17076. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17077. {
  17078. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17079. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17080. {
  17081. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17082. {
  17083. tempIndex = ((gun_index==2) ? 1: 0);
  17084. }
  17085. else
  17086. {
  17087. tempIndex = gun_index;
  17088. }
  17089. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17090. {
  17091. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17092. {
  17093. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17094. }
  17095. }// End of for CHAdeMO_QUANTITY
  17096. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17097. }
  17098. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17099. {
  17100. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17101. {
  17102. tempIndex = ((gun_index==2) ? 1: 0);
  17103. }
  17104. else
  17105. {
  17106. tempIndex = gun_index;
  17107. }
  17108. for (int index = 0; index < CCS_QUANTITY; index++)
  17109. {
  17110. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17111. {
  17112. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17113. }
  17114. }// End of for CCS_QUANTITY
  17115. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17116. }
  17117. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17118. {
  17119. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17120. {
  17121. tempIndex = ((gun_index==2) ? 1: 0);
  17122. }
  17123. else
  17124. {
  17125. tempIndex = gun_index;
  17126. }
  17127. for (int index = 0; index < GB_QUANTITY; index++)
  17128. {
  17129. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17130. {
  17131. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17132. }
  17133. }// End of for GB_QUANTITY
  17134. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17135. }
  17136. else if(gunType[gun_index] == GUN_TYPE_DO)
  17137. {
  17138. tempIndex = gun_index;
  17139. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17140. {
  17141. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17142. {
  17143. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17144. }
  17145. }
  17146. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17147. }
  17148. else
  17149. {
  17150. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17151. {
  17152. tempIndex = 2;
  17153. }
  17154. else
  17155. {
  17156. tempIndex = gun_index;
  17157. }
  17158. for (int index = 0; index < AC_QUANTITY; index++)
  17159. {
  17160. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17161. {
  17162. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17163. }
  17164. }// End of for AC_QUANTITY
  17165. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17166. }
  17167. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17168. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17169. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17170. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17171. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17172. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17173. }
  17174. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17175. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17176. {
  17177. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17178. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17179. {
  17180. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17181. {
  17182. tempIndex = ((gun_index==2) ? 1: 0);
  17183. }
  17184. else
  17185. {
  17186. tempIndex = gun_index;
  17187. }
  17188. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17189. {
  17190. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17191. {
  17192. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17193. }
  17194. }// END OF CHAdeMO_QUANTITY
  17195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17196. }
  17197. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17198. {
  17199. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17200. {
  17201. tempIndex = ((gun_index==2) ? 1: 0);
  17202. }
  17203. else
  17204. {
  17205. tempIndex = gun_index;
  17206. }
  17207. for (int index = 0; index < CCS_QUANTITY; index++)
  17208. {
  17209. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17210. {
  17211. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17212. }
  17213. }// END OF CCS_QUANTITY
  17214. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17215. }
  17216. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17217. {
  17218. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17219. {
  17220. tempIndex = ((gun_index==2) ? 1: 0);
  17221. }
  17222. else
  17223. {
  17224. tempIndex = gun_index;
  17225. }
  17226. for (int index = 0; index < GB_QUANTITY; index++)
  17227. {
  17228. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17229. {
  17230. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17231. }
  17232. }// END OF GB_QUANTITY
  17233. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17234. }
  17235. else if(gunType[gun_index] == GUN_TYPE_DO)
  17236. {
  17237. tempIndex = gun_index;
  17238. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17239. {
  17240. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17241. {
  17242. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17243. }
  17244. }
  17245. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17246. }
  17247. else
  17248. {
  17249. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17250. {
  17251. tempIndex = 2;
  17252. }
  17253. else
  17254. {
  17255. tempIndex = gun_index;
  17256. }
  17257. for (int index = 0; index < AC_QUANTITY; index++)
  17258. {
  17259. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17260. {
  17261. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17262. }
  17263. }// END OF AC_QUANTITY
  17264. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17265. }
  17266. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17267. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17268. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17269. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17270. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17271. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17272. }
  17273. //2.3====================================== Power.Active.Import =========================================
  17274. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17275. {
  17276. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17277. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17278. {
  17279. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17280. {
  17281. tempIndex = ((gun_index==2) ? 1: 0);
  17282. }
  17283. else
  17284. {
  17285. tempIndex = gun_index;
  17286. }
  17287. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17288. {
  17289. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17290. {
  17291. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17292. }
  17293. } // End for CHAdeMO_QUANTITY
  17294. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17295. }
  17296. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17297. {
  17298. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17299. {
  17300. tempIndex = ((gun_index==2) ? 1: 0);
  17301. }
  17302. else
  17303. {
  17304. tempIndex = gun_index;
  17305. }
  17306. for (int index = 0; index < CCS_QUANTITY; index++)
  17307. {
  17308. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17309. {
  17310. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17311. }
  17312. } // END for CCS_QUANTITY
  17313. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17314. }
  17315. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17316. {
  17317. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17318. {
  17319. tempIndex = ((gun_index==2) ? 1: 0);
  17320. }
  17321. else
  17322. {
  17323. tempIndex = gun_index;
  17324. }
  17325. for (int index = 0; index < GB_QUANTITY; index++)
  17326. {
  17327. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17328. {
  17329. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17330. }
  17331. }// END for GB_QUANTITY
  17332. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17333. }
  17334. else if(gunType[gun_index] == GUN_TYPE_DO)
  17335. {
  17336. tempIndex = gun_index;
  17337. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17338. {
  17339. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17340. {
  17341. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17342. }
  17343. }
  17344. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17345. }
  17346. else
  17347. {
  17348. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17349. {
  17350. tempIndex = 2;
  17351. }
  17352. else
  17353. {
  17354. tempIndex = gun_index;
  17355. }
  17356. for (int index = 0; index < AC_QUANTITY; index++)
  17357. {
  17358. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17359. {
  17360. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17361. }
  17362. } // END for AC_QUANTITY
  17363. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17364. }
  17365. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17366. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17367. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17368. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17369. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17371. }
  17372. //2.4====================================== Voltage L1 ====================================================
  17373. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17374. {
  17375. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17376. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17377. {
  17378. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17379. {
  17380. tempIndex = ((gun_index==2) ? 1: 0);
  17381. }
  17382. else
  17383. {
  17384. tempIndex = gun_index;
  17385. }
  17386. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17387. {
  17388. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17389. {
  17390. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17391. }
  17392. } // END OF FOR CHAdeMO_QUANTITY
  17393. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17394. }
  17395. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17396. {
  17397. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17398. {
  17399. tempIndex = ((gun_index==2) ? 1: 0);
  17400. }
  17401. else
  17402. {
  17403. tempIndex = gun_index;
  17404. }
  17405. for (int index = 0; index < CCS_QUANTITY; index++)
  17406. {
  17407. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17408. {
  17409. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17410. }
  17411. } // END OF FOR CCS_QUANTITY
  17412. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17413. }
  17414. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17415. {
  17416. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17417. {
  17418. tempIndex = ((gun_index==2) ? 1: 0);
  17419. }
  17420. else
  17421. {
  17422. tempIndex = gun_index;
  17423. }
  17424. for (int index = 0; index < GB_QUANTITY; index++)
  17425. {
  17426. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17427. {
  17428. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17429. }
  17430. } // END OF FOR GB_QUANTITY
  17431. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17432. }
  17433. else if(gunType[gun_index] == GUN_TYPE_DO)
  17434. {
  17435. tempIndex = gun_index;
  17436. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17437. {
  17438. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17439. {
  17440. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17441. }
  17442. }
  17443. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17444. }
  17445. else
  17446. {
  17447. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17448. {
  17449. tempIndex = 2;
  17450. }
  17451. else
  17452. {
  17453. tempIndex = gun_index;
  17454. }
  17455. for (int index = 0; index < AC_QUANTITY; index++)
  17456. {
  17457. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17458. {
  17459. 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
  17460. }
  17461. } // END OF FOR AC_QUANTITY
  17462. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17463. }
  17464. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17465. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17466. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17467. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17468. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17469. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17470. }
  17471. //2.5============================================== End SoC =========================================================
  17472. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17473. {
  17474. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17475. 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))
  17476. {
  17477. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17478. {
  17479. tempIndex = ((gun_index==2) ? 1: 0);
  17480. }
  17481. else
  17482. {
  17483. tempIndex = gun_index;
  17484. }
  17485. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17486. {
  17487. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17488. {
  17489. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17490. {
  17491. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17492. }
  17493. }
  17494. }
  17495. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17496. {
  17497. for (int index = 0; index < CCS_QUANTITY; index++)
  17498. {
  17499. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17500. {
  17501. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17502. }
  17503. }
  17504. }
  17505. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17506. {
  17507. for (int index = 0; index < GB_QUANTITY; index++)
  17508. {
  17509. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17510. {
  17511. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17512. }
  17513. }
  17514. }
  17515. else if(gunType[gun_index] == GUN_TYPE_DO)
  17516. {
  17517. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17518. {
  17519. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17520. {
  17521. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17522. }
  17523. }
  17524. }
  17525. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17526. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17527. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17528. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17529. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17530. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17531. } // END FOR DC CASE
  17532. }
  17533. //2.6====================================== Current.Import L2 ==============================================
  17534. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17535. {
  17536. // AC 3 phase L2 current
  17537. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17538. {
  17539. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17540. {
  17541. tempIndex = 2;
  17542. }
  17543. else
  17544. {
  17545. tempIndex = gun_index;
  17546. }
  17547. for (int index = 0; index < AC_QUANTITY; index++)
  17548. {
  17549. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17550. {
  17551. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17552. }
  17553. }// End of for AC_QUANTITY
  17554. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17555. }
  17556. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17557. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17558. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17559. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17560. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17561. }
  17562. //2.7====================================== Current.Import L3 ==============================================
  17563. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17564. {
  17565. // AC 3 phase L3 current
  17566. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17567. {
  17568. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17569. {
  17570. tempIndex = 2;
  17571. }
  17572. else
  17573. {
  17574. tempIndex = gun_index;
  17575. }
  17576. for (int index = 0; index < AC_QUANTITY; index++)
  17577. {
  17578. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17579. {
  17580. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17581. }
  17582. }// End of for AC_QUANTITY
  17583. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17584. }
  17585. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17586. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17587. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17588. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17589. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17590. }
  17591. //2.9====================================== Voltage L2 ====================================================
  17592. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17593. {
  17594. // AC 3 phase L2 volatge
  17595. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17596. {
  17597. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17598. {
  17599. tempIndex = 2;
  17600. }
  17601. else
  17602. {
  17603. tempIndex = gun_index;
  17604. }
  17605. for (int index = 0; index < AC_QUANTITY; index++)
  17606. {
  17607. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17608. {
  17609. 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
  17610. }
  17611. } // END OF FOR AC_QUANTITY
  17612. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  17613. }
  17614. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17615. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17616. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17617. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17618. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17619. }
  17620. //2.10====================================== Voltage L3 ====================================================
  17621. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17622. {
  17623. // AC 3 phase L3 volatge
  17624. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17625. {
  17626. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17627. {
  17628. tempIndex = 2;
  17629. }
  17630. else
  17631. {
  17632. tempIndex = gun_index;
  17633. }
  17634. for (int index = 0; index < AC_QUANTITY; index++)
  17635. {
  17636. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17637. {
  17638. 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
  17639. }
  17640. } // END OF FOR AC_QUANTITY
  17641. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  17642. }
  17643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17644. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  17645. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  17646. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  17647. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17648. }
  17649. //====================== Start SoC ================================
  17650. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17651. {
  17652. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17653. 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))
  17654. {
  17655. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17656. {
  17657. tempIndex = ((gun_index==2) ? 1: 0);
  17658. }
  17659. else
  17660. {
  17661. tempIndex = gun_index;
  17662. }
  17663. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17664. {
  17665. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17666. {
  17667. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17668. {
  17669. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  17670. }
  17671. }
  17672. }
  17673. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17674. {
  17675. for (int index = 0; index < CCS_QUANTITY; index++)
  17676. {
  17677. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17678. {
  17679. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  17680. }
  17681. }
  17682. }
  17683. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17684. {
  17685. for (int index = 0; index < GB_QUANTITY; index++)
  17686. {
  17687. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17688. {
  17689. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  17690. }
  17691. }
  17692. }
  17693. else if(gunType[gun_index] == GUN_TYPE_DO)
  17694. {
  17695. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17696. {
  17697. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17698. {
  17699. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  17700. }
  17701. }
  17702. }
  17703. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17704. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  17705. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17706. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  17707. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  17708. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17709. } // END FOR DC CASE
  17710. }
  17711. //======================================== Message create ==============================================
  17712. json_object *StopTransaction = json_object_new_object();
  17713. json_object *transactionDatas = json_object_new_array();
  17714. json_object *sampledValues = json_object_new_array();
  17715. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  17716. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  17717. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  17718. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  17719. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  17720. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  17721. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  17722. {
  17723. json_object *transactionData = json_object_new_object();
  17724. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  17725. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  17726. {
  17727. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  17728. {
  17729. json_object *sampledValue = json_object_new_object();
  17730. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  17731. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  17732. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  17733. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  17734. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  17735. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  17736. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  17737. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  17738. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  17739. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  17740. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  17741. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  17742. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  17743. json_object_array_add(sampledValues, sampledValue);
  17744. }
  17745. }
  17746. json_object_object_add(transactionData, "sampledValue", sampledValues);
  17747. json_object_array_add(transactionDatas, transactionData);
  17748. }
  17749. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  17750. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  17751. ,MESSAGE_TYPE_CALL
  17752. ,guid
  17753. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  17754. json_object_put(StopTransaction);
  17755. // Check File "TempStopTransaction" Exist
  17756. if((access(TempStopTransaction,F_OK))!=-1)
  17757. {
  17758. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  17759. fclose(fopen(TempStopTransaction, "w"));
  17760. }
  17761. else
  17762. {
  17763. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  17764. FILE *log = fopen(TempStopTransaction, "w+");
  17765. if(log == NULL)
  17766. {
  17767. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  17768. return ;
  17769. }
  17770. else
  17771. {
  17772. fclose(log);
  17773. }
  17774. }
  17775. //Add TempStopTransaction | Update TempStopTransaction
  17776. // open file for writing
  17777. FILE *outfile;
  17778. outfile = fopen (TempStopTransaction, "a");
  17779. //DEBUG_INFO("data = %s\n", queuedata);
  17780. fputs(queuedata, outfile);
  17781. fputs("\n", outfile);
  17782. fclose (outfile);
  17783. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17784. OCPP_updatePeriodEnergy(gun_index);
  17785. }
  17786. void checkTempStopTransaction(int gun_index)
  17787. {
  17788. FILE *fptr1;
  17789. char ch;
  17790. char str[QUEUE_MESSAGE_LENGTH]={0};
  17791. char guid[37]={0};
  17792. char tempdata[65]={0};
  17793. char connectorStr[2]={0};
  17794. char TempStopTransaction[256];
  17795. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  17796. fptr1 = fopen(TempStopTransaction, "r");
  17797. //TempStopTransaction格式: 槍號,StopTransaction封包
  17798. if (!fptr1)
  17799. {
  17800. //printf(" File not found or unable to open the input file!!\n");
  17801. return ;
  17802. }
  17803. ch=fgetc(fptr1);
  17804. //printf(" Now the content of the file %s is : \n",fname);
  17805. rewind(fptr1);
  17806. if(ch!=EOF)
  17807. {
  17808. // copy all contents to the temporary file except the specific line
  17809. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  17810. {
  17811. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17812. if(str[0]=='\0')
  17813. {
  17814. break;
  17815. }
  17816. //TempStopTransaction格式: 槍號,StopTransaction封包
  17817. strncpy(connectorStr, str, 1);
  17818. if(atoi(connectorStr) != (gun_index+1))
  17819. {
  17820. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  17821. fclose(fptr1);
  17822. return ;
  17823. }
  17824. //random_uuid(guid);
  17825. strncpy(guid, str+6, 36); //copy guid
  17826. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  17827. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  17828. {
  17829. //DEBUG_INFO("StopTransaction mapitem pass\n");
  17830. }
  17831. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  17832. OCPP_insert_transaction_msg(NO, str);
  17833. memset(str,0,ARRAY_SIZE(str));
  17834. }
  17835. }
  17836. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  17837. fclose(fptr1);
  17838. remove(TempStopTransaction); // remove the original file
  17839. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17840. }
  17841. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  17842. {
  17843. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  17844. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  17845. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  17846. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  17847. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  17848. }
  17849. int GetWebSocketPingInterval(void)
  17850. {
  17851. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  17852. }
  17853. int GetServerSign(void)
  17854. {
  17855. return server_sign;
  17856. }
  17857. uint8_t GetOcppSecurityProfile()
  17858. {
  17859. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  17860. }
  17861. void GetOcppChargerBoxId(uint8_t *data)
  17862. {
  17863. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17864. }
  17865. void GetOcppSecurityPassword(uint8_t *data)
  17866. {
  17867. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17868. }
  17869. void SetOcppVersion(uint8_t *version)
  17870. {
  17871. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  17872. DEBUG_INFO("ocpp version: %s\n", version);
  17873. if(strstr((char*)version, "ocpp1.6") != NULL)
  17874. {
  17875. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  17876. }
  17877. else if(strstr((char*)version, "ocpp2.0") != NULL)
  17878. {
  17879. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  17880. system("pkill OcppBackend");
  17881. }
  17882. }
  17883. void SetServerSign(int value)
  17884. {
  17885. server_sign = value;
  17886. }
  17887. int GetBootNotificationInterval(void)
  17888. {
  17889. return BootNotificationInterval;
  17890. }
  17891. int GetInternetConn(void)
  17892. {
  17893. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  17894. }
  17895. int GetBackendConnectionTimeout(void)
  17896. {
  17897. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  17898. }
  17899. int isConnectorInitMode(int gun_index)
  17900. {
  17901. int tempIndex = 0;
  17902. int result = TRUE;
  17903. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17904. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17905. {
  17906. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17907. {
  17908. tempIndex = ((gun_index==2) ? 1: 0);
  17909. }
  17910. else
  17911. {
  17912. tempIndex = gun_index;
  17913. }
  17914. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17915. {
  17916. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  17917. {
  17918. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17919. } //end of the same index
  17920. }//end of for CHAdeMO_QUANTITY
  17921. }
  17922. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17923. {
  17924. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17925. {
  17926. tempIndex = ((gun_index==2) ? 1: 0);
  17927. }
  17928. else
  17929. {
  17930. tempIndex = gun_index;
  17931. }
  17932. for (int index = 0; index < CCS_QUANTITY; index++)
  17933. {
  17934. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17935. {
  17936. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17937. } //end of the same index
  17938. } // end of for CCS_QUANTITY
  17939. }
  17940. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17941. {
  17942. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17943. {
  17944. tempIndex = ((gun_index==2) ? 1: 0);
  17945. }
  17946. else
  17947. {
  17948. tempIndex = gun_index;
  17949. }
  17950. for (int index = 0; index < GB_QUANTITY; index++)
  17951. {
  17952. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17953. {
  17954. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17955. } //end of the same index
  17956. } // end of for GB_QUANTITY
  17957. }
  17958. else if(gunType[gun_index] == GUN_TYPE_DO)
  17959. {
  17960. tempIndex = gun_index;
  17961. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17962. {
  17963. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17964. {
  17965. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17966. } //end of the same index
  17967. }
  17968. }
  17969. else
  17970. {
  17971. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17972. {
  17973. tempIndex = 2;
  17974. }
  17975. else
  17976. {
  17977. tempIndex = gun_index;
  17978. }
  17979. for (int index = 0; index < AC_QUANTITY; index++)
  17980. {
  17981. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17982. {
  17983. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17984. }//end of the same index
  17985. }//end of for AC_QUANTITY
  17986. }
  17987. return result;
  17988. }
  17989. void refreshProcDogTimer()
  17990. {
  17991. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  17992. }
  17993. void InitialSystemValue(void)
  17994. {
  17995. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  17996. locallistVersion=0;
  17997. BootNotificationInterval = 0;
  17998. authorizeRetryTimes = 0;
  17999. GunStatusInterval = 10;
  18000. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18001. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18002. //Hear Beat
  18003. HeartBeatWithNOResponse = 0;
  18004. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18005. FirstHeartBeat = 0;
  18006. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18007. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18008. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18009. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18010. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18011. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18012. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18013. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18014. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18015. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18016. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18017. //Status && ConnectorPlugIn Setting
  18018. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18019. {
  18020. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18021. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18022. }
  18023. for (int index = 0; index < CCS_QUANTITY; index++)
  18024. {
  18025. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18026. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18027. }
  18028. for (int index = 0; index < GB_QUANTITY; index++)
  18029. {
  18030. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18031. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18032. }
  18033. for (int index = 0; index < AC_QUANTITY; index++)
  18034. {
  18035. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18036. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18037. }
  18038. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18039. {
  18040. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18041. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18042. }
  18043. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18044. {
  18045. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18046. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18047. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18048. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18049. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18050. }
  18051. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18052. refreshStartTimer(&clientTime.Heartbeat);
  18053. sleep(1);
  18054. }
  18055. void LWS_Send(char *str)
  18056. {
  18057. //=====================================================
  18058. // Check InternetConn 0: disconnected, 1: connected
  18059. //====================================================
  18060. if(GetOcppConnStatus() == 0)
  18061. {
  18062. DEBUG_INFO("offline now !!!\n");
  18063. return;
  18064. }
  18065. // Only disable isWebsocketSendable operation initiated by charger
  18066. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18067. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18068. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18069. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18070. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18071. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18072. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18073. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18074. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18075. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18076. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18077. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18078. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18079. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18080. {
  18081. isWebsocketSendable = 0;
  18082. }
  18083. pthread_mutex_lock(&lock_send);
  18084. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18085. sprintf((char *)SendBuffer, "%s", str);
  18086. SendBufLen = strlen(str);
  18087. pthread_mutex_unlock(&lock_send);
  18088. lws_callback_on_writable(wsi_client);
  18089. //lws_service(context, 0);
  18090. //sleep(1);
  18091. }
  18092. void LWS_SendNow(char *str)
  18093. {
  18094. //=====================================================
  18095. // Check InternetConn 0: disconnected, 1: connected
  18096. //====================================================
  18097. if(GetOcppConnStatus() == 0)
  18098. {
  18099. DEBUG_INFO("offline now !!!\n");
  18100. return;
  18101. }
  18102. // Only disable isWebsocketSendable operation initiated by charger
  18103. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18104. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18105. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18106. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18107. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18108. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18109. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18110. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18111. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18112. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18113. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18114. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18115. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18116. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18117. {
  18118. isWebsocketSendable = 0;
  18119. }
  18120. pthread_mutex_lock(&lock_send);
  18121. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18122. sprintf((char *)SendBuffer, "%s", str);
  18123. SendBufLen = strlen(str);
  18124. pthread_mutex_unlock(&lock_send);
  18125. lws_callback_on_writable(wsi_client);
  18126. lws_service(context, 0);
  18127. //sleep(1);
  18128. }