MessageHandler.c 904 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659
  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[256]={0};
  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)
  8352. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8353. }
  8354. json_object_put(ChangeConfiguration);
  8355. if((uuid==NULL) || (payload ==NULL) )
  8356. {
  8357. DEBUG_ERROR("Payload is null\n");
  8358. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8359. }
  8360. else
  8361. {
  8362. int status = setKeyValue(keystr, valuestr);
  8363. switch(status)
  8364. {
  8365. case ConfigurationStatus_Accepted:
  8366. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8367. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8368. StoreConfigurationTable();
  8369. break;
  8370. case RebootRequired:
  8371. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8372. StoreConfigurationTable();
  8373. break;
  8374. case NotSupported:
  8375. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8376. break;
  8377. case ConfigurationStatus_Rejected:
  8378. default:
  8379. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8380. break;
  8381. }
  8382. }
  8383. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8384. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8385. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8386. {
  8387. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8388. SetOcppConnStatus(FALSE);
  8389. }
  8390. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8391. {
  8392. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8393. }
  8394. return result;
  8395. }
  8396. int handleClearCacheRequest(char *uuid, char *payload)
  8397. {
  8398. mtrace();
  8399. int result = FAIL;
  8400. char comfirmstr[20];
  8401. char rmFileCmd[100]={0};
  8402. struct stat stats;
  8403. DEBUG_INFO("handleClearCacheRequest...\n");
  8404. stat("/Storage/OCPP", &stats);
  8405. // Check for directory existence
  8406. if (S_ISDIR(stats.st_mode) == 1)
  8407. {}
  8408. else
  8409. {
  8410. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8411. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  8412. system(rmFileCmd);
  8413. }
  8414. if(OCPP_cleanLocalCache())
  8415. {
  8416. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8417. }
  8418. else
  8419. {
  8420. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8421. }
  8422. sendClearCacheConfirmation(uuid, comfirmstr);
  8423. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8424. return result;
  8425. }
  8426. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8427. {
  8428. mtrace();
  8429. int result = FAIL;
  8430. int resultRename;
  8431. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8432. char chargingProfilePurposeStr[26]={0};
  8433. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8434. char tempchargingProfilePurposeStr[26]={0};
  8435. char str[100]={0};
  8436. char fname[200]={0};
  8437. char comfirmstr[20]={0};
  8438. char word[1600]={0};
  8439. int clearflag = FALSE;
  8440. int chargingProfileIdIsNULL = FALSE;
  8441. int connectorIsNULL = FALSE;
  8442. int chargingProfilePurposeIsNULL = FALSE;
  8443. int stackLevelIsNULL = FALSE;
  8444. //int GotoEnd = FALSE;
  8445. FILE *fptr1, *fptr2;
  8446. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  8447. int n_chargingProfile=0;
  8448. int isEmptyFile = FALSE;
  8449. char sLineWord[1600]={0};
  8450. char chargingProfiles[10][100]={0};
  8451. int ChargeProfileCount = 0;
  8452. int ch;
  8453. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8454. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8455. json_object *ClearChargingProfile;
  8456. ClearChargingProfile = json_tokener_parse(payload);
  8457. if(!is_error(ClearChargingProfile))
  8458. {
  8459. // Optional data
  8460. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8461. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8462. else
  8463. chargingProfileIdIsNULL = TRUE;
  8464. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8465. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8466. else
  8467. connectorIsNULL = TRUE;
  8468. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8469. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8470. else
  8471. chargingProfilePurposeIsNULL = TRUE;
  8472. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8473. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8474. else
  8475. stackLevelIsNULL = TRUE;
  8476. }
  8477. json_object_put(ClearChargingProfile);
  8478. if(connectorIsNULL == FALSE)
  8479. {
  8480. switch(connectorIdInt)
  8481. {
  8482. case 0:
  8483. if(chargingProfilePurposeIsNULL == TRUE)
  8484. {
  8485. int l = 0;
  8486. strcpy(fname, ChargePointMaxProfile_JSON);
  8487. if((access(fname,F_OK))!=-1)
  8488. {
  8489. strcpy(chargingProfiles[l], fname);
  8490. l = l + 1;
  8491. }
  8492. strcpy(fname, TxDefaultProfile_0_JSON);
  8493. if((access(fname,F_OK))!=-1)
  8494. {
  8495. strcpy(chargingProfiles[l], fname);
  8496. l = l + 1;
  8497. }
  8498. ChargeProfileCount = l;
  8499. }
  8500. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8501. {
  8502. strcpy(fname, ChargePointMaxProfile_JSON);
  8503. if((access(fname,F_OK))!=-1)
  8504. {
  8505. strcpy(chargingProfiles[0], fname);
  8506. ChargeProfileCount = 1;
  8507. }
  8508. }
  8509. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8510. {
  8511. strcpy(fname, TxDefaultProfile_0_JSON);
  8512. if((access(fname,F_OK))!=-1)
  8513. {
  8514. strcpy(chargingProfiles[0], fname);
  8515. ChargeProfileCount = 1;
  8516. }
  8517. }
  8518. break;
  8519. default:
  8520. if(chargingProfilePurposeIsNULL == TRUE)
  8521. {
  8522. int m = 0;
  8523. memset(fname, 0, ARRAY_SIZE(fname));
  8524. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8525. if((access(fname,F_OK))!=-1)
  8526. {
  8527. strcpy(chargingProfiles[m], fname);
  8528. m = m + 1;
  8529. }
  8530. memset(fname, 0, ARRAY_SIZE(fname));
  8531. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8532. if((access(fname,F_OK))!=-1)
  8533. {
  8534. strcpy(chargingProfiles[m], fname);
  8535. m = m + 1;
  8536. }
  8537. ChargeProfileCount = m;
  8538. }
  8539. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8540. {
  8541. //strcpy(fname, TxDefaultProfile_1_JSON);
  8542. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8543. if((access(fname,F_OK))!=-1)
  8544. {
  8545. strcpy(chargingProfiles[0], fname);
  8546. ChargeProfileCount = 1;
  8547. }
  8548. }
  8549. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8550. {
  8551. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8552. if((access(fname,F_OK))!=-1)
  8553. {
  8554. strcpy(chargingProfiles[0], fname);
  8555. ChargeProfileCount = 1;
  8556. }
  8557. //strcpy(fname, TxProfile_1_JSON);
  8558. }
  8559. //strcpy(fname, ChargePointMaxProfile_JSON );
  8560. break;
  8561. }
  8562. }
  8563. else // Check all Charging Profiles
  8564. {
  8565. int i = 0;
  8566. char fnametemp[200]={0};
  8567. ChargeProfileCount = 0;
  8568. //Check ChargePointMaxProfile.json exit
  8569. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8570. {
  8571. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  8572. i = i + 1;
  8573. }
  8574. //Check TxDefaultProfile_0.json exit
  8575. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8576. {
  8577. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  8578. i = i + 1;
  8579. }
  8580. //Check TxDefaultProfile_%d.json
  8581. for(int j=1; j <= gunTotalNumber; j++)
  8582. {
  8583. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8584. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8585. if((access(fnametemp,F_OK))!=-1)
  8586. {
  8587. strcpy(chargingProfiles[i], fnametemp);
  8588. i = i + 1;
  8589. }
  8590. }
  8591. //Check TxProfile_%d.json
  8592. for(int j=1; j <= gunTotalNumber; j++)
  8593. {
  8594. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8595. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8596. if((access(fnametemp,F_OK))!=-1)
  8597. {
  8598. strcpy(chargingProfiles[i], fnametemp);
  8599. i = i + 1;
  8600. }
  8601. }
  8602. ChargeProfileCount = i;
  8603. }// End connectorIsNULL is TRUE
  8604. if(ChargeProfileCount == 0)
  8605. {
  8606. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8607. goto end;
  8608. }
  8609. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8610. {
  8611. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8612. goto end;
  8613. }
  8614. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8615. {
  8616. memset(str, 0, ARRAY_SIZE(str));
  8617. // clear temp file
  8618. sprintf(str,"rm -f %s",temp);
  8619. system(str);
  8620. for(int k=0; k < ChargeProfileCount; k++)
  8621. {
  8622. memset(str, 0, ARRAY_SIZE(str));
  8623. //clear file in C
  8624. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8625. system(str);
  8626. }
  8627. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8628. goto end;
  8629. }
  8630. else if(connectorIsNULL == TRUE)
  8631. {
  8632. for(int k=0; k < ChargeProfileCount; k++)
  8633. {
  8634. fptr1 = fopen(chargingProfiles[k], "r");
  8635. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  8636. //Check Charging Profile Count
  8637. while(fscanf(fptr1, "%s", word) != EOF)
  8638. {
  8639. //DEBUG_INFO("word=%s\n",word);
  8640. if(strstr(word, "chargingProfileId")!= NULL)
  8641. {
  8642. //DEBUG_INFO("test chargingProfileId \n");
  8643. n_chargingProfile = n_chargingProfile + 1;
  8644. //DEBUG_INFO("chargingProfileId Found\n");
  8645. }
  8646. }
  8647. rewind(fptr1);
  8648. //search Charging Profile Element
  8649. //int i= 0;
  8650. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8651. {
  8652. json_object *tmpProfilee;
  8653. tmpProfilee = json_tokener_parse(sLineWord);
  8654. if(!is_error(tmpProfilee))
  8655. {
  8656. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8657. {
  8658. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8659. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8660. }
  8661. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8662. {
  8663. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8664. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8665. }
  8666. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8667. {
  8668. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8669. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8670. }
  8671. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8672. {
  8673. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8674. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8675. }
  8676. }
  8677. json_object_put(tmpProfilee);
  8678. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8679. {
  8680. //------- not write to fptr2-------//
  8681. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8682. //clearflag = TRUE;
  8683. }
  8684. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8685. {
  8686. //------- not write to fptr2-------//
  8687. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8688. }
  8689. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8690. {
  8691. //------- not write to fptr2-------//
  8692. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8693. }
  8694. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8695. {
  8696. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8697. }
  8698. else
  8699. {
  8700. fprintf(fptr2, sLineWord);//writing data into file
  8701. }
  8702. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8703. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8704. if(clearflag == TRUE)
  8705. {
  8706. fclose(fptr1);
  8707. fclose(fptr2);
  8708. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8709. system(str);
  8710. // clear temp file
  8711. sprintf(str,"rm -f %s",temp);
  8712. system(str);
  8713. }
  8714. else
  8715. {
  8716. fclose(fptr1);
  8717. fclose(fptr2);
  8718. memset(str, 0, ARRAY_SIZE(str));
  8719. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8720. system(str);
  8721. resultRename = rename(temp, chargingProfiles[k]);
  8722. if(resultRename == 0)
  8723. {
  8724. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8725. }
  8726. else
  8727. {
  8728. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8729. }
  8730. if(comfirmstr[0]== 0)
  8731. {
  8732. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8733. }
  8734. //Check chargingProfile is empty file
  8735. /*------ Read the file ----------------*/
  8736. fptr1=fopen(chargingProfiles[k],"r");
  8737. ch=fgetc(fptr1);
  8738. rewind(fptr1);
  8739. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8740. if(ch!=EOF)
  8741. {
  8742. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8743. {
  8744. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8745. if(sLineWord[0]=='\0')
  8746. {
  8747. isEmptyFile = TRUE;
  8748. break;
  8749. }
  8750. else
  8751. {
  8752. isEmptyFile = FALSE;
  8753. break;
  8754. }
  8755. }
  8756. }
  8757. else
  8758. isEmptyFile = TRUE;
  8759. fclose(fptr1);
  8760. if(isEmptyFile == TRUE)
  8761. {
  8762. memset(str, 0, ARRAY_SIZE(str));
  8763. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8764. system(str);
  8765. }
  8766. }
  8767. }// End of while(int k=0; k < ChargePointCount; k++)
  8768. }
  8769. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8770. {
  8771. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8772. for(int k=0; k < ChargeProfileCount; k++)
  8773. {
  8774. fptr1 = fopen(chargingProfiles[k], "r");
  8775. fptr2 = fopen(temp, "w+");
  8776. //Check Charging Profile Count
  8777. while(fscanf(fptr1, "%s", word) != EOF)
  8778. {
  8779. //DEBUG_INFO("word=%s\n",word);
  8780. if(strstr(word, "chargingProfileId")!= NULL)
  8781. {
  8782. n_chargingProfile = n_chargingProfile + 1;
  8783. }
  8784. }
  8785. rewind(fptr1);
  8786. //search Charging Profile Element
  8787. //int i= 0;
  8788. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8789. {
  8790. json_object *tmpProfilee;
  8791. tmpProfilee = json_tokener_parse(sLineWord);
  8792. if(!is_error(tmpProfilee))
  8793. {
  8794. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8795. {
  8796. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8797. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8798. }
  8799. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8800. {
  8801. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8802. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8803. }
  8804. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8805. {
  8806. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8807. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8808. }
  8809. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8810. {
  8811. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8812. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8813. }
  8814. }
  8815. json_object_put(tmpProfilee);
  8816. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8817. {
  8818. //------- not write to fptr2-------//
  8819. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8820. //clearflag = TRUE;
  8821. }
  8822. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8823. {
  8824. //------- not write to fptr2-------//
  8825. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8826. }
  8827. else if(stackLevelIsNULL == TRUE)
  8828. {
  8829. //Clear Whole File
  8830. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8831. clearflag = TRUE;
  8832. break;
  8833. }
  8834. else
  8835. {
  8836. fprintf(fptr2, sLineWord);//writing data into file
  8837. }
  8838. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8839. }
  8840. if(clearflag == TRUE)
  8841. {
  8842. fclose(fptr1);
  8843. fclose(fptr2);
  8844. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8845. system(str);
  8846. // clear temp file
  8847. sprintf(str,"rm -f %s",temp);
  8848. system(str);
  8849. }
  8850. else
  8851. {
  8852. fclose(fptr1);
  8853. fclose(fptr2);
  8854. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8855. system(str);
  8856. resultRename = rename(temp, chargingProfiles[k]);
  8857. if(resultRename == 0)
  8858. {
  8859. DEBUG_INFO("File ChargingProfile renamed successfully");
  8860. }
  8861. else
  8862. {
  8863. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8864. }
  8865. if(comfirmstr[0]== 0)
  8866. {
  8867. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8868. }
  8869. //Check chargingProfile is empty file
  8870. /*------ Read the file ----------------*/
  8871. fptr1=fopen(chargingProfiles[k],"r");
  8872. ch=fgetc(fptr1);
  8873. rewind(fptr1);
  8874. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8875. if(ch!=EOF)
  8876. {
  8877. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8878. {
  8879. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8880. if(sLineWord[0]=='\0')
  8881. {
  8882. isEmptyFile = TRUE;
  8883. break;
  8884. }
  8885. else
  8886. {
  8887. isEmptyFile = FALSE;
  8888. break;
  8889. }
  8890. }
  8891. }
  8892. else
  8893. isEmptyFile = TRUE;
  8894. fclose(fptr1);
  8895. if(isEmptyFile == TRUE)
  8896. {
  8897. memset(str, 0, ARRAY_SIZE(str));
  8898. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8899. system(str);
  8900. }
  8901. /*------- End of reading ---------------*/
  8902. }
  8903. } // while(int k=0; k < ChargeProfileCount; k++)
  8904. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8905. end:
  8906. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8907. {
  8908. if(connectorIdInt == 0)
  8909. {
  8910. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8911. {
  8912. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  8913. }
  8914. }
  8915. else
  8916. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  8917. }
  8918. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8919. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8920. return result;
  8921. }
  8922. void createFirmwareVersionByDataTransfer(void)
  8923. {
  8924. json_object *FirmwareDataTransfer = json_object_new_object();
  8925. // AC & DC model
  8926. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8927. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8928. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8929. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8930. // DC model
  8931. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8932. {
  8933. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8934. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8935. (gunType[3] != GUN_TYPE_UNKNOWN))
  8936. {
  8937. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8938. }
  8939. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8940. {
  8941. // DS DM DW
  8942. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8943. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8944. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8945. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8946. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8947. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8948. }
  8949. else
  8950. {
  8951. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8952. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8953. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8954. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8955. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8956. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8957. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8958. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8959. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8960. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8961. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8962. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8963. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8964. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8965. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8966. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8967. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8968. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8969. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8970. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8971. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8972. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8973. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8974. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8975. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8976. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8977. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8978. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8979. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8980. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8981. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8982. }
  8983. }
  8984. // 4G model
  8985. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8986. {
  8987. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8988. }
  8989. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8990. json_object_put(FirmwareDataTransfer);
  8991. }
  8992. int handleDataTransferRequest(char *uuid, char *payload)
  8993. {
  8994. mtrace();
  8995. json_object *response = json_object_new_object();
  8996. int result = FAIL;
  8997. char tempvendorId[255]={0};
  8998. char tempmessageId[50]={0};
  8999. char tempdata[512]={0};
  9000. char message[2048]={0};
  9001. DEBUG_INFO("handleDataTransferRequest...\n");
  9002. if((uuid != NULL) && (payload != NULL))
  9003. {
  9004. json_object *DataTransfer;
  9005. DataTransfer = json_tokener_parse(payload);
  9006. if(!is_error(DataTransfer))
  9007. {
  9008. // Required data
  9009. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9010. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9011. // Optional data
  9012. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9013. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9014. if(json_object_object_get(DataTransfer, "data") != NULL)
  9015. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9016. result = PASS;
  9017. }
  9018. json_object_put(DataTransfer);
  9019. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9020. {
  9021. // Send all moudle firmware version on EVSE
  9022. createFirmwareVersionByDataTransfer();
  9023. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9024. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9025. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9026. json_object_put(response);
  9027. }
  9028. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9029. {
  9030. system("/usr/bin/run_tmate_restart.sh &");
  9031. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9032. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9033. json_object_put(response);
  9034. }
  9035. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9036. {
  9037. json_object *data;
  9038. data = json_tokener_parse(tempdata);
  9039. if(!is_error(data))
  9040. {
  9041. 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))
  9042. {
  9043. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9044. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9045. if(json_object_object_get(data, "SOC") != NULL)
  9046. {
  9047. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9048. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9049. }
  9050. if(json_object_object_get(data, "Energy") != NULL)
  9051. {
  9052. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9053. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9054. }
  9055. if(json_object_object_get(data, "Duration") != NULL)
  9056. {
  9057. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9058. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9059. }
  9060. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9061. }
  9062. else
  9063. {
  9064. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9065. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9066. }
  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("Configuration content something wrong."));
  9072. }
  9073. json_object_put(data);
  9074. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9075. json_object_put(response);
  9076. }
  9077. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9078. {
  9079. json_object *data;
  9080. data = json_tokener_parse(tempdata);
  9081. if(!is_error(data))
  9082. {
  9083. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9084. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9085. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9086. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9087. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9088. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9089. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9090. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9091. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9092. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9093. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9094. }
  9095. else
  9096. {
  9097. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9098. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9099. }
  9100. json_object_put(data);
  9101. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9102. json_object_put(response);
  9103. }
  9104. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9105. {
  9106. json_object *data;
  9107. data = json_tokener_parse(tempdata);
  9108. if(!is_error(data))
  9109. {
  9110. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9111. if(json_object_object_get(data, "idToken") != NULL)
  9112. {
  9113. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9114. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9115. }
  9116. if(json_object_object_get(data, "price") != NULL)
  9117. {
  9118. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9119. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9120. }
  9121. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9122. }
  9123. else
  9124. {
  9125. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9126. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9127. }
  9128. json_object_put(data);
  9129. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9130. json_object_put(response);
  9131. }
  9132. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9133. {
  9134. json_object *data;
  9135. data = json_tokener_parse(tempdata);
  9136. if(!is_error(data))
  9137. {
  9138. if(json_object_object_get(data, "txId") != NULL)
  9139. {
  9140. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9141. for(int idx = 0;idx<gunTotalNumber;idx++)
  9142. {
  9143. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9144. {
  9145. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9146. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9147. if(json_object_object_get(data, "description") != NULL)
  9148. {
  9149. // California pricing V1.0
  9150. DEBUG_INFO("California pricing V1.0\n");
  9151. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9152. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9153. }
  9154. else
  9155. {
  9156. // California pricing V1.1
  9157. DEBUG_INFO("California pricing V1.1\n");
  9158. if(json_object_object_get(data, "timestamp") != NULL)
  9159. {
  9160. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9161. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9162. }
  9163. if(json_object_object_get(data, "meterValue") != NULL)
  9164. {
  9165. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9166. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9167. }
  9168. if(json_object_object_get(data, "cost") != NULL)
  9169. {
  9170. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9171. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9172. }
  9173. if(json_object_object_get(data, "state") != NULL)
  9174. {
  9175. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9176. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9177. }
  9178. if(json_object_object_get(data, "chargingPrice") != NULL)
  9179. {
  9180. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9181. {
  9182. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9183. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9184. }
  9185. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9186. {
  9187. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9188. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9189. }
  9190. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9191. {
  9192. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9193. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9194. }
  9195. }
  9196. if(json_object_object_get(data, "idlePrice") != NULL)
  9197. {
  9198. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9199. {
  9200. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9201. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9202. }
  9203. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9204. {
  9205. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9206. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9207. }
  9208. }
  9209. if(json_object_object_get(data, "nextPeriod") != NULL)
  9210. {
  9211. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9212. {
  9213. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9214. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9215. }
  9216. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9217. {
  9218. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9219. {
  9220. 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")));
  9221. 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"));
  9222. }
  9223. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9224. {
  9225. 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")));
  9226. 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"));
  9227. }
  9228. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9229. {
  9230. 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")));
  9231. 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"));
  9232. }
  9233. }
  9234. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9235. {
  9236. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9237. {
  9238. 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")));
  9239. 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"));
  9240. }
  9241. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9242. {
  9243. 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")));
  9244. 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"));
  9245. }
  9246. }
  9247. }
  9248. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9249. {
  9250. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9251. {
  9252. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9253. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9254. }
  9255. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9256. {
  9257. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9258. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9259. }
  9260. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9261. {
  9262. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9263. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9264. }
  9265. }
  9266. }
  9267. }
  9268. }
  9269. }
  9270. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9271. }
  9272. else
  9273. {
  9274. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9275. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9276. }
  9277. json_object_put(data);
  9278. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9279. json_object_put(response);
  9280. }
  9281. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9282. {
  9283. json_object *data;
  9284. data = json_tokener_parse(tempdata);
  9285. if(!is_error(data))
  9286. {
  9287. if(json_object_object_get(data, "txId") != NULL)
  9288. {
  9289. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9290. for(int idx = 0;idx<gunTotalNumber;idx++)
  9291. {
  9292. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9293. {
  9294. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9295. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9296. if(json_object_object_get(data, "description") != NULL)
  9297. {
  9298. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9299. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9300. }
  9301. }
  9302. }
  9303. }
  9304. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9305. }
  9306. else
  9307. {
  9308. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9309. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9310. }
  9311. json_object_put(data);
  9312. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9313. json_object_put(response);
  9314. }
  9315. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9316. {
  9317. json_object *data;
  9318. data = json_tokener_parse(tempdata);
  9319. if(!is_error(data))
  9320. {
  9321. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9322. if(json_object_object_get(data, "Content_Type") != NULL)
  9323. {
  9324. 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))
  9325. {
  9326. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9327. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9328. {
  9329. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9330. }
  9331. }
  9332. else
  9333. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9334. }
  9335. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9336. }
  9337. else
  9338. {
  9339. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9340. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9341. }
  9342. json_object_put(data);
  9343. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9344. json_object_put(response);
  9345. }
  9346. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  9347. {
  9348. json_object *data;
  9349. data = json_tokener_parse(tempdata);
  9350. if(!is_error(data))
  9351. {
  9352. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9353. if(json_object_object_get(data, "Page_Index") != NULL)
  9354. {
  9355. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9356. }
  9357. if(json_object_object_get(data, "Duration") != NULL)
  9358. {
  9359. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9360. }
  9361. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  9362. }
  9363. else
  9364. {
  9365. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9366. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9367. }
  9368. json_object_put(data);
  9369. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9370. json_object_put(response);
  9371. }
  9372. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9373. {
  9374. json_object *data;
  9375. data = json_tokener_parse(tempdata);
  9376. if(!is_error(data))
  9377. {
  9378. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9379. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9380. {
  9381. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9382. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9383. else
  9384. {
  9385. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9386. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9387. }
  9388. }
  9389. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9390. {
  9391. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9392. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9393. else
  9394. {
  9395. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9396. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9397. }
  9398. }
  9399. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9400. {
  9401. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9402. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9403. else
  9404. {
  9405. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9406. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9407. }
  9408. }
  9409. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9410. {
  9411. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9412. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9413. else
  9414. {
  9415. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9416. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9417. }
  9418. }
  9419. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9420. {
  9421. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9422. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9423. else
  9424. {
  9425. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9426. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9427. }
  9428. }
  9429. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9430. {
  9431. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9432. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9433. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9434. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9435. else
  9436. {
  9437. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9438. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9439. }
  9440. }
  9441. if(json_object_object_get(data, "isAuthentication") != NULL)
  9442. {
  9443. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9444. {
  9445. case 0:
  9446. case 1:
  9447. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9448. break;
  9449. default:
  9450. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9451. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9452. break;
  9453. }
  9454. }
  9455. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9456. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9457. }
  9458. else
  9459. {
  9460. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9461. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9462. }
  9463. json_object_put(data);
  9464. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9465. json_object_put(response);
  9466. }
  9467. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  9468. {
  9469. json_object *data;
  9470. data = json_tokener_parse(tempdata);
  9471. if(!is_error(data))
  9472. {
  9473. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9474. {
  9475. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  9476. {
  9477. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9478. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9479. }
  9480. else
  9481. {
  9482. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9483. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  9484. }
  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("Configuration content something wrong."));
  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. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9498. json_object_put(response);
  9499. }
  9500. else
  9501. {
  9502. // Can not find valid message id
  9503. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9504. }
  9505. }
  9506. else
  9507. {
  9508. // Payload is null
  9509. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9510. }
  9511. LWS_Send(message);
  9512. return result;
  9513. }
  9514. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9515. {
  9516. mtrace();
  9517. int result = FAIL;
  9518. int connectorIdInt, durationInt;
  9519. char chargingRateUnitStr[4]={0};
  9520. char comfirmstr[20];
  9521. int confirmPeriods = 0;
  9522. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9523. json_object *GetCompositeSchedule;
  9524. GetCompositeSchedule = json_tokener_parse(payload);
  9525. if(!is_error(GetCompositeSchedule))
  9526. {
  9527. // Required data
  9528. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9529. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9530. else
  9531. connectorIdInt = -1;
  9532. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9533. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9534. else
  9535. durationInt = 86400;
  9536. // Optional data
  9537. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9538. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9539. }
  9540. json_object_put(GetCompositeSchedule);
  9541. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9542. if((connectorIdInt == 0) ||
  9543. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9544. {
  9545. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9546. struct StructChargingProfile tmpProfile[1];
  9547. if(strstr(chargingRateUnitStr, "W") != NULL)
  9548. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9549. else
  9550. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9551. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9552. {
  9553. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9554. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9555. }
  9556. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9557. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9558. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9559. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9560. {
  9561. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9562. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9563. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9564. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9565. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9566. {
  9567. confirmPeriods = idx;
  9568. break;
  9569. }
  9570. }
  9571. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9572. {
  9573. confirmPeriods += 1;
  9574. }
  9575. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9576. }
  9577. else
  9578. {
  9579. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9580. }
  9581. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9582. return result;
  9583. }
  9584. int handleGetConfigurationRequest(char *uuid, char *payload)
  9585. {
  9586. mtrace();
  9587. int result = FAIL;
  9588. int MaxKeySupported = 0;
  9589. int n_keys = 0;
  9590. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9591. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9592. json_object *GetConfiguration;
  9593. GetConfiguration = json_tokener_parse(payload);
  9594. if(!is_error(GetConfiguration))
  9595. {
  9596. // Optional data
  9597. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9598. {
  9599. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9600. {
  9601. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9602. n_keys = idx + 1;
  9603. }
  9604. }
  9605. }
  9606. json_object_put(GetConfiguration);
  9607. UnknownKeynum = 0;
  9608. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9609. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9610. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9611. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9612. if(n_keys != 0)
  9613. {
  9614. for(int i=0;i<n_keys;i++)
  9615. {
  9616. getKeyValue(requestKey[i]);
  9617. }
  9618. }
  9619. else
  9620. {
  9621. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9622. getKeyValue("");
  9623. }
  9624. processUnkownKey();
  9625. sendGetConfigurationConfirmation(uuid);
  9626. return result;
  9627. }
  9628. static char fnamePlusPath[100]={0};
  9629. static char fnamePWithNoPath[60]={0};
  9630. void checkUploadLog(void)
  9631. {
  9632. FILE *fp;
  9633. /* Open the command for reading. */
  9634. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9635. if (fp == NULL) {
  9636. DEBUG_WARN("Failed to run command\n" );
  9637. exit(1);
  9638. }
  9639. int ftppathlen = 0;
  9640. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9641. int i = 0;
  9642. /* Read the output a line at a time - output it. */
  9643. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9644. if(i==0)
  9645. {
  9646. ftppathlen = strlen(fnamePlusPath);
  9647. DEBUG_INFO("%s\n", fnamePlusPath);
  9648. fnamePlusPath[ftppathlen]='\0';
  9649. break;
  9650. }
  9651. i= i+1;
  9652. }
  9653. /* close */
  9654. pclose(fp);
  9655. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9656. {
  9657. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9658. {
  9659. fnamePlusPath[k]='\0';
  9660. }
  9661. }
  9662. i=1;
  9663. //char fname[60]={0};
  9664. while(i < ftppathlen)
  9665. {
  9666. int len=ftppathlen-i;
  9667. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9668. {
  9669. DEBUG_INFO("compare '/' all right\n");
  9670. break;
  9671. }
  9672. i=i+1;
  9673. }
  9674. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9675. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9676. fnamePWithNoPath[i+1] = '\0';
  9677. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9678. {
  9679. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9680. {
  9681. fnamePWithNoPath[j]='\0';
  9682. }
  9683. }
  9684. FILE* fp1 = fopen(fnamePlusPath, "r");
  9685. if (fp1)
  9686. {
  9687. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9688. // file exists
  9689. fclose(fp1);
  9690. }
  9691. else
  9692. {
  9693. // file doesn't exist
  9694. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9695. }
  9696. }
  9697. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9698. {
  9699. mtrace();
  9700. int result = FAIL;
  9701. time_t CurrentTime;
  9702. struct tm *tm;
  9703. pthread_t th_Status;
  9704. CurrentTime = time(NULL);
  9705. tm = localtime(&CurrentTime);
  9706. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  9707. 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);
  9708. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9709. if(!interLock.isGetDiagnosticGoing)
  9710. {
  9711. interLock.isGetDiagnosticGoing = 1;
  9712. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9713. sleep(1);
  9714. }
  9715. else
  9716. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9717. return result;
  9718. }
  9719. void* GetDiagnosticsProcess(void* data)
  9720. {
  9721. pthread_detach(pthread_self());
  9722. mtrace();
  9723. int retriesInt=0, retryIntervalInt=0;
  9724. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9725. 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};
  9726. int port=0;
  9727. int isSuccess = FALSE;
  9728. char cmdBuf[2048];
  9729. struct tm *tmNow;
  9730. time_t CurrentTime;
  9731. struct tm tmStart;
  9732. struct tm tmStop;
  9733. CurrentTime = time(NULL);
  9734. tmNow=localtime(&CurrentTime);
  9735. uint16_t targetYear, targetMonth;
  9736. json_object *GetDiagnostics;
  9737. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9738. GetDiagnostics = json_tokener_parse(data);
  9739. if(!is_error(GetDiagnostics))
  9740. {
  9741. // Required data
  9742. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9743. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9744. // Optional data
  9745. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9746. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9747. else
  9748. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9749. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9750. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9751. else
  9752. retryIntervalInt = 30;
  9753. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9754. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9755. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9756. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9757. }
  9758. json_object_put(GetDiagnostics);
  9759. // Pack log to compress file
  9760. 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) &&
  9761. (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))
  9762. {
  9763. // Pack system log
  9764. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9765. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9766. targetYear = tmStart.tm_year;
  9767. targetMonth = tmStart.tm_mon;
  9768. do
  9769. {
  9770. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9771. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9772. if(targetMonth+1>=13)
  9773. {
  9774. targetYear += 1;
  9775. targetMonth = 1;
  9776. }
  9777. else
  9778. {
  9779. targetMonth += 1;
  9780. }
  9781. }while((targetYear < (tmNow->tm_year+1900)) ||
  9782. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9783. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9784. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9785. system(cmdBuf);
  9786. // Pack charging & event log
  9787. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9788. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9789. targetYear = tmStart.tm_year;
  9790. targetMonth = tmStart.tm_mon;
  9791. do
  9792. {
  9793. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9794. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9795. if(targetMonth+1>=13)
  9796. {
  9797. targetYear += 1;
  9798. targetMonth = 1;
  9799. }
  9800. else
  9801. {
  9802. targetMonth += 1;
  9803. }
  9804. }while((targetYear < (tmNow->tm_year+1900)) ||
  9805. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9806. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9807. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9808. system(cmdBuf);
  9809. // Combine log file
  9810. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9811. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9812. }
  9813. else
  9814. {
  9815. system("exec /root/logPackTools 'log' 6");
  9816. }
  9817. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9818. system(cmdBuf);
  9819. checkUploadLog();
  9820. //****************location*******************/
  9821. if(strcmp(locationstr,"")==0)
  9822. {
  9823. DEBUG_INFO("location is <Empty>!\n");
  9824. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9825. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9826. goto end;
  9827. }
  9828. memset(protocol, 0, ARRAY_SIZE(protocol));
  9829. memset(user, 0, ARRAY_SIZE(user) );
  9830. memset(password, 0, ARRAY_SIZE(password));
  9831. memset(host, 0, ARRAY_SIZE(host));
  9832. memset(path, 0, ARRAY_SIZE(path));
  9833. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9834. memset(host1, 0, ARRAY_SIZE(host1));
  9835. memset(path1, 0, ARRAY_SIZE(path1));
  9836. /*location: ftp://user:password@host:port/path*/
  9837. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9838. if((access(fnamePlusPath,F_OK))!=-1)
  9839. {
  9840. DEBUG_INFO("fnamePlusPath exist.\n");
  9841. }
  9842. else
  9843. {
  9844. DEBUG_INFO("fnamePlusPath not exist!\n");
  9845. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9846. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9847. goto end;
  9848. }
  9849. if(strchr(locationstr,'@')==NULL)
  9850. {
  9851. sscanf(locationstr,
  9852. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9853. protocol, host, &port, path);
  9854. strcpy(user,"anonymous");
  9855. strcpy(password,"");
  9856. }
  9857. else
  9858. {
  9859. //DEBUG_INFO("pch=%s\n", pch);
  9860. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9861. protocol, user, password, host, &port, path);
  9862. }
  9863. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9864. {
  9865. DEBUG_INFO("protocol is not ftp/http ! \n");
  9866. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9867. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9868. goto end;
  9869. }
  9870. if(strncmp(locationstr,"http", 4) == 0)
  9871. {
  9872. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9873. sprintf(ftppath,"/%s", path);
  9874. do
  9875. {
  9876. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9877. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9878. sleep(3);
  9879. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9880. if(!isSuccess)
  9881. {
  9882. DEBUG_INFO("Diagnostics fail.\n");
  9883. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9884. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9885. sleep(retryIntervalInt);
  9886. }
  9887. else
  9888. {
  9889. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9890. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9891. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9892. }
  9893. retriesInt--;
  9894. }while((isSuccess == 0)&&(retriesInt >= 0));
  9895. }
  9896. else
  9897. {
  9898. sscanf(host,"%[^/]%s",host1, path1);
  9899. if(strlen(path) > 0)
  9900. sprintf(ftppath,"/%s", path);
  9901. else
  9902. sprintf(ftppath,"/%s", path1);
  9903. int ftppathlen=strlen(ftppath);
  9904. int i=1;
  9905. char filenametemp[50];
  9906. while(i < ftppathlen)
  9907. {
  9908. int len=ftppathlen-i;
  9909. if(ftppath[len]== 47) // '/' ascll code: 47
  9910. {
  9911. DEBUG_INFO("find '/' all right\n");
  9912. break;
  9913. }
  9914. i=i+1;
  9915. }
  9916. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9917. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9918. filenametemp[i+1] = 0;
  9919. if(port == 0)
  9920. port = 21;
  9921. do
  9922. {
  9923. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9924. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9925. sleep(3);
  9926. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9927. if(!isSuccess)
  9928. {
  9929. DEBUG_INFO("Diagnostics fail.\n");
  9930. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9931. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9932. sleep(retryIntervalInt);
  9933. }
  9934. else
  9935. {
  9936. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9937. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9938. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9939. }
  9940. retriesInt--;
  9941. }while((!isSuccess)&&(retriesInt >= 0));
  9942. }
  9943. end:
  9944. system("rm -f /mnt/*");
  9945. sleep(5);
  9946. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9947. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9948. interLock.isGetDiagnosticGoing = 0;
  9949. pthread_exit(NULL);
  9950. }
  9951. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9952. {
  9953. mtrace();
  9954. int result = FAIL;
  9955. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9956. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9957. {
  9958. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9959. locallistVersion = -1;
  9960. }
  9961. else
  9962. {
  9963. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9964. OCPP_getListVerion();
  9965. }
  9966. //from db.OCPP_getListVerion
  9967. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9968. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  9969. sendGetLocalListVersionConfirmation(uuid,"");
  9970. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  9971. return result;
  9972. }
  9973. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  9974. {
  9975. mtrace();
  9976. int result = FAIL;
  9977. int connectorIdInt=-1;
  9978. int tempIndex = 0;
  9979. int connectorIdIsNULL, chargingProfileIsNULL;
  9980. char comfirmstr[20]={0};
  9981. char cmdBuf[512];
  9982. json_object *RemoteStartTransaction;
  9983. FILE *fp;
  9984. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9985. if(server_pending == TRUE)
  9986. {
  9987. return 0;
  9988. }
  9989. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9990. RemoteStartTransaction = json_tokener_parse(payload);
  9991. if(!is_error(RemoteStartTransaction))
  9992. {
  9993. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9994. {
  9995. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9996. }
  9997. else
  9998. {
  9999. connectorIdIsNULL = TRUE;
  10000. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10001. {
  10002. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10003. {
  10004. connectorIdIsNULL = FALSE;
  10005. connectorIdInt = (gun_index+1);
  10006. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10007. break;
  10008. }
  10009. }
  10010. }
  10011. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10012. {
  10013. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10014. // Required data
  10015. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10016. // Optional data
  10017. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10018. {
  10019. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10020. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10021. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10022. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10023. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10024. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10025. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10026. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10027. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10028. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10029. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10030. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10031. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10032. {
  10033. 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")));
  10034. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10035. 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"));
  10036. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10037. 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"));
  10038. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10039. 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")));
  10040. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10041. {
  10042. 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++)
  10043. {
  10044. 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"));
  10045. 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"));
  10046. 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)
  10047. 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"));
  10048. }
  10049. }
  10050. }
  10051. }
  10052. else
  10053. {
  10054. chargingProfileIsNULL = TRUE;
  10055. }
  10056. }
  10057. }
  10058. else
  10059. {
  10060. connectorIdIsNULL = TRUE;
  10061. }
  10062. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10063. {
  10064. DEBUG_WARN("Connector id is NULL\n.");
  10065. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10066. goto end;
  10067. }
  10068. /*
  10069. enum _SYSTEM_STATUS
  10070. {
  10071. S_BOOTING = 0,
  10072. S_IDLE, = 1
  10073. S_AUTHORIZING, = 2
  10074. S_REASSIGN_CHECK, = 3
  10075. S_REASSIGN, = 4
  10076. S_PRECHARGE, = 5
  10077. S_PREPARING_FOR_EV, = 6
  10078. S_PREPARING_FOR_EVSE, = 7
  10079. S_CHARGING, = 8
  10080. S_TERMINATING, = 9
  10081. S_COMPLETE, = 10
  10082. S_ALARM, = 11
  10083. S_FAULT = 12
  10084. }
  10085. */
  10086. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10087. {
  10088. //check Transaction active
  10089. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10090. {
  10091. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10092. {
  10093. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10094. }
  10095. else
  10096. {
  10097. tempIndex = connectorIdInt -1;
  10098. }
  10099. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10100. {
  10101. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10102. {
  10103. 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))
  10104. {
  10105. //Reserved
  10106. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10107. }
  10108. 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))
  10109. {
  10110. //Reserved
  10111. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10112. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10113. goto end;
  10114. }
  10115. else
  10116. {
  10117. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10118. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10119. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10120. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10121. {
  10122. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10123. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10124. goto end;
  10125. }
  10126. }//END FOR ELSE
  10127. }
  10128. }// END FOR CHAdeMO_QUANTITY
  10129. }
  10130. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10131. {
  10132. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10133. {
  10134. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10135. }
  10136. else
  10137. {
  10138. tempIndex = connectorIdInt -1;
  10139. }
  10140. for (int index = 0; index < CCS_QUANTITY; index++)
  10141. {
  10142. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10143. {
  10144. 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))
  10145. {
  10146. //Reserved
  10147. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10148. }
  10149. 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))
  10150. {
  10151. //Reserved
  10152. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10153. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10154. goto end;
  10155. }
  10156. else
  10157. {
  10158. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10159. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10160. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10161. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10162. {
  10163. DEBUG_WARN("CCS connector not allow start\n.");
  10164. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10165. goto end;
  10166. }
  10167. }// END FOR ELSE
  10168. }
  10169. }// END FOR CCS_QUANTITY
  10170. }
  10171. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10172. {
  10173. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10174. {
  10175. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10176. }
  10177. else
  10178. {
  10179. tempIndex = connectorIdInt -1;
  10180. }
  10181. for (int index = 0; index < GB_QUANTITY; index++)
  10182. {
  10183. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10184. {
  10185. 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))
  10186. {
  10187. //Reserved
  10188. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10189. }
  10190. 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))
  10191. {
  10192. //Reserved
  10193. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10194. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10195. goto end;
  10196. }
  10197. else
  10198. {
  10199. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10200. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10201. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10202. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10203. {
  10204. DEBUG_WARN("GB connector not allow start\n.");
  10205. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10206. goto end;
  10207. }
  10208. }// END FOR ELSE
  10209. }
  10210. } // END FOR GB_QUANTITY
  10211. }
  10212. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10213. {
  10214. tempIndex = connectorIdInt -1;
  10215. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10216. {
  10217. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10218. {
  10219. 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))
  10220. {
  10221. //Reserved
  10222. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10223. }
  10224. 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))
  10225. {
  10226. //Reserved
  10227. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10228. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10229. goto end;
  10230. }
  10231. else
  10232. {
  10233. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10234. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10235. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10236. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10237. {
  10238. DEBUG_WARN("GB connector not allow start\n.");
  10239. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10240. goto end;
  10241. }
  10242. }// END FOR ELSE
  10243. }
  10244. } // END FOR GB_QUANTITY
  10245. }
  10246. else
  10247. {
  10248. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10249. {
  10250. tempIndex = 2;
  10251. }
  10252. else
  10253. {
  10254. tempIndex = connectorIdInt -1;
  10255. }
  10256. for (int index = 0; index < AC_QUANTITY; index++)
  10257. {
  10258. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10259. {
  10260. 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))
  10261. {
  10262. //Reserved
  10263. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10264. }
  10265. 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))
  10266. {
  10267. //Reserved
  10268. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10269. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10270. goto end;
  10271. }
  10272. else
  10273. {
  10274. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10275. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10276. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10277. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10278. {
  10279. DEBUG_WARN("AC connector not allow start\n.");
  10280. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10281. goto end;
  10282. }
  10283. }//END FOR ELSE
  10284. }
  10285. }// END FOR AC_QUANTITY
  10286. }
  10287. if(chargingProfileIsNULL == FALSE)
  10288. {
  10289. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10290. {
  10291. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10292. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10293. //memset idTag
  10294. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10295. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10296. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10297. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10298. // Save profile to file
  10299. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10300. system(cmdBuf);
  10301. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10302. fp = fopen(cmdBuf, "w");
  10303. 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));
  10304. fclose(fp);
  10305. }
  10306. else
  10307. {
  10308. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10309. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10310. }
  10311. }
  10312. else
  10313. {
  10314. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10315. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10316. //memset idTag
  10317. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10318. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10319. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10320. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10321. }
  10322. }
  10323. else
  10324. {
  10325. DEBUG_WARN("Connector id over\n.");
  10326. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10327. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10328. }
  10329. end:
  10330. json_object_put(RemoteStartTransaction);
  10331. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10332. {
  10333. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10334. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10335. }
  10336. //OCPP send RemoteStartConfirmation by first.
  10337. sendRemoteStartConfirmation(uuid, comfirmstr);
  10338. return result;
  10339. }
  10340. int handleRemoteStartRequest(char *uuid, char *payload)
  10341. {
  10342. mtrace();
  10343. int result = PASS;
  10344. int connectorIdInt=-1;
  10345. int tempIndex = 0;
  10346. char comfirmstr[20]={0};
  10347. char cmdBuf[512];
  10348. json_object *RemoteStartTransaction;
  10349. FILE *fp;
  10350. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10351. if(server_pending == TRUE)
  10352. {
  10353. result = FAIL;
  10354. }
  10355. RemoteStartTransaction = json_tokener_parse(payload);
  10356. if(!is_error(RemoteStartTransaction))
  10357. {
  10358. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10359. {
  10360. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10361. }
  10362. else
  10363. {
  10364. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10365. {
  10366. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10367. {
  10368. connectorIdInt = (gun_index+1);
  10369. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10370. break;
  10371. }
  10372. }
  10373. }
  10374. if(connectorIdInt == 0)
  10375. {
  10376. DEBUG_WARN("Connector id shall not equal 0.\n");
  10377. result = FAIL;
  10378. }
  10379. else if(connectorIdInt == -1)
  10380. {
  10381. DEBUG_INFO("Connector id does not specific.\n");
  10382. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10383. {
  10384. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10385. // Required data
  10386. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10387. // Optional data
  10388. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10389. {
  10390. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10391. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10392. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10393. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10394. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10395. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10396. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10397. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10398. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10399. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10400. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10401. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10402. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10403. {
  10404. 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")));
  10405. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10406. 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"));
  10407. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10408. 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"));
  10409. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10410. 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")));
  10411. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10412. {
  10413. 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++)
  10414. {
  10415. 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"));
  10416. 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"));
  10417. 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)
  10418. 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"));
  10419. }
  10420. }
  10421. }
  10422. }
  10423. else
  10424. {
  10425. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10426. }
  10427. }
  10428. }
  10429. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10430. {
  10431. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10432. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10433. // Required data
  10434. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10435. // Optional data
  10436. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10437. {
  10438. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10439. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10440. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10441. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10442. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10443. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10444. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10445. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10446. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10447. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10448. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10449. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10450. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10451. {
  10452. 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")));
  10453. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10454. 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"));
  10455. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10456. 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"));
  10457. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10458. 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")));
  10459. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10460. {
  10461. 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++)
  10462. {
  10463. 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"));
  10464. 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"));
  10465. 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)
  10466. 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"));
  10467. }
  10468. }
  10469. }
  10470. }
  10471. else
  10472. {
  10473. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10474. }
  10475. }
  10476. else
  10477. {
  10478. DEBUG_WARN("Connector id is over maximun value.\n");
  10479. result = FAIL;
  10480. }
  10481. }
  10482. if(result == PASS)
  10483. {
  10484. if(connectorIdInt > 0)
  10485. {
  10486. //check Transaction active
  10487. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10488. {
  10489. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10490. {
  10491. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10492. }
  10493. else
  10494. {
  10495. tempIndex = connectorIdInt -1;
  10496. }
  10497. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10498. {
  10499. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10500. {
  10501. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10502. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10503. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10504. {
  10505. //Reserved
  10506. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10507. }
  10508. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10509. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10510. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10511. {
  10512. //Reserved
  10513. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10514. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10515. goto end;
  10516. }
  10517. else
  10518. {
  10519. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10520. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10521. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10522. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10523. {
  10524. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10525. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10526. goto end;
  10527. }
  10528. }//END FOR ELSE
  10529. }
  10530. }// END FOR CHAdeMO_QUANTITY
  10531. }
  10532. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10533. {
  10534. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10535. {
  10536. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10537. }
  10538. else
  10539. {
  10540. tempIndex = connectorIdInt -1;
  10541. }
  10542. for (int index = 0; index < CCS_QUANTITY; index++)
  10543. {
  10544. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10545. {
  10546. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10547. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10548. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10549. {
  10550. //Reserved
  10551. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10552. }
  10553. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10554. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10555. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10556. {
  10557. //Reserved
  10558. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10559. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10560. goto end;
  10561. }
  10562. else
  10563. {
  10564. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10565. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10566. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10567. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10568. {
  10569. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10570. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10571. goto end;
  10572. }
  10573. }// END FOR ELSE
  10574. }
  10575. }// END FOR CCS_QUANTITY
  10576. }
  10577. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10578. {
  10579. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10580. {
  10581. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10582. }
  10583. else
  10584. {
  10585. tempIndex = connectorIdInt -1;
  10586. }
  10587. for (int index = 0; index < GB_QUANTITY; index++)
  10588. {
  10589. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10590. {
  10591. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10592. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10593. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10594. {
  10595. //Reserved
  10596. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10597. }
  10598. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10599. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10600. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10601. {
  10602. //Reserved
  10603. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10604. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10605. goto end;
  10606. }
  10607. else
  10608. {
  10609. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10610. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10611. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10612. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10613. {
  10614. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10615. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10616. goto end;
  10617. }
  10618. }// END FOR ELSE
  10619. }
  10620. } // END FOR GB_QUANTITY
  10621. }
  10622. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10623. {
  10624. tempIndex = connectorIdInt -1;
  10625. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10626. {
  10627. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10628. {
  10629. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10630. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10631. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10632. {
  10633. //Reserved
  10634. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10635. }
  10636. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10637. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10638. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10639. {
  10640. //Reserved
  10641. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10642. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10643. goto end;
  10644. }
  10645. else
  10646. {
  10647. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10648. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10649. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10650. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10651. {
  10652. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10653. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10654. goto end;
  10655. }
  10656. }// END FOR ELSE
  10657. }
  10658. } // END FOR GB_QUANTITY
  10659. }
  10660. else
  10661. {
  10662. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10663. {
  10664. tempIndex = 2;
  10665. }
  10666. else
  10667. {
  10668. tempIndex = connectorIdInt -1;
  10669. }
  10670. for (int index = 0; index < AC_QUANTITY; index++)
  10671. {
  10672. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10673. {
  10674. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10675. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10676. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10677. {
  10678. //Reserved
  10679. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10680. }
  10681. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10682. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10683. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10684. {
  10685. //Reserved
  10686. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10687. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10688. goto end;
  10689. }
  10690. else
  10691. {
  10692. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10693. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10694. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10695. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10696. {
  10697. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10698. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10699. goto end;
  10700. }
  10701. }//END FOR ELSE
  10702. }
  10703. }// END FOR AC_QUANTITY
  10704. }
  10705. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10706. {
  10707. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10708. {
  10709. // Save profile to file
  10710. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10711. system(cmdBuf);
  10712. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10713. fp = fopen(cmdBuf, "w");
  10714. 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));
  10715. fclose(fp);
  10716. }
  10717. else
  10718. {
  10719. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10720. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10721. goto end;
  10722. }
  10723. }
  10724. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10725. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10726. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10727. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10728. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10729. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10730. }
  10731. else
  10732. {
  10733. uint8_t isHasIdleConnector = FALSE;
  10734. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10735. {
  10736. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10737. {
  10738. isHasIdleConnector = TRUE;
  10739. break;
  10740. }
  10741. }
  10742. if(isHasIdleConnector == TRUE)
  10743. {
  10744. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10745. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10746. {
  10747. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10748. {
  10749. // Save profile to file
  10750. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  10751. system(cmdBuf);
  10752. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  10753. fp = fopen(cmdBuf, "w");
  10754. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10755. fclose(fp);
  10756. refreshStartTimer(&clientTime.RemoteStartWait);
  10757. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  10758. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10759. }
  10760. else
  10761. {
  10762. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10763. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10764. }
  10765. }
  10766. }
  10767. else
  10768. {
  10769. DEBUG_INFO("There is not any connector is idle.\n");
  10770. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10771. }
  10772. }
  10773. }
  10774. else
  10775. {
  10776. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10777. }
  10778. end:
  10779. json_object_put(RemoteStartTransaction);
  10780. sendRemoteStartConfirmation(uuid, comfirmstr);
  10781. return result;
  10782. }
  10783. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10784. {
  10785. mtrace();
  10786. int result = FAIL;
  10787. int match = FALSE;
  10788. int GunNO = 0;
  10789. int tempIndex = 0;
  10790. int transactionIdInt=0;
  10791. int transactionIdIsNULL= TRUE;
  10792. char comfirmstr[20];
  10793. json_object *RemoteStopTransaction;
  10794. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10795. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10796. if(server_pending == TRUE)
  10797. {
  10798. return 0;
  10799. }
  10800. RemoteStopTransaction = json_tokener_parse(payload);
  10801. if(!is_error(RemoteStopTransaction))
  10802. {
  10803. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10804. {
  10805. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10806. transactionIdIsNULL = FALSE;
  10807. }
  10808. }
  10809. json_object_put(RemoteStopTransaction);
  10810. if(transactionIdIsNULL == FALSE)
  10811. {
  10812. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10813. {
  10814. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10815. {
  10816. //check Transaction active
  10817. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10818. {
  10819. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10820. {
  10821. tempIndex = ((gun_index==2) ? 1: 0);
  10822. }
  10823. else
  10824. {
  10825. tempIndex = gun_index;
  10826. }
  10827. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10828. {
  10829. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10830. {
  10831. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10832. {
  10833. match = TRUE;
  10834. GunNO = gun_index;
  10835. }
  10836. }
  10837. }// END FOR CHAdeMO_QUANTITY
  10838. }
  10839. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10840. {
  10841. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10842. {
  10843. tempIndex = ((gun_index==2) ? 1: 0);
  10844. }
  10845. else
  10846. {
  10847. tempIndex = gun_index;
  10848. }
  10849. for (int index = 0; index < CCS_QUANTITY; index++)
  10850. {
  10851. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10852. {
  10853. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10854. {
  10855. match = TRUE;
  10856. GunNO = gun_index;
  10857. }
  10858. }
  10859. }// END FOR CCS_QUANTITY
  10860. }
  10861. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10862. {
  10863. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10864. {
  10865. tempIndex = ((gun_index==2) ? 1: 0);
  10866. }
  10867. else
  10868. {
  10869. tempIndex = gun_index;
  10870. }
  10871. for (int index = 0; index < GB_QUANTITY; index++)
  10872. {
  10873. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10874. {
  10875. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10876. {
  10877. match = TRUE;
  10878. GunNO = gun_index;
  10879. }
  10880. }
  10881. }// END FOR GB_QUANTITY
  10882. }
  10883. else if(gunType[gun_index] == GUN_TYPE_DO)
  10884. {
  10885. tempIndex = gun_index;
  10886. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10887. {
  10888. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10889. {
  10890. 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
  10891. {
  10892. match = TRUE;
  10893. GunNO = gun_index;
  10894. }
  10895. }
  10896. }// END FOR GB_QUANTITY
  10897. }
  10898. else
  10899. {
  10900. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10901. {
  10902. tempIndex = 2;
  10903. }
  10904. else
  10905. {
  10906. tempIndex = gun_index;
  10907. }
  10908. for (int index = 0; index < AC_QUANTITY; index++)
  10909. {
  10910. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10911. {
  10912. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10913. {
  10914. match = TRUE;
  10915. GunNO = gun_index;
  10916. }
  10917. }
  10918. }// END FOR CHAdeMO_QUANTITY
  10919. } // END FOR AC ELSE
  10920. }// CHECK IF ResponseTransactionId == transactionIdInt
  10921. }//END FOR
  10922. if( match == TRUE)
  10923. {
  10924. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  10925. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10926. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  10927. }
  10928. else
  10929. {
  10930. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10931. }
  10932. }
  10933. else
  10934. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10935. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  10936. return result;
  10937. }
  10938. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  10939. {
  10940. mtrace();
  10941. int result = FAIL;
  10942. int connectorIdInt=0, reservationIdInt=0;
  10943. int tempIndex = 0;
  10944. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  10945. char comfirmstr[20]={0};
  10946. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  10947. int c = 0;
  10948. char *loc;
  10949. //char *ptr;
  10950. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  10951. strcpy(sstrtemp, stringtrimspace(payload));
  10952. //***(1)connectorId ****/
  10953. c=0;
  10954. loc = strstr(sstrtemp, "connectorId");
  10955. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10956. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  10957. {
  10958. sstr[c] = loc[strlen("connectorId")+2+c];
  10959. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10960. c++;
  10961. }
  10962. sstr[c] = '\0';
  10963. connectorIdInt = atoi(sstr);
  10964. //***(2)expiryDate ****/
  10965. loc = strstr(sstrtemp, "expiryDate");
  10966. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10967. c = 0;
  10968. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  10969. {
  10970. sstr[c] = loc[3+strlen("expiryDate")+c];
  10971. c++;
  10972. }
  10973. sstr[c] = '\0';
  10974. strcpy(expiryDatestr, sstr);
  10975. //***(3)idTag ****/
  10976. loc = strstr(sstrtemp, "idTag");
  10977. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10978. c = 0;
  10979. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  10980. {
  10981. sstr[c] = loc[3+strlen("idTag")+c];
  10982. c++;
  10983. }
  10984. sstr[c] = '\0';
  10985. strcpy(idTagstr, sstr);
  10986. //***(4)parentIdTag ****/
  10987. loc = strstr(sstrtemp, "parentIdTag");
  10988. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10989. c = 0;
  10990. if(loc == NULL)
  10991. {
  10992. strcpy(parentIdTagstr, "");
  10993. }
  10994. else
  10995. {
  10996. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  10997. {
  10998. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10999. c++;
  11000. }
  11001. sstr[c] = '\0';
  11002. strcpy(parentIdTagstr, sstr);
  11003. }
  11004. //***(5)reservationId ****/
  11005. c=0;
  11006. loc = strstr(sstrtemp, "reservationId");
  11007. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11008. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11009. {
  11010. sstr[c] = loc[strlen("reservationId")+2+c];
  11011. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11012. c++;
  11013. }
  11014. sstr[c] = '\0';
  11015. reservationIdInt = atoi(sstr);
  11016. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11017. /*
  11018. enum SYSTEM_STATUS
  11019. {
  11020. SYS_MODE_BOOTING = 0,
  11021. SYS_MODE_IDLE = 1,
  11022. SYS_MODE_AUTHORIZING = 2,
  11023. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11024. SYS_MODE_REASSIGN = 4,
  11025. SYS_MODE_PREPARING = 5,
  11026. SYS_MODE_PREPARE_FOR_EV = 6,
  11027. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11028. SYS_MODE_CHARGING = 8,
  11029. SYS_MODE_TERMINATING = 9,
  11030. SYS_MODE_COMPLETE = 10,
  11031. SYS_MODE_ALARM = 11,
  11032. SYS_MODE_FAULT = 12,
  11033. SYS_MODE_RESERVATION = 13,
  11034. SYS_MODE_BOOKING = 14,
  11035. SYS_MODE_MAINTAIN = 15,
  11036. SYS_MODE_DEBUG = 16,
  11037. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11038. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11039. SYS_MODE_UPDATE = 19
  11040. };
  11041. */
  11042. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11043. {
  11044. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11045. goto end;
  11046. }
  11047. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11048. {
  11049. //check Transaction active
  11050. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11051. {
  11052. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11053. {
  11054. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11055. }
  11056. else
  11057. {
  11058. tempIndex = connectorIdInt -1;
  11059. }
  11060. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11061. {
  11062. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11063. {
  11064. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11065. {
  11066. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11067. {
  11068. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11069. {
  11070. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11071. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11072. }
  11073. 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'))
  11074. {
  11075. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11076. }
  11077. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11078. {
  11079. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11080. }
  11081. else
  11082. {
  11083. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11084. }
  11085. }
  11086. 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
  11087. {
  11088. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11089. }
  11090. }
  11091. else
  11092. {
  11093. //replace reservation
  11094. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11095. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11096. }
  11097. }
  11098. } // END FOR CHAdeMO_QUANTITY
  11099. }
  11100. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11101. {
  11102. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11103. {
  11104. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11105. }
  11106. else
  11107. {
  11108. tempIndex = connectorIdInt -1;
  11109. }
  11110. for (int index = 0; index < CCS_QUANTITY; index++)
  11111. {
  11112. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11113. {
  11114. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11115. {
  11116. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11117. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11118. {
  11119. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11120. {
  11121. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11122. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11123. }
  11124. 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'))
  11125. {
  11126. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11127. }
  11128. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11129. {
  11130. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11131. }
  11132. else
  11133. {
  11134. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11135. }
  11136. }
  11137. 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
  11138. {
  11139. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11140. }
  11141. }
  11142. else
  11143. {
  11144. //replace reservation
  11145. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11146. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11147. }
  11148. }
  11149. } // END FOR CCS_QUANTITY
  11150. }
  11151. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11152. {
  11153. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11154. {
  11155. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11156. }
  11157. else
  11158. {
  11159. tempIndex = connectorIdInt -1;
  11160. }
  11161. for (int index = 0; index < GB_QUANTITY; index++)
  11162. {
  11163. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11164. {
  11165. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11166. {
  11167. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11168. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11169. {
  11170. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11171. {
  11172. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11173. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11174. }
  11175. 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'))
  11176. {
  11177. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11178. }
  11179. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11180. {
  11181. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11182. }
  11183. else
  11184. {
  11185. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11186. }
  11187. }
  11188. 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
  11189. {
  11190. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11191. }
  11192. }
  11193. else
  11194. {
  11195. //replace reservation
  11196. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11197. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11198. }
  11199. }
  11200. }// END FOR GB_QUANTITY
  11201. }
  11202. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11203. {
  11204. tempIndex = connectorIdInt -1;
  11205. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11206. {
  11207. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11208. {
  11209. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11210. {
  11211. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11212. 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
  11213. {
  11214. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11215. {
  11216. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11217. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11218. }
  11219. 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'))
  11220. {
  11221. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11222. }
  11223. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11224. {
  11225. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11226. }
  11227. else
  11228. {
  11229. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11230. }
  11231. }
  11232. 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
  11233. {
  11234. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11235. }
  11236. }
  11237. else
  11238. {
  11239. //replace reservation
  11240. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11241. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11242. }
  11243. }
  11244. }// END FOR GB_QUANTITY
  11245. }
  11246. else
  11247. {
  11248. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11249. {
  11250. tempIndex = 2;
  11251. }
  11252. else
  11253. {
  11254. tempIndex = (connectorIdInt -1);
  11255. }
  11256. for (int index = 0; index < AC_QUANTITY; index++)
  11257. {
  11258. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11259. {
  11260. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11261. {
  11262. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11263. {
  11264. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11265. {
  11266. 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))
  11267. {
  11268. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11269. }
  11270. else
  11271. {
  11272. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11273. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11274. }
  11275. }
  11276. 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'))
  11277. {
  11278. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11279. }
  11280. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11281. {
  11282. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11283. }
  11284. else
  11285. {
  11286. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11287. }
  11288. }
  11289. 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
  11290. {
  11291. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11292. }
  11293. }
  11294. else
  11295. {
  11296. //replace reservation
  11297. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11298. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11299. }
  11300. }
  11301. } // END FOR AC_QUANTITY
  11302. }
  11303. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11304. }
  11305. else if(connectorIdInt == 0)
  11306. {
  11307. //check Transaction active
  11308. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11309. {
  11310. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11311. {
  11312. 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'))
  11313. {
  11314. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11315. goto end;
  11316. }
  11317. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11318. {
  11319. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11320. goto end;
  11321. }
  11322. 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
  11323. {
  11324. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11325. goto end;
  11326. }
  11327. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11328. {
  11329. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11330. goto end;
  11331. }
  11332. }
  11333. }// END FOR CHAdeMO_QUANTITY
  11334. for (int index = 0; index < CCS_QUANTITY; index++)
  11335. {
  11336. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11337. {
  11338. 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'))
  11339. {
  11340. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11341. goto end;
  11342. }
  11343. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11344. {
  11345. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11346. goto end;
  11347. }
  11348. 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
  11349. {
  11350. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11351. goto end;
  11352. }
  11353. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11354. {
  11355. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11356. goto end;
  11357. }
  11358. }
  11359. } // END FOR CCS_QUANTITY
  11360. for (int index = 0; index < GB_QUANTITY; index++)
  11361. {
  11362. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11363. {
  11364. 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'))
  11365. {
  11366. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11367. goto end;
  11368. }
  11369. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11370. {
  11371. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11372. goto end;
  11373. }
  11374. 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
  11375. {
  11376. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11377. goto end;
  11378. }
  11379. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11380. {
  11381. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11382. goto end;
  11383. }
  11384. }
  11385. } // END FOR GB_QUANTITY
  11386. for (int index = 0; index < AC_QUANTITY; index++)
  11387. {
  11388. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11389. {
  11390. 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'))
  11391. {
  11392. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11393. goto end;
  11394. }
  11395. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11396. {
  11397. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11398. goto end;
  11399. }
  11400. 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
  11401. {
  11402. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11403. goto end;
  11404. }
  11405. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11406. {
  11407. 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))
  11408. {
  11409. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11410. goto end;
  11411. }
  11412. }
  11413. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11414. {
  11415. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11416. goto end;
  11417. }
  11418. }
  11419. }// END FOR AC_QUANTITY
  11420. //The connectorId is 0
  11421. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  11422. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11423. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11424. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  11425. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11426. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  11427. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11428. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  11429. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  11430. result = TRUE;
  11431. return result;
  11432. }
  11433. else
  11434. {
  11435. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11436. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11437. }
  11438. if(strcmp(comfirmstr,"Accepted") == 0)
  11439. {
  11440. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11441. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11442. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11443. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11444. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11445. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  11446. result = TRUE;
  11447. return result;
  11448. }
  11449. end:
  11450. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11451. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11452. return result;
  11453. }
  11454. int handleResetRequest(char *uuid, char *payload)
  11455. {
  11456. mtrace();
  11457. int result = FAIL;
  11458. char sstr[10]={0},sstrtemp[30]={ 0 };
  11459. char typestr[10]={0};
  11460. char comfirmstr[20]={0};
  11461. int c = 0;
  11462. char *loc;
  11463. DEBUG_INFO("handleResetRequest...\n");
  11464. strcpy(sstrtemp, stringtrimspace(payload));
  11465. loc = strstr(sstrtemp, "type");
  11466. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11467. c = 0;
  11468. while (loc[3+strlen("type")+c] != '\"')
  11469. {
  11470. sstr[c] = loc[3+strlen("type")+c];
  11471. c++;
  11472. }
  11473. sstr[c] = '\0';
  11474. strcpy(typestr,sstr);
  11475. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11476. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11477. {
  11478. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11479. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  11480. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11481. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11482. }
  11483. else
  11484. {
  11485. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11486. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11487. result = PASS;
  11488. }
  11489. sendResetConfirmation(uuid, comfirmstr);
  11490. return result;
  11491. }
  11492. int handleSendLocalListRequest(char *uuid, char *payload)
  11493. {
  11494. mtrace();
  11495. int result = FAIL;
  11496. char comfirmstr[20];
  11497. int checkState_Faulted = FALSE;
  11498. json_object *SendLocalList;
  11499. DEBUG_INFO("handleSendLocalListRequest...\n");
  11500. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11501. {
  11502. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11503. goto end;
  11504. }
  11505. //check Charge Point state
  11506. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11507. {
  11508. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11509. {
  11510. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11511. }
  11512. }
  11513. for (int index = 0; index < CCS_QUANTITY; index++)
  11514. {
  11515. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11516. {
  11517. checkState_Faulted = TRUE; //OCPP Status
  11518. }
  11519. }
  11520. for (int index = 0; index < GB_QUANTITY; index++)
  11521. {
  11522. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11523. {
  11524. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11525. }
  11526. }
  11527. //check Charge Point state
  11528. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11529. {
  11530. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11531. {
  11532. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11533. }
  11534. }
  11535. //check Charge Point state
  11536. for (int index = 0; index < AC_QUANTITY; index++)
  11537. {
  11538. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11539. {
  11540. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11541. }
  11542. }
  11543. if(checkState_Faulted == TRUE)
  11544. {
  11545. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11546. goto end;
  11547. }
  11548. // Parsing payload
  11549. SendLocalList = json_tokener_parse(payload);
  11550. if(!is_error(SendLocalList))
  11551. {
  11552. // Required data
  11553. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11554. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11555. // Optional data
  11556. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11557. {
  11558. //Check UpdateType
  11559. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11560. {
  11561. //Local list full update
  11562. DEBUG_INFO("Local list full update.\n");
  11563. OCPP_getListVerion();
  11564. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11565. {
  11566. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11567. goto end;
  11568. }
  11569. OCPP_cleanLocalList();
  11570. }
  11571. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11572. {
  11573. //Local list different update
  11574. DEBUG_INFO("Local list different update.\n");
  11575. OCPP_getListVerion();
  11576. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11577. {
  11578. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11579. goto end;
  11580. }
  11581. }
  11582. else
  11583. {
  11584. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11585. goto end;
  11586. }
  11587. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11588. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11589. {
  11590. 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")));
  11591. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11592. {
  11593. 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")));
  11594. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11595. 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")));
  11596. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11597. 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")));
  11598. }
  11599. // Add to db
  11600. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11601. {
  11602. //Local list full update
  11603. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11604. idx,
  11605. ShmOCPP16Data->SendLocalList.ListVersion,
  11606. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11607. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11608. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11609. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11610. // update list
  11611. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11612. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11613. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11614. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11615. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11616. }
  11617. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11618. {
  11619. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11620. idx,
  11621. ShmOCPP16Data->SendLocalList.ListVersion,
  11622. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11623. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11624. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11625. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11626. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11627. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11628. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11629. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11630. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11631. }
  11632. }
  11633. }
  11634. else
  11635. {
  11636. //Check UpdateType
  11637. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11638. {
  11639. //Local list full update
  11640. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11641. OCPP_cleanLocalList();
  11642. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11643. goto end;
  11644. }
  11645. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11646. {
  11647. //Local list different update
  11648. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11649. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11650. goto end;
  11651. }
  11652. }
  11653. result = PASS;
  11654. }
  11655. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11656. end:
  11657. json_object_put(SendLocalList);
  11658. sendSendLocalListConfirmation(uuid, comfirmstr);
  11659. return result;
  11660. }
  11661. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11662. {
  11663. mtrace();
  11664. int result = FAIL;
  11665. struct StructSetChargingProfile SetProfileReq = {0};
  11666. int tempchargingProfileIdInt;
  11667. int chargingSchedulePeriodCount = 0;
  11668. char comfirmstr[20]={0};
  11669. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  11670. char rmFileCmd[128]={0};
  11671. int profileQuantity = 0;
  11672. json_object *SetChargingProfile;
  11673. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11674. SetChargingProfile = json_tokener_parse(payload);
  11675. if(!is_error(SetChargingProfile))
  11676. {
  11677. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11678. {
  11679. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11680. }
  11681. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11682. {
  11683. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11684. {
  11685. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11686. }
  11687. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11688. {
  11689. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11690. }
  11691. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11692. {
  11693. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11694. }
  11695. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11696. {
  11697. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11698. }
  11699. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11700. {
  11701. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11702. }
  11703. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11704. {
  11705. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11706. }
  11707. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11708. {
  11709. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11710. }
  11711. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11712. {
  11713. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11714. }
  11715. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11716. {
  11717. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11718. {
  11719. 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")));
  11720. }
  11721. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11722. {
  11723. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11724. }
  11725. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11726. {
  11727. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11728. }
  11729. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11730. {
  11731. 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")));
  11732. }
  11733. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11734. {
  11735. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11736. if(chargingSchedulePeriodCount <= 10)
  11737. {
  11738. 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++)
  11739. {
  11740. 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)
  11741. {
  11742. 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"));
  11743. }
  11744. 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)
  11745. {
  11746. 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"));
  11747. }
  11748. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  11749. {
  11750. 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"));
  11751. }
  11752. }
  11753. }
  11754. }
  11755. }
  11756. }
  11757. }
  11758. // Profile periods quantity check
  11759. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11760. {
  11761. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11762. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11763. goto end;
  11764. }
  11765. // Check invalid limit
  11766. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11767. {
  11768. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11769. {
  11770. 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)))) ||
  11771. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11772. {
  11773. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11774. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11775. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11776. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11777. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11778. goto end;
  11779. }
  11780. }
  11781. }
  11782. else
  11783. {
  11784. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11785. {
  11786. if((SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:modelnameInfo.ParsingInfo[0].Current)))
  11787. {
  11788. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11789. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11790. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11791. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11792. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11793. goto end;
  11794. }
  11795. }
  11796. }
  11797. // Profile purpose info check
  11798. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11799. {
  11800. FILE *fp;
  11801. char dataLine[4096]={0};
  11802. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11803. if(SetProfileReq.ConnectorId != 0)
  11804. {
  11805. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11806. DEBUG_WARN("Profile connector id is not 0.\n");
  11807. goto end;
  11808. }
  11809. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11810. if (!fp)
  11811. {
  11812. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11813. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11814. }
  11815. else
  11816. {
  11817. while(fscanf(fp, "%s", dataLine) != EOF)
  11818. {
  11819. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11820. {
  11821. profileQuantity += 1;
  11822. }
  11823. }
  11824. }
  11825. fclose(fp);
  11826. }
  11827. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11828. {
  11829. FILE *fp;
  11830. char dataLine[4096]={0};
  11831. char filename[128]={0};
  11832. int tmpProfileQuantity;
  11833. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11834. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11835. {
  11836. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11837. DEBUG_WARN("Profile connector id is over max gun number.\n");
  11838. goto end;
  11839. }
  11840. if(SetProfileReq.ConnectorId == 0)
  11841. {
  11842. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  11843. {
  11844. tmpProfileQuantity = 0;
  11845. memset(filename, 0, ARRAY_SIZE(filename));
  11846. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  11847. fp = fopen(filename, "r");
  11848. if (!fp)
  11849. {
  11850. DEBUG_INFO("%s does not create.\n", filename);
  11851. fp = fopen(filename, "w+");
  11852. }
  11853. else
  11854. {
  11855. while(fscanf(fp, "%s", dataLine) != EOF)
  11856. {
  11857. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11858. {
  11859. tmpProfileQuantity += 1;
  11860. }
  11861. }
  11862. }
  11863. fclose(fp);
  11864. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  11865. }
  11866. }
  11867. else
  11868. {
  11869. memset(filename, 0, ARRAY_SIZE(filename));
  11870. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11871. fp = fopen(filename, "r");
  11872. if (!fp)
  11873. {
  11874. DEBUG_INFO("%s does not create.\n", filename);
  11875. fp = fopen(filename, "w+");
  11876. }
  11877. else
  11878. {
  11879. while(fscanf(fp, "%s", dataLine) != EOF)
  11880. {
  11881. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11882. {
  11883. profileQuantity += 1;
  11884. }
  11885. }
  11886. }
  11887. fclose(fp);
  11888. }
  11889. }
  11890. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11891. {
  11892. int isMatchTransactiodId= FALSE;
  11893. FILE *fp;
  11894. char dataLine[4096]={0};
  11895. char filename[128]={0};
  11896. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  11897. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  11898. if(SetProfileReq.ConnectorId == 0)
  11899. {
  11900. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11901. DEBUG_WARN("Profile connector id is 0.\n");
  11902. goto end;
  11903. }
  11904. int tempIndex = 0;
  11905. //check Transaction active
  11906. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  11907. {
  11908. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11909. {
  11910. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11911. }
  11912. else
  11913. {
  11914. tempIndex = SetProfileReq.ConnectorId -1;
  11915. }
  11916. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11917. {
  11918. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11919. {
  11920. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11921. {
  11922. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11923. {
  11924. isMatchTransactiodId = TRUE;
  11925. break;
  11926. }
  11927. }
  11928. }
  11929. }
  11930. }
  11931. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  11932. {
  11933. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11934. {
  11935. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11936. }
  11937. else
  11938. {
  11939. tempIndex = SetProfileReq.ConnectorId -1;
  11940. }
  11941. for (int index = 0; index < CCS_QUANTITY; index++)
  11942. {
  11943. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11944. {
  11945. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  11946. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11947. {
  11948. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11949. {
  11950. isMatchTransactiodId = TRUE;
  11951. break;
  11952. }
  11953. }
  11954. }
  11955. }
  11956. }
  11957. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  11958. {
  11959. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11960. {
  11961. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11962. }
  11963. else
  11964. {
  11965. tempIndex = SetProfileReq.ConnectorId -1;
  11966. }
  11967. for (int index = 0; index < GB_QUANTITY; index++)
  11968. {
  11969. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11970. {
  11971. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11972. {
  11973. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11974. {
  11975. isMatchTransactiodId = TRUE;
  11976. break;
  11977. }
  11978. }
  11979. }
  11980. }
  11981. }
  11982. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  11983. {
  11984. tempIndex = SetProfileReq.ConnectorId -1;
  11985. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11986. {
  11987. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11988. {
  11989. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  11990. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11991. {
  11992. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11993. {
  11994. isMatchTransactiodId = TRUE;
  11995. break;
  11996. }
  11997. }
  11998. }
  11999. }
  12000. }
  12001. else
  12002. {
  12003. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12004. {
  12005. tempIndex = 2;
  12006. }
  12007. else
  12008. {
  12009. tempIndex = (SetProfileReq.ConnectorId -1);
  12010. }
  12011. for (int index = 0; index < AC_QUANTITY; index++)
  12012. {
  12013. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12014. {
  12015. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12016. {
  12017. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12018. {
  12019. isMatchTransactiodId = TRUE;
  12020. break;
  12021. }
  12022. }
  12023. }
  12024. }
  12025. }
  12026. //check Transaction active
  12027. if(isMatchTransactiodId == FALSE)
  12028. {
  12029. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12030. DEBUG_WARN("Tx profile transaction id is not match.\n");
  12031. goto end;
  12032. }
  12033. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12034. {
  12035. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12036. DEBUG_WARN("Connector id is over max gun number.\n");
  12037. goto end;
  12038. }
  12039. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12040. fp = fopen(filename, "r");
  12041. if (!fp)
  12042. {
  12043. DEBUG_INFO("%s does not create.\n", filename);
  12044. fp = fopen(filename, "w+");
  12045. }
  12046. else
  12047. {
  12048. //Check Charging Profile Count
  12049. while(fscanf(fp, "%s", dataLine) != EOF)
  12050. {
  12051. //DEBUG_INFO("word=%s\n",word);
  12052. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12053. {
  12054. profileQuantity += 1;
  12055. }
  12056. }
  12057. }
  12058. fclose(fp);
  12059. }
  12060. // Check ChargeProfileMaxStackLevel
  12061. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12062. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12063. {
  12064. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12065. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12066. goto end;
  12067. }
  12068. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12069. {
  12070. FILE *fp;
  12071. char dataLine[4096]={0};
  12072. char fnametemp[128]={0};
  12073. int tmpProfileQuantity;
  12074. //Check ChargePointMaxProfile.json exit
  12075. profileQuantity = 0;
  12076. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12077. {
  12078. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  12079. //Check Charging Profile Count
  12080. tmpProfileQuantity = 0;
  12081. while(fscanf(fp, "%s", dataLine) != EOF)
  12082. {
  12083. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12084. {
  12085. profileQuantity += 1;
  12086. tmpProfileQuantity += 1;
  12087. }
  12088. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12089. }
  12090. fclose(fp);
  12091. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12092. }
  12093. //Check TxDefaultProfile_%d.json
  12094. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12095. {
  12096. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12097. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12098. if((access(fnametemp,F_OK))!=-1)
  12099. {
  12100. fp = fopen(fnametemp, "r");
  12101. //Check Charging Profile Count
  12102. tmpProfileQuantity = 0;
  12103. while(fscanf(fp, "%s", dataLine) != EOF)
  12104. {
  12105. //DEBUG_INFO("word=%s\n",word);
  12106. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12107. {
  12108. profileQuantity += 1;
  12109. tmpProfileQuantity += 1;
  12110. }
  12111. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12112. }
  12113. fclose(fp);
  12114. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12115. }
  12116. }
  12117. //Check TxProfile_%d.json
  12118. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12119. {
  12120. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12121. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  12122. if((access(fnametemp,F_OK))!=-1)
  12123. {
  12124. fp = fopen(fnametemp, "r");
  12125. //Check Charging Profile Count
  12126. tmpProfileQuantity = 0;
  12127. while(fscanf(fp, "%s", dataLine) != EOF)
  12128. {
  12129. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12130. {
  12131. profileQuantity += 1;
  12132. tmpProfileQuantity += 1;
  12133. }
  12134. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12135. }
  12136. fclose(fp);
  12137. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12138. }
  12139. }
  12140. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12141. if(profileQuantity > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12142. {
  12143. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12144. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12145. goto end;
  12146. }
  12147. }
  12148. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12149. //**********************************Write to File********************************************************/
  12150. {
  12151. FILE *infile;
  12152. FILE *outfile;
  12153. char dataLine[4096]={0};
  12154. char filename[128]={0};
  12155. int chkChar=0;
  12156. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12157. {
  12158. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12159. {
  12160. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12161. }
  12162. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12163. {
  12164. if(SetProfileReq.ConnectorId==0)
  12165. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12166. else
  12167. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12168. }
  12169. else
  12170. {
  12171. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12172. }
  12173. infile = fopen (filename, "r");
  12174. outfile = fopen (tempfile, "w");
  12175. chkChar = fgetc(infile);
  12176. rewind(infile);
  12177. if(chkChar == EOF)
  12178. {
  12179. // Profile is empty
  12180. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12181. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12182. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12183. fclose(infile);
  12184. fclose(outfile);
  12185. sprintf(rmFileCmd,"rm -f %s",filename);
  12186. system(rmFileCmd);
  12187. rename(tempfile, filename);
  12188. }
  12189. else
  12190. {
  12191. // Profile is not empty
  12192. int ChargingProfileAdded = FALSE;
  12193. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12194. {
  12195. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12196. json_object *tmpChargingProfile;
  12197. tmpChargingProfile = json_tokener_parse(dataLine);
  12198. if(!is_error(SetChargingProfile))
  12199. {
  12200. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12201. {
  12202. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12203. {
  12204. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12205. }
  12206. }
  12207. }
  12208. json_object_put(tmpChargingProfile);
  12209. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12210. {
  12211. if(ChargingProfileAdded == FALSE)
  12212. {
  12213. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12214. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12215. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12216. ChargingProfileAdded = TRUE;
  12217. }
  12218. }
  12219. else
  12220. {
  12221. fprintf(outfile,"%s\n",dataLine);
  12222. if(ChargingProfileAdded == FALSE)
  12223. {
  12224. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12225. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12226. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12227. ChargingProfileAdded = TRUE;
  12228. }
  12229. }
  12230. } // end of while loop
  12231. fclose(infile);
  12232. fclose(outfile);
  12233. sprintf(rmFileCmd,"rm -f %s",filename);
  12234. system(rmFileCmd);
  12235. rename(tempfile, filename);
  12236. }
  12237. }
  12238. sleep(1);
  12239. result = TRUE;
  12240. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12241. }
  12242. end:
  12243. json_object_put(SetChargingProfile);
  12244. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12245. {
  12246. if(SetProfileReq.ConnectorId == 0)
  12247. {
  12248. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12249. {
  12250. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  12251. }
  12252. }
  12253. else
  12254. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12255. }
  12256. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12257. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12258. return result;
  12259. }
  12260. int handleTriggerMessageRequest(char *uuid, char *payload)
  12261. {
  12262. mtrace();
  12263. int result = FAIL;
  12264. int connectorIdIsNULL = FALSE;
  12265. int connectorIdInt =0;
  12266. char sstr[40]={0},sstrtemp[100]={ 0 };
  12267. char requestedMessagestr[40]={0};
  12268. char comfirmstr[20]={0};
  12269. int c = 0;
  12270. char *loc;
  12271. DEBUG_INFO("handleTriggerMessageRequest\n");
  12272. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12273. strcpy(sstrtemp, stringtrimspace(payload));
  12274. c = 0;
  12275. loc = strstr(sstrtemp, "requestedMessage");
  12276. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12277. {
  12278. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12279. c++;
  12280. }
  12281. sstr[c] = '\0';
  12282. strcpy(requestedMessagestr, sstr);
  12283. c = 0;
  12284. loc = strstr(sstrtemp, "connectorId");
  12285. if(loc == NULL)
  12286. {
  12287. connectorIdIsNULL = TRUE;
  12288. }
  12289. else
  12290. {
  12291. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12292. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12293. {
  12294. sstr[c] = loc[strlen("connectorId")+2+c];
  12295. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12296. c++;
  12297. }
  12298. sstr[c] = '\0';
  12299. connectorIdInt = atoi(sstr);
  12300. }
  12301. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12302. {
  12303. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12304. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12305. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12306. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12307. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12308. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12309. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12310. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12311. {
  12312. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12313. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12314. return TRUE;
  12315. }
  12316. else
  12317. {
  12318. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12319. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12320. }
  12321. }
  12322. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12323. {
  12324. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12325. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12326. return TRUE;
  12327. }
  12328. //==========================
  12329. // Trigger message
  12330. //==========================
  12331. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12332. {
  12333. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12334. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12335. {
  12336. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12337. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12338. }
  12339. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12340. }
  12341. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12342. {
  12343. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  12344. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12345. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12346. }
  12347. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12348. {
  12349. //sendBootNotificationRequest();
  12350. server_sign = FALSE;
  12351. }
  12352. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12353. {
  12354. refreshStartTimer(&clientTime.Heartbeat);
  12355. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  12356. }
  12357. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12358. {
  12359. if(connectorIdIsNULL == FALSE)
  12360. {
  12361. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12362. {
  12363. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12364. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12365. }
  12366. }
  12367. else
  12368. {
  12369. for(int idx=0;idx< gunTotalNumber;idx++)
  12370. {
  12371. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12372. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12373. }
  12374. }
  12375. }
  12376. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12377. {
  12378. if(connectorIdIsNULL == FALSE)
  12379. {
  12380. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  12381. {
  12382. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12383. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  12384. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12385. }
  12386. }
  12387. else
  12388. {
  12389. for(int idx=0;idx< gunTotalNumber;idx++)
  12390. {
  12391. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  12392. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12393. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12394. }
  12395. }
  12396. }
  12397. return result;
  12398. }
  12399. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12400. {
  12401. mtrace();
  12402. int result = FAIL;
  12403. int connectorIdInt =0;
  12404. char comfirmstr[20]={0};
  12405. int tempIndex = 0;
  12406. json_object *UnlockConnector;
  12407. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12408. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12409. UnlockConnector = json_tokener_parse(payload);
  12410. if(!is_error(UnlockConnector))
  12411. {
  12412. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12413. {
  12414. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12415. }
  12416. }
  12417. json_object_put(UnlockConnector);
  12418. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12419. if(gunTotalNumber == 0)
  12420. {
  12421. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12422. goto end;
  12423. }
  12424. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12425. {
  12426. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12427. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12428. goto end;
  12429. }
  12430. else
  12431. {
  12432. //check Transaction active
  12433. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12434. {
  12435. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12436. {
  12437. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12438. }
  12439. else
  12440. {
  12441. tempIndex = connectorIdInt -1;
  12442. }
  12443. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12444. {
  12445. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12446. {
  12447. //stop Transaction
  12448. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12449. }
  12450. }
  12451. }
  12452. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12453. {
  12454. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12455. {
  12456. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12457. }
  12458. else
  12459. {
  12460. tempIndex = connectorIdInt -1;
  12461. }
  12462. for (int index = 0; index < CCS_QUANTITY; index++)
  12463. {
  12464. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12465. {
  12466. //stop Transaction
  12467. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12468. }
  12469. }
  12470. }
  12471. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12472. {
  12473. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12474. {
  12475. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12476. }
  12477. else
  12478. {
  12479. tempIndex = connectorIdInt -1;
  12480. }
  12481. for (int index = 0; index < GB_QUANTITY; index++)
  12482. {
  12483. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12484. {
  12485. //stop Transaction
  12486. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12487. }
  12488. }
  12489. }
  12490. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12491. {
  12492. tempIndex = connectorIdInt -1;
  12493. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12494. {
  12495. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12496. {
  12497. //stop Transaction
  12498. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12499. }
  12500. }
  12501. }
  12502. else
  12503. {
  12504. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12505. {
  12506. tempIndex = 2;
  12507. }
  12508. else
  12509. {
  12510. tempIndex = connectorIdInt-1;
  12511. }
  12512. for (int index = 0; index < AC_QUANTITY; index++)
  12513. {
  12514. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12515. {
  12516. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12517. }
  12518. }
  12519. }
  12520. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12521. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  12522. result = TRUE;
  12523. return result;
  12524. }
  12525. end:
  12526. //json_object_put(obj); --- remove temporally
  12527. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12528. return result;
  12529. }
  12530. static char UpdateFirmwarepayloadData[300]={0};
  12531. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12532. {
  12533. mtrace();
  12534. int result = FAIL;
  12535. pthread_t t;
  12536. sendUpdateFirmwareConfirmation(uuid);
  12537. memset(UpdateFirmwarepayloadData, 0, 300);
  12538. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12539. if(!interLock.isUpdateFirmwareGoing)
  12540. {
  12541. interLock.isUpdateFirmwareGoing = 1;
  12542. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12543. sleep(1);
  12544. }
  12545. else
  12546. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12547. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  12548. return result;
  12549. }
  12550. void *UpdateFirmwareProcess(void *data)
  12551. {
  12552. pthread_detach(pthread_self());
  12553. mtrace();
  12554. int retriesInt =0, retryIntervalInt=0;
  12555. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  12556. int port=0;
  12557. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  12558. int isSuccess = 0;
  12559. char ftpbuf[1024];
  12560. char temp[1024];
  12561. char * pch;
  12562. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12563. json_object *UpdateFirmware;
  12564. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12565. if(!is_error(UpdateFirmware))
  12566. {
  12567. // Required data
  12568. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12569. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12570. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12571. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12572. // Optional data
  12573. if(json_object_object_get(UpdateFirmware, "retries"))
  12574. {
  12575. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12576. }
  12577. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12578. {
  12579. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12580. }
  12581. }
  12582. json_object_put(UpdateFirmware);
  12583. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12584. memset(path, 0, ARRAY_SIZE(path));
  12585. // Wait retrieveData
  12586. if(strlen(retrieveDatestr) > 10)
  12587. {
  12588. do
  12589. {
  12590. sleep(1);
  12591. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12592. }
  12593. // Ready to download
  12594. system("rm -f /mnt/*");
  12595. if(strncmp(locationstr,"http", 4) == 0)
  12596. {
  12597. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12598. sprintf(ftppath,"/%s", path);
  12599. DEBUG_INFO("locationstr: %s\n", locationstr);
  12600. DEBUG_INFO("protocol: %s\n",protocol);
  12601. DEBUG_INFO("host: %s\n",host);
  12602. DEBUG_INFO("path: %s\n",path);
  12603. DEBUG_INFO("ftppath: %s\n",ftppath);
  12604. int ftppathlen=strlen(ftppath);
  12605. int i=1;
  12606. char filenametemp[50];
  12607. while(i < ftppathlen)
  12608. {
  12609. int len=ftppathlen-i;
  12610. if(ftppath[len]== 47) // '/' ascll code: 47
  12611. {
  12612. DEBUG_INFO("compare '/' all right\n");
  12613. break;
  12614. }
  12615. i=i+1;
  12616. }
  12617. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12618. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12619. filenametemp[i+1] = 0;
  12620. do
  12621. {
  12622. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12623. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12624. sleep(1);
  12625. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12626. if(!isSuccess)
  12627. {
  12628. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12629. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12630. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12631. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12632. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12633. }
  12634. else
  12635. {
  12636. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12637. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12638. }
  12639. retriesInt--;
  12640. }while((isSuccess == 0)&&(retriesInt >= 0));
  12641. }
  12642. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12643. {
  12644. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12645. memset(temp, 0, ARRAY_SIZE(temp));
  12646. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12647. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12648. int ftppathlen=strlen(ftpbuf);
  12649. int i=1;
  12650. char filenametemp[50];
  12651. while(i < ftppathlen)
  12652. {
  12653. int len=ftppathlen-i;
  12654. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12655. {
  12656. DEBUG_INFO(" compare '/' all right\n");
  12657. break;
  12658. }
  12659. i=i+1;
  12660. }
  12661. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12662. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12663. filenametemp[i+1] = 0;
  12664. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12665. pch=strchr(temp,'@');
  12666. if(pch==NULL)
  12667. {
  12668. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12669. protocol, host, &port, path);
  12670. strcpy(user,"anonymous");
  12671. strcpy(password,"");
  12672. }
  12673. else
  12674. {
  12675. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12676. protocol, user, password, host, &port, path);
  12677. }
  12678. sscanf(host,"%[^/]%s",host1, path1);
  12679. sprintf(ftppath,"%s", path1);
  12680. //DEBUG_INFO("protocol =%s\n",protocol);
  12681. //DEBUG_INFO("user =%s\n",user);
  12682. //DEBUG_INFO("password =%s\n",password);
  12683. //DEBUG_INFO("host1 =%s\n",host1);
  12684. //DEBUG_INFO("port =%d\n",port);
  12685. //DEBUG_INFO("path1 =%s\n",path1);
  12686. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12687. //ftpFile(host, user, password, port, ftppath, fname);
  12688. //download firmware pthred
  12689. if(port == 0)
  12690. {
  12691. port = 21;
  12692. }
  12693. do
  12694. {
  12695. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12696. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12697. sleep(1);
  12698. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12699. if(!isSuccess)
  12700. {
  12701. //BulldogUtil.sleepMs(interval*1000);
  12702. DEBUG_INFO("Update firmware request and download file fail.\n");
  12703. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12704. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12705. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12706. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12707. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12708. }
  12709. else
  12710. {
  12711. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12712. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12713. }
  12714. retriesInt--;
  12715. }while((!isSuccess)&&(retriesInt >= 0));
  12716. }
  12717. else
  12718. {
  12719. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12720. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12721. sleep(1);
  12722. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12723. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12724. }
  12725. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12726. interLock.isUpdateFirmwareGoing = 0;
  12727. pthread_exit(NULL);
  12728. }
  12729. int handleCertificateSignedRequest(char *uuid, char *payload)
  12730. {
  12731. mtrace();
  12732. int result = PASS;
  12733. json_object *CertificateSigned;
  12734. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12735. CertificateSigned = json_tokener_parse(payload);
  12736. if(!is_error(CertificateSigned))
  12737. {
  12738. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  12739. }
  12740. json_object_put(CertificateSigned);
  12741. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  12742. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  12743. fclose(fp);
  12744. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12745. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  12746. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  12747. sendCertificateSignedConfirmation(uuid);
  12748. return result;
  12749. }
  12750. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12751. {
  12752. mtrace();
  12753. int result = PASS;
  12754. json_object *DeleteCertificate;
  12755. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12756. DeleteCertificate = json_tokener_parse(payload);
  12757. if(!is_error(DeleteCertificate))
  12758. {
  12759. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12760. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12761. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12762. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12763. }
  12764. json_object_put(DeleteCertificate);
  12765. /*
  12766. * TODO: Delete certificateSigned process
  12767. */
  12768. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  12769. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  12770. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  12771. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  12772. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  12773. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  12774. sendDeleteCertificateConfirmation(uuid);
  12775. return result;
  12776. }
  12777. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12778. {
  12779. mtrace();
  12780. int result = PASS;
  12781. json_object *ExtendedTriggerMessage;
  12782. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12783. ExtendedTriggerMessage = json_tokener_parse(payload);
  12784. if(!is_error(ExtendedTriggerMessage))
  12785. {
  12786. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12787. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12788. {
  12789. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12790. }
  12791. else
  12792. {
  12793. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  12794. }
  12795. }
  12796. json_object_put(ExtendedTriggerMessage);
  12797. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  12798. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  12799. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  12800. {
  12801. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  12802. }
  12803. else
  12804. {
  12805. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  12806. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  12807. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12808. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  12809. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  12810. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  12811. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  12812. {
  12813. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12814. }
  12815. else
  12816. {
  12817. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12818. }
  12819. }
  12820. sendExtendedTriggerMessageConfirmation(uuid);
  12821. //==========================
  12822. // Trigger message
  12823. //==========================
  12824. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  12825. {
  12826. //sendBootNotificationRequest();
  12827. server_sign = FALSE;
  12828. }
  12829. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  12830. {
  12831. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  12832. }
  12833. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12834. {
  12835. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12836. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12837. {
  12838. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12839. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12840. }
  12841. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12842. }
  12843. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  12844. {
  12845. refreshStartTimer(&clientTime.Heartbeat);
  12846. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  12847. }
  12848. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  12849. {
  12850. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12851. {
  12852. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  12853. }
  12854. else
  12855. {
  12856. for(int idx=0;idx< gunTotalNumber;idx++)
  12857. {
  12858. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12859. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12860. }
  12861. }
  12862. }
  12863. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  12864. {
  12865. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  12866. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  12867. {
  12868. 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\" &");
  12869. }
  12870. }
  12871. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  12872. {
  12873. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12874. {
  12875. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  12876. }
  12877. else
  12878. {
  12879. for(int idx=0;idx< gunTotalNumber;idx++)
  12880. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  12881. }
  12882. }
  12883. return result;
  12884. }
  12885. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  12886. {
  12887. mtrace();
  12888. int result = PASS;
  12889. json_object *GetInstalledCertificateIds;
  12890. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  12891. GetInstalledCertificateIds = json_tokener_parse(payload);
  12892. if(!is_error(GetInstalledCertificateIds))
  12893. {
  12894. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  12895. }
  12896. json_object_put(GetInstalledCertificateIds);
  12897. /*
  12898. * TODO: Return installed certificate process
  12899. */
  12900. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  12901. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  12902. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  12903. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  12904. sendGetInstalledCertificateIdsConfirmation(uuid);
  12905. return result;
  12906. }
  12907. int handleGetLogRequest(char *uuid, char *payload)
  12908. {
  12909. mtrace();
  12910. int result = PASS;
  12911. json_object *GetLog;
  12912. DEBUG_INFO("handleGetLogRequest...\n");
  12913. GetLog = json_tokener_parse(payload);
  12914. if(!is_error(GetLog))
  12915. {
  12916. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  12917. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  12918. if(json_object_object_get(GetLog, "retries") != NULL)
  12919. {
  12920. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  12921. }
  12922. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  12923. {
  12924. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  12925. }
  12926. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  12927. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  12928. {
  12929. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  12930. }
  12931. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  12932. {
  12933. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  12934. }
  12935. }
  12936. json_object_put(GetLog);
  12937. /*
  12938. * TODO: Upload log process
  12939. */
  12940. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  12941. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  12942. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  12943. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  12944. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  12945. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  12946. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  12947. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  12948. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  12949. sendGetLogConfirmation(uuid);
  12950. return result;
  12951. }
  12952. int handleInstallCertificateRequest(char *uuid, char *payload)
  12953. {
  12954. mtrace();
  12955. int result = PASS;
  12956. json_object *InstallCertificate;
  12957. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12958. InstallCertificate = json_tokener_parse(payload);
  12959. if(!is_error(InstallCertificate))
  12960. {
  12961. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12962. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12963. /*
  12964. * TODO: Install certificate process
  12965. */
  12966. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  12967. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  12968. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  12969. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  12970. sendInstallCertificateConfirmation(uuid);
  12971. }
  12972. json_object_put(InstallCertificate);
  12973. return result;
  12974. }
  12975. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12976. {
  12977. mtrace();
  12978. int result = PASS;
  12979. json_object *SignedUpdateFirmware;
  12980. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12981. SignedUpdateFirmware = json_tokener_parse(payload);
  12982. if(!is_error(SignedUpdateFirmware))
  12983. {
  12984. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12985. {
  12986. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12987. }
  12988. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12989. {
  12990. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12991. }
  12992. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12993. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12994. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12995. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12996. {
  12997. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12998. }
  12999. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13000. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13001. }
  13002. json_object_put(SignedUpdateFirmware);
  13003. /*
  13004. * TODO: Upgrade firmware process
  13005. */
  13006. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13007. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  13008. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  13009. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  13010. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  13011. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  13012. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  13013. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  13014. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  13015. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  13016. sendInstallCertificateConfirmation(uuid);
  13017. return result;
  13018. }
  13019. int handleUnknownRequest(char *uuid, char *payload)
  13020. {
  13021. mtrace();
  13022. int result = PASS;
  13023. DEBUG_INFO("handleUnknownRequest...\n");
  13024. sendUnknownConfirmation(uuid);
  13025. result = PASS;
  13026. return result;
  13027. }
  13028. //==========================================
  13029. // Handle server response routine
  13030. //==========================================
  13031. void handleAuthorizeResponse(char *payload, int gun_index)
  13032. {
  13033. mtrace();
  13034. char expiryDatestr[30]={0};
  13035. char parentIdTagstr[20]={0};
  13036. char statusstr[20]={0};
  13037. int expiryDateISNULL=FALSE;
  13038. int parentIdTagISNULL=FALSE;
  13039. DEBUG_INFO("handleAuthorizeResponse...\n");
  13040. json_object *Authorize;
  13041. Authorize = json_tokener_parse(payload);
  13042. if(!is_error(Authorize))
  13043. {
  13044. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13045. {
  13046. // Required data
  13047. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13048. // Optional data
  13049. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13050. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13051. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13052. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13053. }
  13054. }
  13055. json_object_put(Authorize);
  13056. if(expiryDateISNULL == FALSE)
  13057. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13058. if(parentIdTagISNULL == FALSE)
  13059. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13060. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  13061. //Update idTag information to authorization cache if supproted
  13062. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13063. {
  13064. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13065. }
  13066. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  13067. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13068. authorizeRetryTimes = 0;
  13069. }
  13070. void handleBootNotificationResponse(char *payload, int gun_index)
  13071. {
  13072. mtrace();
  13073. char statusStr[12]={0};
  13074. char currentTimeStr[30]={0};
  13075. int intervalInt = 0;
  13076. DEBUG_INFO("handleBootNotificationResponse...\n");
  13077. json_object *BootNotification;
  13078. BootNotification = json_tokener_parse(payload);
  13079. if(!is_error(BootNotification))
  13080. {
  13081. // Required data
  13082. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13083. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13084. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13085. }
  13086. json_object_put(BootNotification);
  13087. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13088. BootNotificationInterval = intervalInt;
  13089. //write back to ShmOCPP16Data->BootNotification
  13090. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  13091. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13092. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  13093. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13094. {
  13095. if((intervalInt == 0) || (intervalInt >= 10))
  13096. {
  13097. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13098. HeartBeatWaitTime = intervalInt;
  13099. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13100. }
  13101. server_sign = TRUE;
  13102. server_pending =FALSE;
  13103. }
  13104. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13105. {
  13106. server_pending = TRUE;
  13107. }
  13108. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  13109. srand(time(NULL));
  13110. refreshStartTimer(&clientTime.Heartbeat);
  13111. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13112. SetOcppConnStatus(TRUE);
  13113. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  13114. }
  13115. void handleDataTransferResponse(char *payload, int gun_index)
  13116. {
  13117. char sstr[160]={0};//sstr[200]={ 0 };
  13118. int c = 0;
  13119. char *loc;
  13120. DEBUG_INFO("handleDataTransferResponse ...\n");
  13121. loc = strstr(payload, "status");
  13122. c = 0;
  13123. while (loc[3+strlen("status")+c] != '\"')
  13124. {
  13125. sstr[c] = loc[3+strlen("status")+c];
  13126. c++;
  13127. }
  13128. sstr[c] = '\0';
  13129. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  13130. }
  13131. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13132. {
  13133. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13134. //struct json_object *obj;
  13135. // obj = json_tokener_parse(payload);
  13136. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13137. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13138. //No fields are defined.
  13139. }
  13140. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13141. {
  13142. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13143. //struct json_object *obj;
  13144. // obj = json_tokener_parse(payload);
  13145. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13146. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13147. //No fields are defined.
  13148. }
  13149. void handleHeartbeatResponse(char *payload, int gun_index)
  13150. {
  13151. mtrace();
  13152. DEBUG_INFO("handleHeartbeatResponse...\n");
  13153. json_object *Heartbeat;
  13154. Heartbeat = json_tokener_parse(payload);
  13155. if(!is_error(Heartbeat))
  13156. {
  13157. // Required data
  13158. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13159. }
  13160. json_object_put(Heartbeat);
  13161. if(FirstHeartBeat == 0)
  13162. {
  13163. FirstHeartBeat = 1;
  13164. DEBUG_INFO("FirstHeartBeat \n");
  13165. }
  13166. HeartBeatWithNOResponse = 0;
  13167. refreshStartTimer(&clientTime.Heartbeat);
  13168. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  13169. }
  13170. void handleMeterValuesResponse(char *payload, int gun_index)
  13171. {
  13172. mtrace();
  13173. DEBUG_INFO("handleMeterValuesResponse...\n");
  13174. isQueueSendable = 1;
  13175. }
  13176. void handleStartTransactionResponse(char *payload, int gun_index)
  13177. {
  13178. mtrace();
  13179. //int transactionIdInt = 0;
  13180. FILE *outfile;
  13181. char data[100]={0};
  13182. DEBUG_INFO("handleStartTransactionResponse...\n");
  13183. json_object *StartTransaction;
  13184. StartTransaction = json_tokener_parse(payload);
  13185. if(!is_error(StartTransaction))
  13186. {
  13187. // Required data
  13188. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13189. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13190. // Optional data
  13191. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13192. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13193. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13194. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13195. }
  13196. json_object_put(StartTransaction);
  13197. isQueueSendable = 1;
  13198. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13199. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13200. //-----------Start : write to the Queue TransactionId file -----------------//
  13201. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  13202. {}
  13203. else
  13204. {
  13205. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  13206. if(log == NULL)
  13207. {
  13208. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13209. return ;
  13210. }
  13211. else
  13212. {
  13213. fclose(log);
  13214. }
  13215. }
  13216. // open file for writing
  13217. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13218. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  13219. {
  13220. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  13221. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13222. fputs(data, outfile);
  13223. fclose (outfile);
  13224. }
  13225. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13226. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13227. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13228. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  13229. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13230. }
  13231. void handleStatusNotificationResponse(char *payload, int gun_index)
  13232. {
  13233. mtrace();
  13234. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13235. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13236. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13237. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13238. }
  13239. void handleStopTransactionnResponse(char *payload, int gun_index)
  13240. {
  13241. mtrace();
  13242. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13243. json_object *StopTransaction;
  13244. StopTransaction = json_tokener_parse(payload);
  13245. if(!is_error(StopTransaction))
  13246. {
  13247. // Optional data
  13248. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13249. {
  13250. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13251. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13252. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13253. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13254. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13255. }
  13256. }
  13257. json_object_put(StopTransaction);
  13258. isQueueSendable = 1;
  13259. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13260. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13261. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13262. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13263. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13264. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13265. }
  13266. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13267. {
  13268. mtrace();
  13269. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13270. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  13271. }
  13272. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13273. {
  13274. mtrace();
  13275. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13276. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  13277. }
  13278. void handleSignCertificateResponse(char *payload, int gun_index)
  13279. {
  13280. mtrace();
  13281. DEBUG_INFO("handleSignCertificateResponse...\n");
  13282. json_object *SignCertificate;
  13283. SignCertificate = json_tokener_parse(payload);
  13284. if(!is_error(SignCertificate))
  13285. {
  13286. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13287. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  13288. }
  13289. json_object_put(SignCertificate);
  13290. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  13291. }
  13292. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13293. {
  13294. mtrace();
  13295. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13296. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13297. }
  13298. //==========================================
  13299. // Handle Error routine
  13300. //==========================================
  13301. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13302. {
  13303. mtrace();
  13304. #ifdef SystemLogMessage
  13305. DEBUG_INFO("errorCode: %s\n", errorCode);
  13306. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13307. DEBUG_INFO("errorDetails: %s\n", payload);
  13308. #endif
  13309. }
  13310. //===============================================
  13311. // Common routine
  13312. //===============================================
  13313. int initialConfigurationTable(void)
  13314. {
  13315. //clock_t start_t, end_t, total_t;
  13316. FILE *fp;
  13317. FILE *outfile;
  13318. char str[512]={0};
  13319. char sstr[256]={0};
  13320. int c = 0;
  13321. char *loc;
  13322. int confVersion = 10;
  13323. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13324. //start_t = clock();
  13325. //printf("Starting of the program, start_t = %ld\n", start_t);
  13326. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13327. // Check configuration file size is correct
  13328. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  13329. {
  13330. struct stat st;
  13331. stat("/Storage/OCPP/OCPPConfiguration", &st);
  13332. if(st.st_size < 3100)
  13333. {
  13334. system("rm -f /Storage/OCPP/OCPPConfiguration");
  13335. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13336. }
  13337. }
  13338. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  13339. {
  13340. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13341. if(outfile == NULL)
  13342. {
  13343. DEBUG_INFO("Error opening file\n");
  13344. return FALSE;
  13345. }
  13346. /*Core Profile*/
  13347. //AllowOfflineTxForUnknownId
  13348. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13351. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13352. //AuthorizationCacheEnabled
  13353. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13354. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13356. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13357. //AuthorizeRemoteTxRequests
  13358. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13361. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13362. //BlinkRepeat
  13363. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13366. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13367. //ClockAlignedDataInterval
  13368. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13369. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13371. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13372. //ConnectionTimeOut
  13373. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13374. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13375. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13376. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13377. //GetConfigurationMaxKeys
  13378. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13380. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13381. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13382. // HeartbeatInterval
  13383. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13386. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13387. // LightIntensity
  13388. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13389. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13391. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13392. // LocalAuthorizeOffline
  13393. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13396. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13397. // LocalPreAuthorize
  13398. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13401. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13402. // MaxEnergyOnInvalidId
  13403. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13404. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13406. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13407. // MeterValuesAlignedData
  13408. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13409. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13410. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13411. 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" );
  13412. else
  13413. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13414. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13415. // MeterValuesAlignedDataMaxLength
  13416. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13417. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13418. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13420. else
  13421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13422. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13423. // MeterValuesSampledData
  13424. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13426. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13427. 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" );
  13428. else
  13429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13430. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13431. // MeterValuesSampledDataMaxLength
  13432. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13434. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13436. else
  13437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13438. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13439. // MeterValueSampleInterval
  13440. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13442. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13443. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13444. // MinimumStatusDuration
  13445. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13446. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13448. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13449. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13450. // NumberOfConnectors
  13451. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13452. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13453. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13454. {
  13455. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13456. }
  13457. else
  13458. {
  13459. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13460. }
  13461. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13462. // ResetRetries
  13463. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13464. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13465. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13466. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13467. // ConnectorPhaseRotation
  13468. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13469. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13470. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13471. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13472. // ConnectorPhaseRotationMaxLength
  13473. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13474. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13475. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13476. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13477. // StopTransactionOnEVSideDisconnect
  13478. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13479. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13480. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13481. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13482. // StopTransactionOnInvalidId
  13483. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13484. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13485. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13486. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13487. // StopTxnAlignedData
  13488. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13489. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13491. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13492. // StopTxnAlignedDataMaxLength
  13493. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13494. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13495. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13496. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13497. // StopTxnSampledData
  13498. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13499. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13500. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13502. else
  13503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13504. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13505. // StopTxnSampledDataMaxLength
  13506. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13508. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13509. {
  13510. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13511. }
  13512. else
  13513. {
  13514. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13515. }
  13516. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13517. // SupportedFeatureProfiles
  13518. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13520. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13521. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13522. // SupportedFeatureProfilesMaxLength
  13523. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13524. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13526. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13527. // TransactionMessageAttempts
  13528. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13529. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13530. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13531. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13532. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13533. // TransactionMessageRetryInterval
  13534. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13537. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13538. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13539. // UnlockConnectorOnEVSideDisconnect
  13540. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13543. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13544. // WebSocketPingInterval
  13545. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13548. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13549. // QueueOffLineMeterValues
  13550. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13551. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13553. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13554. // AuthorizationKey
  13555. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  13558. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13559. // SecurityProfile
  13560. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13562. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  13563. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13564. // DefaultPrice
  13565. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13568. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13569. // CustomDisplayCostAndPrice
  13570. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13573. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13574. // CustomIdleFeeAfterStop
  13575. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13578. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13579. // TimeOffset
  13580. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  13583. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13584. // NextTimeOffsetTransitionDateTime
  13585. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13586. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  13588. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13589. // TimeOffsetNextTransition
  13590. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13592. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  13593. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13594. // SystemUptimeSec
  13595. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13598. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13599. // FreeVend
  13600. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "Free-FreeVend");
  13602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13603. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13604. // Configuration Version
  13605. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13607. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13608. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13609. //* Local Auth List Management Profile*/
  13610. #if 0
  13611. //For OCTT Test Case
  13612. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13613. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13615. #endif
  13616. #if 1
  13617. //LocalAuthListEnabled
  13618. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13621. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13622. #endif
  13623. //LocalAuthListMaxLength
  13624. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  13627. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13628. //SendLocalListMaxLength
  13629. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13632. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13633. //ReserveConnectorZeroSupported
  13634. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13637. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13638. //* Smart Charging Profile */
  13639. //ChargeProfileMaxStackLevel
  13640. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13643. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13644. // ChargingScheduleAllowedChargingRateUnit
  13645. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13648. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13649. // ChargingScheduleMaxPeriods
  13650. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13654. // ConnectorSwitch3to1PhaseSupported
  13655. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13658. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13659. // MaxChargingProfilesInstalled
  13660. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13663. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13664. fclose(outfile);
  13665. }
  13666. else
  13667. {
  13668. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  13669. char keystr[60]={0};
  13670. char readonlystr[10]={0};
  13671. char valuestr[256]={0};
  13672. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  13673. if(fp == NULL) {
  13674. DEBUG_INFO("Error opening file");
  13675. return FALSE;
  13676. }
  13677. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13678. {
  13679. //DEBUG_INFO("Get Configuration \n");
  13680. if(strlen(str) > 0)
  13681. {
  13682. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13683. //*************************key*********************************/
  13684. if(strstr(str, "key") != NULL)
  13685. {
  13686. loc = strstr(str, "key");
  13687. c = 0;
  13688. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13689. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13690. {
  13691. sstr[c] = loc[strlen("key")+3+c];
  13692. c++;
  13693. }
  13694. sstr[c] = '\0';
  13695. strcpy(keystr,sstr);
  13696. }
  13697. //*************************readonly*********************************/
  13698. if(strstr(str, "readonly") != NULL)
  13699. {
  13700. loc = strstr(str, "readonly");
  13701. c = 0;
  13702. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13703. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13704. {
  13705. sstr[c] = loc[strlen("readonly")+2+c];
  13706. c++;
  13707. }
  13708. sstr[c] = '\0';
  13709. strcpy(readonlystr,sstr);
  13710. }
  13711. //*************************value*********************************/
  13712. if(strstr(str, "value") != NULL)
  13713. {
  13714. loc = strstr(str, "value");
  13715. c = 0;
  13716. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13717. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13718. {
  13719. sstr[c] = loc[strlen("value")+3+c];
  13720. c++;
  13721. }
  13722. sstr[c] = '\0';
  13723. strcpy(valuestr,sstr);
  13724. }
  13725. // DEBUG_INFO("keystr=%s\n",keystr);
  13726. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13727. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13728. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13729. {
  13730. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13731. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13732. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13733. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13734. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13735. }
  13736. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13737. {
  13738. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13739. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13740. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13741. }
  13742. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13743. {
  13744. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13745. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13746. }
  13747. if(strcmp(keystr, "BlinkRepeat") == 0)
  13748. {
  13749. //Charger.BlinkRepeat = Integer.parseInt(value);
  13750. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13751. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13752. }
  13753. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13754. {
  13755. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13756. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13757. }
  13758. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13759. {
  13760. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13761. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13762. }
  13763. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13764. {
  13765. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13766. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13767. }
  13768. if(strcmp(keystr, "HeartbeatInterval") == 0)
  13769. {
  13770. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13771. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  13772. HeartBeatWaitTime = atoi(valuestr);
  13773. }
  13774. if(strcmp(keystr, "LightIntensity") == 0)
  13775. {
  13776. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13777. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  13778. }
  13779. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  13780. {
  13781. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13782. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  13783. }
  13784. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  13785. {
  13786. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13787. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  13788. }
  13789. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  13790. {
  13791. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13792. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  13793. }
  13794. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  13795. {
  13796. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13797. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  13798. }
  13799. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  13800. {
  13801. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13802. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  13803. }
  13804. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  13805. {
  13806. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13807. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  13808. }
  13809. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  13810. {
  13811. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13812. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  13813. }
  13814. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  13815. {
  13816. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13817. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  13818. }
  13819. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  13820. {
  13821. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  13823. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  13824. }
  13825. if(strcmp(keystr, "NumberOfConnectors") == 0)
  13826. {
  13827. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13828. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  13829. }
  13830. if(strcmp(keystr, "ResetRetries") == 0)
  13831. {
  13832. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13833. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  13834. }
  13835. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  13836. {
  13837. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13838. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  13839. }
  13840. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  13841. {
  13842. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13843. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  13844. }
  13845. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  13846. {
  13847. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13848. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  13849. }
  13850. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  13851. {
  13852. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13853. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  13854. }
  13855. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  13856. {
  13857. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13858. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  13859. }
  13860. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  13861. {
  13862. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13863. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13864. }
  13865. if(strcmp(keystr, "StopTxnSampledData") == 0)
  13866. {
  13867. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13868. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  13869. }
  13870. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  13871. {
  13872. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13873. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13874. }
  13875. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  13876. {
  13877. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13878. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  13879. }
  13880. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  13881. {
  13882. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13883. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  13884. }
  13885. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  13886. {
  13887. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13888. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  13889. TransactionMessageAttemptsValue = atoi(valuestr);
  13890. }
  13891. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  13892. {
  13893. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13894. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  13895. TransactionMessageRetryIntervalValue = atoi(valuestr);
  13896. }
  13897. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  13898. {
  13899. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13900. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  13901. }
  13902. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  13903. {
  13904. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13905. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  13906. }
  13907. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  13908. {
  13909. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13910. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  13911. }
  13912. if(strcmp(keystr, "AuthorizationKey") == 0)
  13913. {
  13914. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13915. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  13916. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  13917. }
  13918. if(strcmp(keystr, "SecurityProfile") == 0)
  13919. {
  13920. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13921. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  13922. }
  13923. if(strcmp(keystr, "DefaultPrice") == 0)
  13924. {
  13925. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13926. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  13927. }
  13928. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  13929. {
  13930. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13931. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  13932. }
  13933. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  13934. {
  13935. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13936. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  13937. }
  13938. if(strcmp(keystr, "TimeOffset") == 0)
  13939. {
  13940. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13941. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  13942. }
  13943. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  13944. {
  13945. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13946. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  13947. }
  13948. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  13949. {
  13950. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13951. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  13952. }
  13953. if(strcmp(keystr, "SystemUptimeSec") == 0)
  13954. {
  13955. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13956. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  13957. }
  13958. if(strcmp(keystr, "FreeVend") == 0)
  13959. {
  13960. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13961. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  13962. }
  13963. if(strcmp(keystr, "ConfigurationVersion") == 0)
  13964. {
  13965. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13966. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  13967. }
  13968. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  13969. {
  13970. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13971. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  13972. }
  13973. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  13974. {
  13975. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13976. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  13977. }
  13978. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  13979. {
  13980. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13981. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  13982. }
  13983. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  13984. {
  13985. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13986. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  13987. }
  13988. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  13989. {
  13990. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13991. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  13992. }
  13993. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13994. {
  13995. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13996. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  13997. }
  13998. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  13999. {
  14000. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14001. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14002. }
  14003. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14004. {
  14005. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14006. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14007. }
  14008. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14009. {
  14010. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14011. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14012. }
  14013. }
  14014. }
  14015. fclose(fp);
  14016. }
  14017. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14018. {
  14019. return PASS;
  14020. }
  14021. else
  14022. {
  14023. return FAIL;
  14024. }
  14025. }
  14026. void StoreConfigurationTable(void)
  14027. {
  14028. FILE *outfile;
  14029. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14030. if(outfile == NULL)
  14031. {
  14032. DEBUG_INFO("Error opening file");
  14033. return ;
  14034. }
  14035. /*Core Profile*/
  14036. //AllowOfflineTxForUnknownId
  14037. /*
  14038. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14039. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14042. */
  14043. //DEBUG_INFO("data=%s\n",data);
  14044. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14045. //AuthorizationCacheEnabled
  14046. /*
  14047. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14050. */
  14051. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14052. //AuthorizeRemoteTxRequests
  14053. /*
  14054. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14057. */
  14058. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14059. //BlinkRepeat
  14060. /*
  14061. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14064. */
  14065. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14066. //ClockAlignedDataInterval
  14067. /*
  14068. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14071. */
  14072. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14073. //ConnectionTimeOut
  14074. /*
  14075. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14078. */
  14079. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14080. //GetConfigurationMaxKeys
  14081. /*
  14082. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14085. */
  14086. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14087. // HeartbeatInterval
  14088. /*
  14089. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14092. */
  14093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14094. // LightIntensity
  14095. /*
  14096. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14099. */
  14100. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14101. // LocalAuthorizeOffline
  14102. /*
  14103. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14106. */
  14107. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14108. // LocalPreAuthorize
  14109. /*
  14110. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14113. */
  14114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14115. // MaxEnergyOnInvalidId
  14116. /*
  14117. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14120. */
  14121. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14123. // MeterValuesAlignedData
  14124. /*
  14125. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14128. */
  14129. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14130. // MeterValuesAlignedDataMaxLength
  14131. /*
  14132. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14135. */
  14136. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14137. // MeterValuesSampledData
  14138. /*
  14139. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14142. */
  14143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14144. // MeterValuesSampledDataMaxLength
  14145. /*
  14146. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14149. */
  14150. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14151. // MeterValueSampleInterval
  14152. /*
  14153. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14156. */
  14157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14158. // MinimumStatusDuration
  14159. /*
  14160. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14163. */
  14164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14165. // NumberOfConnectors
  14166. /*
  14167. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14169. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14170. {
  14171. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14172. }
  14173. else
  14174. {
  14175. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14176. }
  14177. */
  14178. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14179. // ResetRetries
  14180. /*
  14181. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14184. */
  14185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14186. // ConnectorPhaseRotation
  14187. /*
  14188. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14191. */
  14192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14193. // ConnectorPhaseRotationMaxLength
  14194. /*
  14195. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14197. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14198. */
  14199. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14200. // StopTransactionOnEVSideDisconnect
  14201. /*
  14202. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14205. */
  14206. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14207. // StopTransactionOnInvalidId
  14208. /*
  14209. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14211. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14212. */
  14213. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14214. // StopTxnAlignedData
  14215. /*
  14216. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14219. */
  14220. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14221. // StopTxnAlignedDataMaxLength
  14222. /*
  14223. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14226. */
  14227. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14228. // StopTxnSampledData
  14229. /*
  14230. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14233. */
  14234. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14235. // StopTxnSampledDataMaxLength
  14236. /*
  14237. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14240. */
  14241. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14242. // SupportedFeatureProfiles
  14243. /*
  14244. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14247. */
  14248. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14249. // SupportedFeatureProfilesMaxLength
  14250. /*
  14251. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14254. */
  14255. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14256. // TransactionMessageAttempts
  14257. /*
  14258. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14261. */
  14262. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14263. // TransactionMessageRetryInterval
  14264. /*
  14265. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14268. */
  14269. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14270. // UnlockConnectorOnEVSideDisconnect
  14271. /*
  14272. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14274. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14275. */
  14276. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14277. // WebSocketPingInterval
  14278. /*
  14279. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14282. */
  14283. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14284. // QueueOffLineMeterValues
  14285. /*
  14286. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14289. */
  14290. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14291. // AuthorizationKey
  14292. /*
  14293. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14296. */
  14297. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14298. // SecurityProfile
  14299. /*
  14300. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14303. */
  14304. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14305. // DefaultPrice
  14306. /*
  14307. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14308. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14310. */
  14311. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14312. // CustomDisplayCostAndPrice
  14313. /*
  14314. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14317. */
  14318. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14319. // CustomIdleFeeAfterStop
  14320. /*
  14321. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14324. */
  14325. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14326. // TimeOffset
  14327. /*
  14328. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  14331. */
  14332. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14333. // NextTimeOffsetTransitionDateTime
  14334. /*
  14335. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14337. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  14338. */
  14339. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14340. // TimeOffsetNextTransition
  14341. /*
  14342. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  14345. */
  14346. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14347. // SystemUptimeSec
  14348. /*
  14349. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14351. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14352. */
  14353. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14354. // FreeVend
  14355. /*
  14356. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14359. */
  14360. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14361. // ConfigurationVersion
  14362. /*
  14363. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14366. */
  14367. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14368. //* Local Auth List Management Profile*/
  14369. //LocalAuthListEnabled
  14370. /*
  14371. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14374. */
  14375. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14376. //LocalAuthListMaxLength
  14377. /*
  14378. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14381. */
  14382. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14383. //SendLocalListMaxLength
  14384. /*
  14385. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14388. */
  14389. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14390. //ReserveConnectorZeroSupported
  14391. /*
  14392. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14395. */
  14396. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14397. //* Smart Charging Profile */
  14398. //ChargeProfileMaxStackLevel
  14399. /*
  14400. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14403. */
  14404. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14405. // ChargingScheduleAllowedChargingRateUnit
  14406. /*
  14407. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14409. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14410. */
  14411. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14412. // ChargingScheduleMaxPeriods
  14413. /*
  14414. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14416. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14417. */
  14418. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14419. // ConnectorSwitch3to1PhaseSupported
  14420. /*
  14421. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14423. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14424. */
  14425. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14426. // MaxChargingProfilesInstalled
  14427. /*
  14428. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14431. */
  14432. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14433. fclose(outfile);
  14434. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14435. }
  14436. void getKeyValue(char *keyReq)
  14437. {
  14438. int isEmpty = FALSE;
  14439. int isKnowKey = FALSE;
  14440. DEBUG_INFO("keyReq = %s\n", keyReq);
  14441. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14442. isEmpty = TRUE;
  14443. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14444. {
  14445. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14447. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14448. {
  14449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14450. }
  14451. else
  14452. {
  14453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14454. }
  14455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14456. isKnowKey = TRUE;
  14457. }
  14458. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14459. {
  14460. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14462. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14463. {
  14464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14465. }
  14466. else
  14467. {
  14468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14469. }
  14470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14471. isKnowKey = TRUE;
  14472. }
  14473. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14474. {
  14475. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14477. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14478. {
  14479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14480. }
  14481. else
  14482. {
  14483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14484. }
  14485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14486. isKnowKey = TRUE;
  14487. }
  14488. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14489. {
  14490. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14492. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14493. {
  14494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14495. }
  14496. else
  14497. {
  14498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14499. }
  14500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14501. isKnowKey = TRUE;
  14502. }
  14503. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14504. {
  14505. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14507. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14508. {
  14509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14510. }
  14511. else
  14512. {
  14513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14514. }
  14515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14516. isKnowKey = TRUE;
  14517. }
  14518. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14519. {
  14520. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14522. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14523. {
  14524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14525. }
  14526. else
  14527. {
  14528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14529. }
  14530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14531. isKnowKey = TRUE;
  14532. }
  14533. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14534. {
  14535. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14537. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14538. {
  14539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14540. }
  14541. else
  14542. {
  14543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14544. }
  14545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14546. isKnowKey = TRUE;
  14547. }
  14548. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14549. {
  14550. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14552. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14553. {
  14554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14555. }
  14556. else
  14557. {
  14558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14559. }
  14560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14561. isKnowKey = TRUE;
  14562. }
  14563. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14564. {
  14565. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14567. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14568. {
  14569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14570. }
  14571. else
  14572. {
  14573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14574. }
  14575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14576. isKnowKey = TRUE;
  14577. }
  14578. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14579. {
  14580. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14582. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14583. {
  14584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14585. }
  14586. else
  14587. {
  14588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14589. }
  14590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14591. isKnowKey = TRUE;
  14592. }
  14593. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14594. {
  14595. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14597. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14598. {
  14599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14600. }
  14601. else
  14602. {
  14603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14604. }
  14605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14606. isKnowKey = TRUE;
  14607. }
  14608. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14609. {
  14610. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14611. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14612. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14613. {
  14614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14615. }
  14616. else
  14617. {
  14618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14619. }
  14620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14621. isKnowKey = TRUE;
  14622. }
  14623. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14624. {
  14625. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14627. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14628. {
  14629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14630. }
  14631. else
  14632. {
  14633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14634. }
  14635. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14636. isKnowKey = TRUE;
  14637. }
  14638. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14639. {
  14640. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14642. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14643. {
  14644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14645. }
  14646. else
  14647. {
  14648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14649. }
  14650. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14651. isKnowKey = TRUE;
  14652. }
  14653. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14654. {
  14655. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14657. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14658. {
  14659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14660. }
  14661. else
  14662. {
  14663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14664. }
  14665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14666. isKnowKey = TRUE;
  14667. }
  14668. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14669. {
  14670. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14672. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14673. {
  14674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14675. }
  14676. else
  14677. {
  14678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14679. }
  14680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14681. isKnowKey = TRUE;
  14682. }
  14683. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14684. {
  14685. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14687. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14688. {
  14689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14690. }
  14691. else
  14692. {
  14693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14694. }
  14695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14696. isKnowKey = TRUE;
  14697. }
  14698. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14699. {
  14700. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14702. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14703. {
  14704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14705. }
  14706. else
  14707. {
  14708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14709. }
  14710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  14711. isKnowKey = TRUE;
  14712. }
  14713. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14714. {
  14715. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14717. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14718. {
  14719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14720. }
  14721. else
  14722. {
  14723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14724. }
  14725. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  14726. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  14727. isKnowKey = TRUE;
  14728. }
  14729. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  14730. {
  14731. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  14732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  14733. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14734. {
  14735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  14736. }
  14737. else
  14738. {
  14739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  14740. }
  14741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  14742. isKnowKey = TRUE;
  14743. }
  14744. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  14745. {
  14746. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  14747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  14748. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14749. {
  14750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  14751. }
  14752. else
  14753. {
  14754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  14755. }
  14756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  14757. isKnowKey = TRUE;
  14758. }
  14759. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  14760. {
  14761. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  14762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  14763. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14764. {
  14765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14766. }
  14767. else
  14768. {
  14769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14770. }
  14771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  14772. isKnowKey = TRUE;
  14773. }
  14774. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  14775. {
  14776. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  14777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  14778. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14779. {
  14780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14781. }
  14782. else
  14783. {
  14784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14785. }
  14786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  14787. isKnowKey = TRUE;
  14788. }
  14789. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  14790. {
  14791. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  14792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  14793. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14794. {
  14795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14796. }
  14797. else
  14798. {
  14799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14800. }
  14801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  14802. isKnowKey = TRUE;
  14803. }
  14804. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  14805. {
  14806. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  14807. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  14808. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14809. {
  14810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14811. }
  14812. else
  14813. {
  14814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14815. }
  14816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  14817. isKnowKey = TRUE;
  14818. }
  14819. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  14820. {
  14821. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  14822. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  14823. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14824. {
  14825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14826. }
  14827. else
  14828. {
  14829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14830. }
  14831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  14832. isKnowKey = TRUE;
  14833. }
  14834. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  14835. {
  14836. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  14837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  14838. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14839. {
  14840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  14841. }
  14842. else
  14843. {
  14844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  14845. }
  14846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  14847. isKnowKey = TRUE;
  14848. }
  14849. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  14850. {
  14851. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  14852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  14853. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14854. {
  14855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14856. }
  14857. else
  14858. {
  14859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14860. }
  14861. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  14862. isKnowKey = TRUE;
  14863. }
  14864. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  14865. {
  14866. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  14867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  14868. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14869. {
  14870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  14871. }
  14872. else
  14873. {
  14874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  14875. }
  14876. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  14877. isKnowKey = TRUE;
  14878. }
  14879. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  14880. {
  14881. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  14882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  14883. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14884. {
  14885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14886. }
  14887. else
  14888. {
  14889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14890. }
  14891. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  14892. isKnowKey = TRUE;
  14893. }
  14894. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  14895. {
  14896. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  14897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  14898. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14899. {
  14900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  14901. }
  14902. else
  14903. {
  14904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  14905. }
  14906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  14907. isKnowKey = TRUE;
  14908. }
  14909. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  14910. {
  14911. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  14912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  14913. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14914. {
  14915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  14916. }
  14917. else
  14918. {
  14919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  14920. }
  14921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  14922. isKnowKey = TRUE;
  14923. }
  14924. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  14925. {
  14926. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  14927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  14928. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14929. {
  14930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14931. }
  14932. else
  14933. {
  14934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14935. }
  14936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  14937. isKnowKey = TRUE;
  14938. }
  14939. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  14940. {
  14941. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  14942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  14943. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14944. {
  14945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  14946. }
  14947. else
  14948. {
  14949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  14950. }
  14951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  14952. isKnowKey = TRUE;
  14953. }
  14954. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  14955. {
  14956. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  14957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  14958. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14959. {
  14960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  14961. }
  14962. else
  14963. {
  14964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  14965. }
  14966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  14967. isKnowKey = TRUE;
  14968. }
  14969. /*
  14970. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  14971. {
  14972. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  14973. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  14974. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  14975. {
  14976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  14977. }
  14978. else
  14979. {
  14980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  14981. }
  14982. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  14983. isKnowKey = TRUE;
  14984. }*/
  14985. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  14986. {
  14987. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  14988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  14989. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14990. {
  14991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  14992. }
  14993. else
  14994. {
  14995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  14996. }
  14997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  14998. isKnowKey = TRUE;
  14999. }
  15000. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15001. {
  15002. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15004. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15005. {
  15006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15007. }
  15008. else
  15009. {
  15010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15011. }
  15012. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15013. isKnowKey = TRUE;
  15014. }
  15015. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15016. {
  15017. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15019. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15020. {
  15021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15022. }
  15023. else
  15024. {
  15025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15026. }
  15027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15028. isKnowKey = TRUE;
  15029. }
  15030. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15031. {
  15032. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15034. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15035. {
  15036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15037. }
  15038. else
  15039. {
  15040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15041. }
  15042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15043. isKnowKey = TRUE;
  15044. }
  15045. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  15046. {
  15047. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  15048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  15049. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15050. {
  15051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  15052. }
  15053. else
  15054. {
  15055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  15056. }
  15057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  15058. isKnowKey = TRUE;
  15059. }
  15060. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  15061. {
  15062. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  15063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  15064. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15065. {
  15066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  15067. }
  15068. else
  15069. {
  15070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  15071. }
  15072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  15073. isKnowKey = TRUE;
  15074. }
  15075. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  15076. {
  15077. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  15078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  15079. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15080. {
  15081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  15082. }
  15083. else
  15084. {
  15085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  15086. }
  15087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  15088. isKnowKey = TRUE;
  15089. }
  15090. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15091. {
  15092. struct sysinfo s_info;
  15093. int error = sysinfo(&s_info);
  15094. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15096. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15097. {
  15098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15099. }
  15100. else
  15101. {
  15102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15103. }
  15104. if(error != 0)
  15105. {
  15106. DEBUG_WARN("System uptime get error: %d\n", error);
  15107. }
  15108. else
  15109. {
  15110. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15111. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15112. }
  15113. isKnowKey = TRUE;
  15114. }
  15115. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15116. {
  15117. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15118. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15119. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15120. {
  15121. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15122. }
  15123. else
  15124. {
  15125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15126. }
  15127. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  15128. isKnowKey = TRUE;
  15129. }
  15130. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15131. {
  15132. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15133. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15134. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15135. {
  15136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15137. }
  15138. else
  15139. {
  15140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15141. }
  15142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15143. isKnowKey = TRUE;
  15144. }
  15145. #if 1
  15146. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15147. {
  15148. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15150. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15151. {
  15152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15153. }
  15154. else
  15155. {
  15156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15157. }
  15158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15159. isKnowKey = TRUE;
  15160. }
  15161. #endif
  15162. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15163. {
  15164. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15166. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15167. {
  15168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15169. }
  15170. else
  15171. {
  15172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15173. }
  15174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15175. isKnowKey = TRUE;
  15176. }
  15177. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15178. {
  15179. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15181. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15182. {
  15183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15184. }
  15185. else
  15186. {
  15187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15188. }
  15189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15190. isKnowKey = TRUE;
  15191. }
  15192. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15193. {
  15194. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15196. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15197. {
  15198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15199. }
  15200. else
  15201. {
  15202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15203. }
  15204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15205. isKnowKey = TRUE;
  15206. }
  15207. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15208. {
  15209. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15210. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15211. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15212. {
  15213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15214. }
  15215. else
  15216. {
  15217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15218. }
  15219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15220. isKnowKey = TRUE;
  15221. }
  15222. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15223. {
  15224. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15225. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15226. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15227. {
  15228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15229. }
  15230. else
  15231. {
  15232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15233. }
  15234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15235. isKnowKey = TRUE;
  15236. }
  15237. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15238. {
  15239. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15241. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15242. {
  15243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15244. }
  15245. else
  15246. {
  15247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15248. }
  15249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15250. isKnowKey = TRUE;
  15251. }
  15252. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15253. {
  15254. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15256. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15257. {
  15258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15259. }
  15260. else
  15261. {
  15262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15263. }
  15264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15265. isKnowKey = TRUE;
  15266. }
  15267. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15268. {
  15269. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15270. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15271. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15272. {
  15273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15274. }
  15275. else
  15276. {
  15277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15278. }
  15279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15280. isKnowKey = TRUE;
  15281. }
  15282. //=========================================================
  15283. if(!isEmpty && !isKnowKey)
  15284. {
  15285. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15286. strcpy(unknownkey[UnknownKeynum], keyReq);
  15287. UnknownKeynum = UnknownKeynum + 1;
  15288. }
  15289. }
  15290. void processUnkownKey(void)
  15291. {
  15292. DEBUG_INFO("processUnkownKey...\n");
  15293. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15294. for(int index=0; index < UnknownKeynum; index++)
  15295. {
  15296. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15297. {
  15298. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15299. }
  15300. }
  15301. }
  15302. int setKeyValue(char *key, char *value)
  15303. {
  15304. int isSuccess = NotSupported;
  15305. int check_ascii=0;
  15306. char str[256]={0};
  15307. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15308. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15309. {
  15310. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15311. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15312. {
  15313. strcpy(str, (const char*)value);
  15314. for(int i = 0; str[i]; i++){
  15315. str[i] = tolower(str[i]);
  15316. }
  15317. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15318. isSuccess = ConfigurationStatus_Accepted;
  15319. }
  15320. else
  15321. {
  15322. isSuccess = ConfigurationStatus_Rejected;
  15323. }
  15324. }
  15325. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15326. {
  15327. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15328. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15329. {
  15330. strcpy(str, (const char*)value);
  15331. for(int i = 0; str[i]; i++){
  15332. str[i] = tolower(str[i]);
  15333. }
  15334. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15335. isSuccess = ConfigurationStatus_Accepted;
  15336. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  15337. }
  15338. else
  15339. {
  15340. isSuccess = ConfigurationStatus_Rejected;
  15341. }
  15342. }
  15343. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15344. {
  15345. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15346. {
  15347. strcpy(str, (const char*)value);
  15348. for(int i = 0; str[i]; i++)
  15349. {
  15350. str[i] = tolower(str[i]);
  15351. }
  15352. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15353. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15354. isSuccess = ConfigurationStatus_Accepted;
  15355. }
  15356. else
  15357. {
  15358. isSuccess = ConfigurationStatus_Rejected;
  15359. }
  15360. }
  15361. if(strcmp(key, "BlinkRepeat") == 0)
  15362. {
  15363. //Charger.BlinkRepeat = Integer.parseInt(value);
  15364. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15365. {
  15366. check_ascii = value[0];
  15367. if( (check_ascii < 48) || (check_ascii > 57) )
  15368. {
  15369. isSuccess = ConfigurationStatus_Rejected;
  15370. }
  15371. else
  15372. {
  15373. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15374. isSuccess = ConfigurationStatus_Accepted;
  15375. }
  15376. }
  15377. else
  15378. {
  15379. isSuccess = ConfigurationStatus_Rejected;
  15380. }
  15381. }
  15382. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15383. {
  15384. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15385. {
  15386. check_ascii = value[0];
  15387. if( (check_ascii < 48) || (check_ascii > 57) )
  15388. {
  15389. isSuccess = ConfigurationStatus_Rejected;
  15390. }
  15391. else
  15392. {
  15393. if((atoi(value) == 0) || (atoi(value) >= 5))
  15394. {
  15395. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15396. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15397. isSuccess = ConfigurationStatus_Accepted;
  15398. }
  15399. else
  15400. isSuccess = ConfigurationStatus_Rejected;
  15401. }
  15402. }
  15403. else
  15404. {
  15405. isSuccess = ConfigurationStatus_Rejected;
  15406. }
  15407. }
  15408. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15409. {
  15410. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15411. {
  15412. check_ascii = value[0];
  15413. if( (check_ascii < 48) || (check_ascii > 57) )
  15414. {
  15415. isSuccess = ConfigurationStatus_Rejected;
  15416. }
  15417. else
  15418. {
  15419. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15420. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15421. isSuccess = ConfigurationStatus_Accepted;
  15422. }
  15423. }
  15424. else
  15425. {
  15426. isSuccess = ConfigurationStatus_Rejected;
  15427. }
  15428. }
  15429. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15430. {
  15431. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15432. {
  15433. check_ascii = value[0];
  15434. if( (check_ascii < 48) || (check_ascii > 57) )
  15435. {
  15436. isSuccess = ConfigurationStatus_Rejected;
  15437. }
  15438. else
  15439. {
  15440. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15441. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15442. isSuccess = ConfigurationStatus_Accepted;
  15443. }
  15444. }
  15445. else
  15446. {
  15447. isSuccess = ConfigurationStatus_Rejected;
  15448. }
  15449. }
  15450. if(strcmp(key, "HeartbeatInterval") == 0)
  15451. {
  15452. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15453. {
  15454. check_ascii = value[0];
  15455. if( (check_ascii < 48) || (check_ascii > 57) )
  15456. {
  15457. isSuccess = ConfigurationStatus_Rejected;
  15458. }
  15459. else
  15460. {
  15461. if((atoi(value) == 0) || (atoi(value) >= 10))
  15462. {
  15463. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15464. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15465. HeartBeatWaitTime = atoi(value);
  15466. isSuccess = ConfigurationStatus_Accepted;
  15467. }
  15468. else
  15469. {
  15470. isSuccess = ConfigurationStatus_Rejected;
  15471. }
  15472. }
  15473. }
  15474. else
  15475. {
  15476. isSuccess = ConfigurationStatus_Rejected;
  15477. }
  15478. }
  15479. if(strcmp(key, "LightIntensity") == 0)
  15480. {
  15481. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15482. {
  15483. check_ascii = value[0];
  15484. if( (check_ascii < 48) || (check_ascii > 57) )
  15485. {
  15486. isSuccess = ConfigurationStatus_Rejected;
  15487. }
  15488. else
  15489. {
  15490. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15491. isSuccess = ConfigurationStatus_Accepted;
  15492. }
  15493. }
  15494. else
  15495. {
  15496. isSuccess = ConfigurationStatus_Rejected;
  15497. }
  15498. }
  15499. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15500. {
  15501. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15502. {
  15503. strcpy(str, (const char*)value);
  15504. for(int i = 0; str[i]; i++)
  15505. {
  15506. str[i] = tolower(str[i]);
  15507. }
  15508. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15509. isSuccess = ConfigurationStatus_Accepted;
  15510. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15511. }
  15512. else
  15513. {
  15514. isSuccess = ConfigurationStatus_Rejected;
  15515. }
  15516. }
  15517. if(strcmp(key, "LocalPreAuthorize") == 0)
  15518. {
  15519. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15520. {
  15521. strcpy(str, (const char*)value);
  15522. for(int i = 0; str[i]; i++)
  15523. {
  15524. str[i] = tolower(str[i]);
  15525. }
  15526. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15527. isSuccess = ConfigurationStatus_Accepted;
  15528. }
  15529. else
  15530. {
  15531. isSuccess = ConfigurationStatus_Rejected;
  15532. }
  15533. }
  15534. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15535. {
  15536. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15537. {
  15538. check_ascii = value[0];
  15539. if( (check_ascii < 48) || (check_ascii > 57) )
  15540. {
  15541. isSuccess = ConfigurationStatus_Rejected;
  15542. }
  15543. else
  15544. {
  15545. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15546. isSuccess = ConfigurationStatus_Accepted;
  15547. }
  15548. }
  15549. else
  15550. {
  15551. isSuccess = ConfigurationStatus_Rejected;
  15552. }
  15553. }
  15554. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15555. {
  15556. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15557. {
  15558. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15559. isSuccess = ConfigurationStatus_Accepted;
  15560. }
  15561. else
  15562. {
  15563. isSuccess = ConfigurationStatus_Rejected;
  15564. }
  15565. }
  15566. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15567. {
  15568. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15569. {
  15570. check_ascii = value[0];
  15571. if( (check_ascii < 48) || (check_ascii > 57) )
  15572. {
  15573. isSuccess = ConfigurationStatus_Rejected;
  15574. }
  15575. else
  15576. {
  15577. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15578. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15579. isSuccess = ConfigurationStatus_Accepted;
  15580. }
  15581. }
  15582. else
  15583. {
  15584. isSuccess = ConfigurationStatus_Rejected;
  15585. }
  15586. }
  15587. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15588. {
  15589. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15590. {
  15591. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15592. isSuccess = ConfigurationStatus_Accepted;
  15593. }
  15594. else
  15595. {
  15596. isSuccess = ConfigurationStatus_Rejected;
  15597. }
  15598. }
  15599. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15600. {
  15601. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15602. {
  15603. check_ascii = value[0];
  15604. if( (check_ascii < 48) || (check_ascii > 57) )
  15605. {
  15606. isSuccess = ConfigurationStatus_Rejected;
  15607. }
  15608. else
  15609. {
  15610. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15611. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15612. isSuccess = ConfigurationStatus_Accepted;
  15613. }
  15614. }
  15615. else
  15616. {
  15617. isSuccess = ConfigurationStatus_Rejected;
  15618. }
  15619. }
  15620. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15621. {
  15622. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15623. {
  15624. check_ascii = value[0];
  15625. if( (check_ascii < 48) || (check_ascii > 57) )
  15626. {
  15627. isSuccess = ConfigurationStatus_Rejected;
  15628. }
  15629. else
  15630. {
  15631. if((atoi(value) == 0) || (atoi(value) >= 5))
  15632. {
  15633. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15634. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15635. isSuccess = ConfigurationStatus_Accepted;
  15636. }
  15637. else
  15638. {
  15639. isSuccess = ConfigurationStatus_Rejected;
  15640. }
  15641. }
  15642. }
  15643. else
  15644. {
  15645. isSuccess = ConfigurationStatus_Rejected;
  15646. }
  15647. }
  15648. if(strcmp(key, "MinimumStatusDuration") == 0)
  15649. {
  15650. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15651. {
  15652. check_ascii = value[0];
  15653. if( (check_ascii < 48) || (check_ascii > 57) )
  15654. {
  15655. isSuccess = ConfigurationStatus_Rejected;
  15656. }
  15657. else
  15658. {
  15659. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15660. {
  15661. isSuccess = ConfigurationStatus_Rejected;
  15662. }
  15663. else
  15664. {
  15665. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  15666. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  15667. server_cycle_Status = atoi(value); //StatusNotification Cycle
  15668. isSuccess = ConfigurationStatus_Accepted;
  15669. }
  15670. }
  15671. }
  15672. else
  15673. {
  15674. isSuccess = ConfigurationStatus_Rejected;
  15675. }
  15676. }
  15677. if(strcmp(key, "NumberOfConnectors") == 0)
  15678. {
  15679. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15680. {
  15681. check_ascii = value[0];
  15682. if( (check_ascii < 48) || (check_ascii > 57) )
  15683. {
  15684. isSuccess = ConfigurationStatus_Rejected;
  15685. }
  15686. else
  15687. {
  15688. //Charger.ResetRetries = Integer.parseInt(value);
  15689. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  15690. isSuccess = ConfigurationStatus_Accepted;
  15691. }
  15692. }
  15693. else
  15694. {
  15695. isSuccess = ConfigurationStatus_Rejected;
  15696. }
  15697. }
  15698. if(strcmp(key, "ResetRetries") == 0)
  15699. {
  15700. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15701. {
  15702. check_ascii = value[0];
  15703. if( (check_ascii < 48) || (check_ascii > 57) )
  15704. {
  15705. isSuccess = ConfigurationStatus_Rejected;
  15706. }
  15707. else
  15708. {
  15709. //Charger.ResetRetries = Integer.parseInt(value);
  15710. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  15711. isSuccess = ConfigurationStatus_Accepted;
  15712. }
  15713. }
  15714. else
  15715. {
  15716. isSuccess = ConfigurationStatus_Rejected;
  15717. }
  15718. }
  15719. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  15720. {
  15721. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15722. {
  15723. strcpy(str, (const char*)value);
  15724. for(int i = 0; str[i]; i++)
  15725. {
  15726. str[i] = tolower(str[i]);
  15727. }
  15728. if(strcmp(str, "notapplicable")== 0)
  15729. {
  15730. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  15731. isSuccess = ConfigurationStatus_Accepted;
  15732. }
  15733. else if(strcmp(str, "unknown")== 0)
  15734. {
  15735. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  15736. isSuccess = ConfigurationStatus_Accepted;
  15737. }
  15738. else if(strcmp(str, "rst")== 0)
  15739. {
  15740. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  15741. isSuccess = ConfigurationStatus_Accepted;
  15742. }
  15743. else if(strcmp(str, "rts")== 0)
  15744. {
  15745. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  15746. isSuccess = ConfigurationStatus_Accepted;
  15747. }
  15748. else if(strcmp(str, "srt")== 0)
  15749. {
  15750. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  15751. isSuccess = ConfigurationStatus_Accepted;
  15752. }
  15753. else if(strcmp(str, "str")== 0)
  15754. {
  15755. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  15756. isSuccess = ConfigurationStatus_Accepted;
  15757. }
  15758. else if(strcmp(str, "trs")== 0)
  15759. {
  15760. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  15761. isSuccess = ConfigurationStatus_Accepted;
  15762. }
  15763. else if(strcmp(str, "tsr")== 0)
  15764. {
  15765. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  15766. isSuccess = ConfigurationStatus_Accepted;
  15767. }
  15768. else
  15769. {
  15770. isSuccess = ConfigurationStatus_Rejected;
  15771. }
  15772. }
  15773. else
  15774. {
  15775. isSuccess = ConfigurationStatus_Rejected;
  15776. }
  15777. }
  15778. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  15779. {
  15780. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15781. {
  15782. check_ascii = value[0];
  15783. if( (check_ascii < 48) || (check_ascii > 57) )
  15784. {
  15785. isSuccess = ConfigurationStatus_Rejected;
  15786. }
  15787. else
  15788. {
  15789. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  15790. isSuccess = ConfigurationStatus_Accepted;
  15791. }
  15792. }
  15793. else
  15794. {
  15795. isSuccess = ConfigurationStatus_Rejected;
  15796. }
  15797. }
  15798. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  15799. {
  15800. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15801. {
  15802. strcpy(str, (const char*)value);
  15803. for(int i = 0; str[i]; i++)
  15804. {
  15805. str[i] = tolower(str[i]);
  15806. }
  15807. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15808. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15809. isSuccess = ConfigurationStatus_Accepted;
  15810. }
  15811. else
  15812. {
  15813. isSuccess = ConfigurationStatus_Rejected;
  15814. }
  15815. }
  15816. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  15817. {
  15818. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15819. {
  15820. strcpy(str, (const char*)value);
  15821. for(int i = 0; str[i]; i++)
  15822. {
  15823. str[i] = tolower(str[i]);
  15824. }
  15825. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  15826. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15827. isSuccess = ConfigurationStatus_Accepted;
  15828. }
  15829. else
  15830. {
  15831. isSuccess = ConfigurationStatus_Rejected;
  15832. }
  15833. }
  15834. if(strcmp(key, "StopTxnAlignedData") == 0)
  15835. {
  15836. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15837. {
  15838. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  15839. isSuccess = ConfigurationStatus_Accepted;
  15840. }
  15841. else
  15842. {
  15843. isSuccess = ConfigurationStatus_Rejected;
  15844. }
  15845. }
  15846. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  15847. {
  15848. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15849. {
  15850. check_ascii = value[0];
  15851. if( (check_ascii < 48) || (check_ascii > 57) )
  15852. {
  15853. isSuccess = ConfigurationStatus_Rejected;
  15854. }
  15855. else
  15856. {
  15857. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  15858. isSuccess = ConfigurationStatus_Accepted;
  15859. }
  15860. }
  15861. else
  15862. {
  15863. isSuccess = ConfigurationStatus_Rejected;
  15864. }
  15865. }
  15866. if(strcmp(key, "StopTxnSampledData") == 0)
  15867. {
  15868. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15869. {
  15870. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  15871. isSuccess = ConfigurationStatus_Accepted;
  15872. }
  15873. else
  15874. {
  15875. isSuccess = ConfigurationStatus_Rejected;
  15876. }
  15877. }
  15878. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  15879. {
  15880. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15881. {
  15882. check_ascii = value[0];
  15883. if( (check_ascii < 48) || (check_ascii > 57) )
  15884. {
  15885. isSuccess = ConfigurationStatus_Rejected;
  15886. }
  15887. else
  15888. {
  15889. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  15890. isSuccess = ConfigurationStatus_Accepted;
  15891. }
  15892. }
  15893. else
  15894. {
  15895. isSuccess = ConfigurationStatus_Rejected;
  15896. }
  15897. }
  15898. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  15899. {
  15900. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15901. {
  15902. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  15903. isSuccess = ConfigurationStatus_Accepted;
  15904. }
  15905. else
  15906. {
  15907. isSuccess = ConfigurationStatus_Rejected;
  15908. }
  15909. }
  15910. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  15911. {
  15912. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15913. {
  15914. check_ascii = value[0];
  15915. if( (check_ascii < 48) || (check_ascii > 57) )
  15916. {
  15917. isSuccess = ConfigurationStatus_Rejected;
  15918. }
  15919. else
  15920. {
  15921. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  15922. isSuccess = ConfigurationStatus_Accepted;
  15923. }
  15924. }
  15925. else
  15926. {
  15927. isSuccess = ConfigurationStatus_Rejected;
  15928. }
  15929. }
  15930. if(strcmp(key, "TransactionMessageAttempts") == 0)
  15931. {
  15932. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15933. {
  15934. check_ascii = value[0];
  15935. if( (check_ascii < 48) || (check_ascii > 57) )
  15936. {
  15937. isSuccess = ConfigurationStatus_Rejected;
  15938. }
  15939. else
  15940. {
  15941. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  15942. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  15943. TransactionMessageAttemptsValue = atoi(value);
  15944. isSuccess = ConfigurationStatus_Accepted;
  15945. }
  15946. }
  15947. else
  15948. {
  15949. isSuccess = ConfigurationStatus_Rejected;
  15950. }
  15951. }
  15952. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  15953. {
  15954. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15955. {
  15956. check_ascii = value[0];
  15957. if( (check_ascii < 48) || (check_ascii > 57) )
  15958. {
  15959. isSuccess = ConfigurationStatus_Rejected;
  15960. }
  15961. else
  15962. {
  15963. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  15964. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  15965. TransactionMessageRetryIntervalValue = atoi(value);
  15966. isSuccess = ConfigurationStatus_Accepted;
  15967. }
  15968. }
  15969. else
  15970. {
  15971. isSuccess = ConfigurationStatus_Rejected;
  15972. }
  15973. }
  15974. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  15975. {
  15976. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15977. {
  15978. strcpy(str, (const char*)value);
  15979. for(int i = 0; str[i]; i++)
  15980. {
  15981. str[i] = tolower(str[i]);
  15982. }
  15983. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15984. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15985. isSuccess = ConfigurationStatus_Accepted;
  15986. }
  15987. else
  15988. {
  15989. isSuccess = ConfigurationStatus_Rejected;
  15990. }
  15991. }
  15992. if(strcmp(key, "WebSocketPingInterval") == 0)
  15993. {
  15994. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15995. {
  15996. check_ascii = value[0];
  15997. if( (check_ascii < 48) || (check_ascii > 57) )
  15998. {
  15999. isSuccess = ConfigurationStatus_Rejected;
  16000. }
  16001. else
  16002. {
  16003. if((atoi(value) == 0) || (atoi(value) >= 10))
  16004. {
  16005. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16006. isSuccess = ConfigurationStatus_Accepted;
  16007. }
  16008. else
  16009. isSuccess = ConfigurationStatus_Rejected;
  16010. }
  16011. }
  16012. else
  16013. {
  16014. isSuccess = ConfigurationStatus_Rejected;
  16015. }
  16016. }
  16017. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16018. {
  16019. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16020. {
  16021. strcpy(str, (const char*)value);
  16022. for(int i = 0; str[i]; i++)
  16023. {
  16024. str[i] = tolower(str[i]);
  16025. }
  16026. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16027. isSuccess = ConfigurationStatus_Accepted;
  16028. }
  16029. else
  16030. {
  16031. isSuccess = ConfigurationStatus_Rejected;
  16032. }
  16033. }
  16034. if(strcmp(key, "AuthorizationKey") == 0)
  16035. {
  16036. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16037. {
  16038. strcpy(str, (const char*)value);
  16039. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16040. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16041. isSuccess = ConfigurationStatus_Accepted;
  16042. }
  16043. else
  16044. {
  16045. isSuccess = ConfigurationStatus_Rejected;
  16046. }
  16047. }
  16048. if(strcmp(key, "SecurityProfile") == 0)
  16049. {
  16050. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16051. {
  16052. check_ascii = value[0];
  16053. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16054. {
  16055. isSuccess = ConfigurationStatus_Rejected;
  16056. }
  16057. else if(check_ascii == 0x33)
  16058. {
  16059. isSuccess = NotSupported;
  16060. }
  16061. else
  16062. {
  16063. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16064. {
  16065. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16066. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  16067. isSuccess = ConfigurationStatus_Accepted;
  16068. }
  16069. else
  16070. isSuccess = ConfigurationStatus_Rejected;
  16071. }
  16072. }
  16073. else
  16074. {
  16075. isSuccess = ConfigurationStatus_Rejected;
  16076. }
  16077. }
  16078. if(strcmp(key, "DefaultPrice") == 0)
  16079. {
  16080. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16081. {
  16082. strcpy(str, (const char*)value);
  16083. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16084. isSuccess = ConfigurationStatus_Accepted;
  16085. }
  16086. else
  16087. {
  16088. isSuccess = ConfigurationStatus_Rejected;
  16089. }
  16090. }
  16091. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16092. {
  16093. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16094. {
  16095. strcpy(str, (const char*)value);
  16096. for(int i = 0; str[i]; i++)
  16097. {
  16098. str[i] = tolower(str[i]);
  16099. }
  16100. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16101. isSuccess = ConfigurationStatus_Accepted;
  16102. }
  16103. else
  16104. {
  16105. isSuccess = ConfigurationStatus_Rejected;
  16106. }
  16107. }
  16108. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16109. {
  16110. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16111. {
  16112. strcpy(str, (const char*)value);
  16113. for(int i = 0; str[i]; i++)
  16114. {
  16115. str[i] = tolower(str[i]);
  16116. }
  16117. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16118. isSuccess = ConfigurationStatus_Accepted;
  16119. }
  16120. else
  16121. {
  16122. isSuccess = ConfigurationStatus_Rejected;
  16123. }
  16124. }
  16125. if(strcmp(key, "TimeOffset") == 0)
  16126. {
  16127. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16128. {
  16129. strcpy(str, (const char*)value);
  16130. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  16131. isSuccess = ConfigurationStatus_Accepted;
  16132. }
  16133. else
  16134. {
  16135. isSuccess = ConfigurationStatus_Rejected;
  16136. }
  16137. }
  16138. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  16139. {
  16140. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  16141. {
  16142. strcpy(str, (const char*)value);
  16143. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  16144. isSuccess = ConfigurationStatus_Accepted;
  16145. }
  16146. else
  16147. {
  16148. isSuccess = ConfigurationStatus_Rejected;
  16149. }
  16150. }
  16151. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  16152. {
  16153. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  16154. {
  16155. strcpy(str, (const char*)value);
  16156. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  16157. isSuccess = ConfigurationStatus_Accepted;
  16158. }
  16159. else
  16160. {
  16161. isSuccess = ConfigurationStatus_Rejected;
  16162. }
  16163. }
  16164. if(strcmp(key, "SystemUptimeSec") == 0)
  16165. {
  16166. isSuccess = NotSupported;
  16167. }
  16168. if(strcmp(key, "FreeVend") == 0)
  16169. {
  16170. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16171. {
  16172. strcpy(str, (const char*)value);
  16173. for(int i = 0; str[i]; i++)
  16174. {
  16175. str[i] = tolower(str[i]);
  16176. }
  16177. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16178. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16179. isSuccess = ConfigurationStatus_Accepted;
  16180. }
  16181. else
  16182. {
  16183. isSuccess = ConfigurationStatus_Rejected;
  16184. }
  16185. }
  16186. #if 0
  16187. //For OCPP Test Case
  16188. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16189. {
  16190. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16191. {
  16192. strcpy(str, (const char*)value);
  16193. for(int i = 0; str[i]; i++)
  16194. {
  16195. str[i] = tolower(str[i]);
  16196. }
  16197. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16198. isSuccess = ConfigurationStatus_Accepted;
  16199. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16200. }
  16201. else
  16202. {
  16203. isSuccess = ConfigurationStatus_Rejected;
  16204. }
  16205. }
  16206. #endif
  16207. #if 1
  16208. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16209. {
  16210. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16211. {
  16212. strcpy(str, (const char*)value);
  16213. for(int i = 0; str[i]; i++)
  16214. {
  16215. str[i] = tolower(str[i]);
  16216. }
  16217. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16218. isSuccess = ConfigurationStatus_Accepted;
  16219. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16220. }
  16221. else
  16222. {
  16223. isSuccess = ConfigurationStatus_Rejected;
  16224. }
  16225. }
  16226. #endif
  16227. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16228. {
  16229. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16230. {
  16231. check_ascii = value[0];
  16232. if( (check_ascii < 48) || (check_ascii > 57) )
  16233. {
  16234. isSuccess = ConfigurationStatus_Rejected;
  16235. }
  16236. else
  16237. {
  16238. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16239. isSuccess = ConfigurationStatus_Accepted;
  16240. }
  16241. }
  16242. else
  16243. {
  16244. isSuccess = ConfigurationStatus_Rejected;
  16245. }
  16246. }
  16247. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16248. {
  16249. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16250. {
  16251. check_ascii = value[0];
  16252. if( (check_ascii < 48) || (check_ascii > 57) )
  16253. {
  16254. isSuccess = ConfigurationStatus_Rejected;
  16255. }
  16256. else
  16257. {
  16258. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16259. isSuccess = ConfigurationStatus_Accepted;
  16260. }
  16261. }
  16262. else
  16263. {
  16264. isSuccess = ConfigurationStatus_Rejected;
  16265. }
  16266. }
  16267. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16268. {
  16269. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16270. {
  16271. strcpy(str, (const char*)value);
  16272. for(int i = 0; str[i]; i++)
  16273. {
  16274. str[i] = tolower(str[i]);
  16275. }
  16276. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16277. isSuccess = ConfigurationStatus_Accepted;
  16278. }
  16279. else
  16280. {
  16281. isSuccess = ConfigurationStatus_Rejected;
  16282. }
  16283. }
  16284. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16285. {
  16286. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16287. {
  16288. check_ascii = value[0];
  16289. if( (check_ascii < 48) || (check_ascii > 57) )
  16290. {
  16291. isSuccess = ConfigurationStatus_Rejected;
  16292. }
  16293. else
  16294. {
  16295. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16296. isSuccess = ConfigurationStatus_Accepted;
  16297. }
  16298. }
  16299. else
  16300. {
  16301. isSuccess = ConfigurationStatus_Rejected;
  16302. }
  16303. }
  16304. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16305. {
  16306. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16307. {
  16308. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16309. isSuccess = ConfigurationStatus_Accepted;
  16310. }
  16311. else
  16312. {
  16313. isSuccess = ConfigurationStatus_Rejected;
  16314. }
  16315. }
  16316. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16317. {
  16318. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16319. {
  16320. check_ascii = value[0];
  16321. if( (check_ascii < 48) || (check_ascii > 57) )
  16322. {
  16323. isSuccess = ConfigurationStatus_Rejected;
  16324. }
  16325. else
  16326. {
  16327. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16328. isSuccess = ConfigurationStatus_Accepted;
  16329. }
  16330. }
  16331. else
  16332. {
  16333. isSuccess = ConfigurationStatus_Rejected;
  16334. }
  16335. }
  16336. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16337. {
  16338. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16339. {
  16340. strcpy(str, (const char*)value);
  16341. for(int i = 0; str[i]; i++)
  16342. {
  16343. str[i] = tolower(str[i]);
  16344. }
  16345. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16346. isSuccess = ConfigurationStatus_Accepted;
  16347. }
  16348. else
  16349. {
  16350. isSuccess = ConfigurationStatus_Rejected;
  16351. }
  16352. }
  16353. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16354. {
  16355. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16356. {
  16357. check_ascii = value[0];
  16358. if( (check_ascii < 48) || (check_ascii > 57) )
  16359. {
  16360. isSuccess = ConfigurationStatus_Rejected;
  16361. }
  16362. else
  16363. {
  16364. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16365. isSuccess = ConfigurationStatus_Accepted;
  16366. }
  16367. }
  16368. else
  16369. {
  16370. isSuccess = ConfigurationStatus_Rejected;
  16371. }
  16372. }
  16373. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16374. return isSuccess;
  16375. }
  16376. int TransactionMessageAttemptsGet(void)
  16377. {
  16378. return TransactionMessageAttemptsValue;
  16379. }
  16380. int FirstHeartBeatResponse(void)
  16381. {
  16382. return FirstHeartBeat;
  16383. }
  16384. int TransactionMessageRetryIntervalGet(void)
  16385. {
  16386. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16387. }
  16388. int ReadHttpStatus(int sock)
  16389. {
  16390. //char c;
  16391. char buff[1024]="",*ptr=buff+1;
  16392. int bytes_received, status;
  16393. DEBUG_INFO("Begin Response ..\n");
  16394. while((bytes_received = recv(sock, ptr, 1, 0))){
  16395. if(bytes_received==-1){
  16396. perror("ReadHttpStatus");
  16397. exit(1);
  16398. }
  16399. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16400. ptr++;
  16401. }
  16402. *ptr=0;
  16403. ptr=buff+1;
  16404. sscanf(ptr,"%*s %d ", &status);
  16405. DEBUG_INFO("%s\n",ptr);
  16406. DEBUG_INFO("status=%d\n",status);
  16407. DEBUG_INFO("End Response ..\n");
  16408. return (bytes_received>0)?status:0;
  16409. }
  16410. //the only filed that it parsed is 'Content-Length'
  16411. int ParseHeader(int sock)
  16412. {
  16413. //char c;
  16414. char buff[1024]="",*ptr=buff+4;
  16415. int bytes_received;
  16416. DEBUG_INFO("Begin HEADER ..\n");
  16417. while((bytes_received = recv(sock, ptr, 1, 0))){
  16418. if(bytes_received==-1){
  16419. perror("Parse Header");
  16420. exit(1);
  16421. }
  16422. if(
  16423. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16424. (ptr[-1]=='\r') && (*ptr=='\n' )
  16425. ) break;
  16426. ptr++;
  16427. }
  16428. *ptr=0;
  16429. ptr=buff+4;
  16430. //printf("%s",ptr);
  16431. if(bytes_received){
  16432. ptr=strstr(ptr,"Content-Length:");
  16433. if(ptr){
  16434. sscanf(ptr,"%*s %d",&bytes_received);
  16435. }else
  16436. bytes_received=-1; //unknown size
  16437. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16438. }
  16439. DEBUG_INFO("End HEADER ..\n");
  16440. return bytes_received ;
  16441. }
  16442. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16443. {
  16444. int result = TRUE;
  16445. char rmFileCmd[100]={0};
  16446. char FilePath[100]={0};
  16447. char ftpbuf[200];
  16448. int systemresult;
  16449. sprintf(FilePath,"/mnt/%s",filename);
  16450. system("ping 8.8.8.8 &");
  16451. if((access(FilePath,F_OK))!=-1)
  16452. {
  16453. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16454. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16455. system(rmFileCmd);
  16456. }
  16457. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16458. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16459. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16460. systemresult = system(ftpbuf);
  16461. if(systemresult != 0)
  16462. {
  16463. DEBUG_INFO("http DownLoad error!\n");
  16464. result = FALSE;
  16465. }
  16466. system("pkill ping");
  16467. return result;
  16468. }
  16469. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16470. {
  16471. int result = TRUE;
  16472. char rmFileCmd[100]={0};
  16473. char FilePath[100]={0};
  16474. char ftpbuf[200];
  16475. int systemresult;
  16476. sprintf(FilePath,"/mnt/%s",filename);
  16477. system("ping 8.8.8.8 &");
  16478. if((access(FilePath,F_OK))!=-1)
  16479. {
  16480. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16481. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16482. system(rmFileCmd);
  16483. }
  16484. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16485. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16486. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16487. systemresult = system(ftpbuf);
  16488. if(systemresult != 0)
  16489. {
  16490. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16491. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16492. systemresult = system(ftpbuf);
  16493. if(systemresult != 0)
  16494. {
  16495. DEBUG_WARN("wget error!\n");
  16496. result = FALSE;
  16497. }
  16498. }
  16499. system("pkill ping");
  16500. return result;
  16501. }
  16502. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16503. {
  16504. char rmFileCmd[100]={0};
  16505. char FilePath[100]={0};
  16506. char buf[512];
  16507. int systemresult = 0;
  16508. //DEBUG_INFO("filename=%s\n",filename);
  16509. //DEBUG_INFO("url=%s\n",url);
  16510. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16511. if((access(FilePath,F_OK))!=-1)
  16512. {
  16513. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16514. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16515. system(rmFileCmd);
  16516. }
  16517. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16518. if(fp == NULL)
  16519. {
  16520. DEBUG_INFO("log is NULL\n");
  16521. return FALSE;
  16522. }
  16523. else
  16524. {
  16525. fprintf(fp, "%s\n", url);
  16526. fprintf(fp, "%s\n", filename);
  16527. fclose(fp);
  16528. }
  16529. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16530. if(phpFP == NULL)
  16531. {
  16532. DEBUG_INFO("PHP upload fail.\n");
  16533. return FALSE;
  16534. }
  16535. else
  16536. {
  16537. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16538. {
  16539. if(strstr(buf, "result") != NULL)
  16540. {
  16541. sscanf(buf, "result: %d", &systemresult);
  16542. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16543. }
  16544. }
  16545. pclose(phpFP);
  16546. }
  16547. if(systemresult != 1)
  16548. {
  16549. DEBUG_INFO("HTTP upload error!\n");
  16550. return FALSE;
  16551. }
  16552. return TRUE;
  16553. }
  16554. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16555. {
  16556. int result = FALSE;
  16557. char ftpbuf[200];
  16558. int systemresult;
  16559. /*
  16560. // Domaind name transfer to IP address
  16561. struct hostent* server;
  16562. char *IPbuffer;
  16563. server = gethostbyname(location);
  16564. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16565. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16566. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16567. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16568. systemresult = system(ftpbuf);
  16569. if(systemresult != 0)
  16570. {
  16571. DEBUG_INFO("ftpput error!\n");
  16572. }
  16573. else
  16574. {
  16575. result = TRUE;
  16576. DEBUG_INFO("ftpput OK!\n");
  16577. }
  16578. return result;
  16579. }
  16580. int GetOcppServerURL()
  16581. {
  16582. int result = FALSE;
  16583. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16584. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16585. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16586. struct yuarel url;
  16587. char urlStr[512];
  16588. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  16589. {
  16590. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  16591. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16592. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16593. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  16594. if(yuarel_parse(&url, urlStr) != -1)
  16595. {
  16596. sprintf(OcppProtocol, "%s", url.scheme);
  16597. sprintf(OcppHost, "%s", url.host);
  16598. if(url.path == NULL)
  16599. OcppTempPath[0] = '\0';
  16600. else
  16601. {
  16602. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  16603. {
  16604. sprintf(OcppTempPath, "%s/", url.path);
  16605. }
  16606. else
  16607. {
  16608. sprintf(OcppTempPath, "%s", url.path);
  16609. }
  16610. }
  16611. if(url.port == 0)
  16612. {
  16613. if(strcmp(OcppProtocol, "wss") == 0)
  16614. OcppPort = 443;
  16615. else
  16616. OcppPort = 80;
  16617. }
  16618. else
  16619. OcppPort = url.port;
  16620. result = TRUE;
  16621. }
  16622. }
  16623. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  16624. {
  16625. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  16626. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16627. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16628. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  16629. if(yuarel_parse(&url, urlStr) != -1)
  16630. {
  16631. sprintf(OcppProtocol, "%s", url.scheme);
  16632. sprintf(OcppHost, "%s", url.host);
  16633. if(url.path == NULL)
  16634. OcppTempPath[0] = '\0';
  16635. else
  16636. sprintf(OcppTempPath, "%s", url.path);
  16637. if(url.port == 0)
  16638. {
  16639. if(strcmp(OcppProtocol, "wss") == 0)
  16640. OcppPort = 443;
  16641. else
  16642. OcppPort = 80;
  16643. }
  16644. else
  16645. OcppPort = url.port;
  16646. result = TRUE;
  16647. }
  16648. }
  16649. else
  16650. {
  16651. strcpy(OcppHost,"");
  16652. }
  16653. return result;
  16654. }
  16655. int GetOcppPath()
  16656. {
  16657. int result = FALSE;
  16658. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  16659. {
  16660. if(OcppTempPath == NULL)
  16661. {
  16662. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16663. }
  16664. else
  16665. {
  16666. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16667. }
  16668. result = TRUE;
  16669. goto End;
  16670. }
  16671. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  16672. {
  16673. if(OcppTempPath == NULL)
  16674. {
  16675. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  16676. }
  16677. else
  16678. {
  16679. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  16680. }
  16681. result = TRUE;
  16682. goto End;
  16683. }
  16684. else
  16685. {
  16686. strcpy(OcppPath,"");
  16687. }
  16688. End:
  16689. return result;
  16690. }
  16691. int GetOcppPort()
  16692. {
  16693. return OcppPort;
  16694. }
  16695. int GetOcppConnStatus(void)
  16696. {
  16697. return ShmOCPP16Data->OcppConnStatus;
  16698. }
  16699. void SetOcppConnStatus(uint8_t status)
  16700. {
  16701. ShmOCPP16Data->OcppConnStatus = status;
  16702. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  16703. }
  16704. int GetHeartBeatWithNOResponse(void)
  16705. {
  16706. return HeartBeatWithNOResponse;
  16707. }
  16708. void SetHeartBeatWithNOResponse(void)
  16709. {
  16710. HeartBeatWithNOResponse = 0;
  16711. }
  16712. void GetStartTransactionIdTag(int gun_index)
  16713. {
  16714. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  16715. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  16716. }
  16717. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  16718. {
  16719. char ch;
  16720. FILE *fptr1;
  16721. int temptransactionId;
  16722. char str[100]={0};
  16723. temptransactionId = 0;
  16724. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  16725. {
  16726. DEBUG_INFO("IdTag is empty.\n");
  16727. return temptransactionId;
  16728. }
  16729. /*------ Read the file ----------------*/
  16730. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  16731. if (!fptr1)
  16732. {
  16733. DEBUG_INFO("QueueTransactionId file open error.\n");
  16734. //printf(" File not found or unable to open the input file!!\n");
  16735. return temptransactionId;
  16736. }
  16737. ch=fgetc(fptr1);
  16738. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  16739. rewind(fptr1);
  16740. if(ch!=EOF)
  16741. {
  16742. // printf("%c",ch);
  16743. while (fgets(str, 100, fptr1) != NULL)
  16744. {
  16745. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16746. if(str[0]=='\0')
  16747. {
  16748. break;
  16749. }
  16750. char *revbuf[8] = {0}; // Variable store string split
  16751. int num = 0;// Quantity after string split
  16752. DEBUG_INFO("Transaction queue data= %s\n", str);
  16753. splitstring(str,",",revbuf,&num); // String split
  16754. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  16755. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  16756. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  16757. DEBUG_INFO("------------------------------\n");
  16758. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  16759. {
  16760. if(isStopTransaction)
  16761. {
  16762. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  16763. {
  16764. temptransactionId = atoi(revbuf[2]);
  16765. //break;
  16766. }
  16767. }
  16768. else
  16769. {
  16770. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  16771. {
  16772. temptransactionId = atoi(revbuf[2]);
  16773. //break;
  16774. }
  16775. }
  16776. }
  16777. }
  16778. }
  16779. else
  16780. DEBUG_INFO("EOF\n");
  16781. fclose(fptr1);
  16782. /*------- End of reading ---------------*/
  16783. return temptransactionId;
  16784. }
  16785. void SetTransactionIdZero(int transactionId)
  16786. {
  16787. char ch;
  16788. FILE *fptr1, *fptr2;
  16789. int temptransactionId = 0;
  16790. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  16791. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  16792. if (!fptr1)
  16793. {
  16794. //printf(" File not found or unable to open the input file!!\n");
  16795. return ;
  16796. }
  16797. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  16798. if (!fptr2)
  16799. {
  16800. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  16801. fclose(fptr1);
  16802. return ;
  16803. }
  16804. ch=fgetc(fptr1);
  16805. rewind(fptr1);
  16806. if(ch!=EOF)
  16807. {
  16808. // copy all contents to the temporary file except the specific line
  16809. while (fgets(str, 100, fptr1) != NULL)
  16810. {
  16811. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16812. if(str[0]=='\0')
  16813. {
  16814. break;
  16815. }
  16816. char *revbuf[8] = {0};
  16817. int num = 0;
  16818. strcpy(strtemp, str);
  16819. splitstring(str,",",revbuf,&num);
  16820. if(revbuf[2][0] != '\0')
  16821. {
  16822. temptransactionId = atoi(revbuf[2]);
  16823. if(transactionId != temptransactionId)
  16824. {
  16825. fprintf(fptr2, "%s\n", strtemp);
  16826. }
  16827. }
  16828. }
  16829. }
  16830. fclose(fptr1);
  16831. fclose(fptr2);
  16832. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  16833. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  16834. /*------ Read the file ----------------*/
  16835. }
  16836. int InternetDisconnect(void)
  16837. {
  16838. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  16839. }
  16840. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  16841. void storeTempStopTransaction(int gun_index)
  16842. {
  16843. char guid[37]={0};
  16844. int tempIndex = 0;
  16845. char TempStopTransaction[256];
  16846. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  16847. DEBUG_INFO("storeTempStopTransaction...\n");
  16848. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  16849. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  16850. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  16851. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16852. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16853. {
  16854. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16855. {
  16856. tempIndex = ((gun_index==2) ? 1: 0);
  16857. }
  16858. else
  16859. {
  16860. tempIndex = gun_index;
  16861. }
  16862. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16863. {
  16864. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16865. {
  16866. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  16867. }
  16868. }// END OF CHAdeMO_QUANTITY
  16869. }
  16870. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16871. {
  16872. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16873. {
  16874. tempIndex = ((gun_index==2) ? 1: 0);
  16875. }
  16876. else
  16877. {
  16878. tempIndex = gun_index;
  16879. }
  16880. for (int index = 0; index < CCS_QUANTITY; index++)
  16881. {
  16882. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16883. {
  16884. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  16885. }
  16886. }// END OF CCS_QUANTITY
  16887. }
  16888. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16889. {
  16890. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16891. {
  16892. tempIndex = ((gun_index==2) ? 1: 0);
  16893. }
  16894. else
  16895. {
  16896. tempIndex = gun_index;
  16897. }
  16898. for (int index = 0; index < GB_QUANTITY; index++)
  16899. {
  16900. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16901. {
  16902. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  16903. }
  16904. }// END OF GB_QUANTITY
  16905. }
  16906. else if(gunType[gun_index] == GUN_TYPE_DO)
  16907. {
  16908. tempIndex = gun_index;
  16909. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16910. {
  16911. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16912. {
  16913. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  16914. }
  16915. }
  16916. }
  16917. else
  16918. {
  16919. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16920. {
  16921. tempIndex = 2;
  16922. }
  16923. else
  16924. {
  16925. tempIndex = gun_index;
  16926. }
  16927. for (int index = 0; index < AC_QUANTITY; index++)
  16928. {
  16929. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16930. {
  16931. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  16932. }
  16933. }// END OF AC_QUANTITY
  16934. }
  16935. //Stop Transaction Time
  16936. struct timeval tmnow;
  16937. struct tm *tm;
  16938. char buf[28];//, usec_buf[6];
  16939. gettimeofday(&tmnow, NULL);
  16940. time_t t;
  16941. t = time(NULL);
  16942. /*UTC time and date*/
  16943. tm = gmtime(&t);
  16944. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  16945. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  16946. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  16947. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  16948. random_uuid(guid);
  16949. /***********************************transactionData******************************************************/
  16950. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  16951. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  16952. //=================================
  16953. //1. Transaction_Begin
  16954. //=================================
  16955. //============================== Energy.Active.Import.Interval ===========================================
  16956. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16957. {
  16958. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  16959. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16960. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  16961. 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*/]);
  16962. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16963. 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))
  16964. {
  16965. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  16966. }
  16967. else
  16968. {
  16969. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  16970. }
  16971. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  16972. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16973. }
  16974. //=================================
  16975. //2. Transaction_End
  16976. //=================================
  16977. //2.1====================================== Current.Import L1 ==============================================
  16978. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16979. {
  16980. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  16981. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16982. {
  16983. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16984. {
  16985. tempIndex = ((gun_index==2) ? 1: 0);
  16986. }
  16987. else
  16988. {
  16989. tempIndex = gun_index;
  16990. }
  16991. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16992. {
  16993. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16994. {
  16995. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16996. }
  16997. }// End of for CHAdeMO_QUANTITY
  16998. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16999. }
  17000. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17001. {
  17002. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17003. {
  17004. tempIndex = ((gun_index==2) ? 1: 0);
  17005. }
  17006. else
  17007. {
  17008. tempIndex = gun_index;
  17009. }
  17010. for (int index = 0; index < CCS_QUANTITY; index++)
  17011. {
  17012. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17013. {
  17014. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17015. }
  17016. }// End of for CCS_QUANTITY
  17017. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17018. }
  17019. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17020. {
  17021. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17022. {
  17023. tempIndex = ((gun_index==2) ? 1: 0);
  17024. }
  17025. else
  17026. {
  17027. tempIndex = gun_index;
  17028. }
  17029. for (int index = 0; index < GB_QUANTITY; index++)
  17030. {
  17031. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17032. {
  17033. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17034. }
  17035. }// End of for GB_QUANTITY
  17036. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17037. }
  17038. else if(gunType[gun_index] == GUN_TYPE_DO)
  17039. {
  17040. tempIndex = gun_index;
  17041. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17042. {
  17043. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17044. {
  17045. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17046. }
  17047. }
  17048. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17049. }
  17050. else
  17051. {
  17052. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17053. {
  17054. tempIndex = 2;
  17055. }
  17056. else
  17057. {
  17058. tempIndex = gun_index;
  17059. }
  17060. for (int index = 0; index < AC_QUANTITY; index++)
  17061. {
  17062. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17063. {
  17064. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17065. }
  17066. }// End of for AC_QUANTITY
  17067. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17068. }
  17069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17070. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17071. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17072. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17073. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17074. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17075. }
  17076. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17077. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17078. {
  17079. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17080. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17081. {
  17082. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17083. {
  17084. tempIndex = ((gun_index==2) ? 1: 0);
  17085. }
  17086. else
  17087. {
  17088. tempIndex = gun_index;
  17089. }
  17090. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17091. {
  17092. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17093. {
  17094. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17095. }
  17096. }// END OF CHAdeMO_QUANTITY
  17097. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17098. }
  17099. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17100. {
  17101. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17102. {
  17103. tempIndex = ((gun_index==2) ? 1: 0);
  17104. }
  17105. else
  17106. {
  17107. tempIndex = gun_index;
  17108. }
  17109. for (int index = 0; index < CCS_QUANTITY; index++)
  17110. {
  17111. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17112. {
  17113. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17114. }
  17115. }// END OF CCS_QUANTITY
  17116. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17117. }
  17118. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17119. {
  17120. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17121. {
  17122. tempIndex = ((gun_index==2) ? 1: 0);
  17123. }
  17124. else
  17125. {
  17126. tempIndex = gun_index;
  17127. }
  17128. for (int index = 0; index < GB_QUANTITY; index++)
  17129. {
  17130. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17131. {
  17132. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17133. }
  17134. }// END OF GB_QUANTITY
  17135. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17136. }
  17137. else if(gunType[gun_index] == GUN_TYPE_DO)
  17138. {
  17139. tempIndex = gun_index;
  17140. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17141. {
  17142. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17143. {
  17144. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17145. }
  17146. }
  17147. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17148. }
  17149. else
  17150. {
  17151. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17152. {
  17153. tempIndex = 2;
  17154. }
  17155. else
  17156. {
  17157. tempIndex = gun_index;
  17158. }
  17159. for (int index = 0; index < AC_QUANTITY; index++)
  17160. {
  17161. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17162. {
  17163. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17164. }
  17165. }// END OF AC_QUANTITY
  17166. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17167. }
  17168. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17169. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17170. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17171. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17172. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17173. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17174. }
  17175. //2.3====================================== Power.Active.Import =========================================
  17176. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17177. {
  17178. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17179. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17180. {
  17181. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17182. {
  17183. tempIndex = ((gun_index==2) ? 1: 0);
  17184. }
  17185. else
  17186. {
  17187. tempIndex = gun_index;
  17188. }
  17189. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17190. {
  17191. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17192. {
  17193. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17194. }
  17195. } // End for CHAdeMO_QUANTITY
  17196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17197. }
  17198. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17199. {
  17200. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17201. {
  17202. tempIndex = ((gun_index==2) ? 1: 0);
  17203. }
  17204. else
  17205. {
  17206. tempIndex = gun_index;
  17207. }
  17208. for (int index = 0; index < CCS_QUANTITY; index++)
  17209. {
  17210. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17211. {
  17212. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17213. }
  17214. } // END for CCS_QUANTITY
  17215. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17216. }
  17217. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17218. {
  17219. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17220. {
  17221. tempIndex = ((gun_index==2) ? 1: 0);
  17222. }
  17223. else
  17224. {
  17225. tempIndex = gun_index;
  17226. }
  17227. for (int index = 0; index < GB_QUANTITY; index++)
  17228. {
  17229. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17230. {
  17231. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17232. }
  17233. }// END for GB_QUANTITY
  17234. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17235. }
  17236. else if(gunType[gun_index] == GUN_TYPE_DO)
  17237. {
  17238. tempIndex = gun_index;
  17239. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17240. {
  17241. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17242. {
  17243. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17244. }
  17245. }
  17246. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17247. }
  17248. else
  17249. {
  17250. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17251. {
  17252. tempIndex = 2;
  17253. }
  17254. else
  17255. {
  17256. tempIndex = gun_index;
  17257. }
  17258. for (int index = 0; index < AC_QUANTITY; index++)
  17259. {
  17260. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17261. {
  17262. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17263. }
  17264. } // END for AC_QUANTITY
  17265. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17266. }
  17267. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17268. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17269. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17270. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17271. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17272. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17273. }
  17274. //2.4====================================== Voltage L1 ====================================================
  17275. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17276. {
  17277. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17278. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17279. {
  17280. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17281. {
  17282. tempIndex = ((gun_index==2) ? 1: 0);
  17283. }
  17284. else
  17285. {
  17286. tempIndex = gun_index;
  17287. }
  17288. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17289. {
  17290. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17291. {
  17292. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17293. }
  17294. } // END OF FOR CHAdeMO_QUANTITY
  17295. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17296. }
  17297. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17298. {
  17299. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17300. {
  17301. tempIndex = ((gun_index==2) ? 1: 0);
  17302. }
  17303. else
  17304. {
  17305. tempIndex = gun_index;
  17306. }
  17307. for (int index = 0; index < CCS_QUANTITY; index++)
  17308. {
  17309. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17310. {
  17311. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17312. }
  17313. } // END OF FOR CCS_QUANTITY
  17314. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17315. }
  17316. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17317. {
  17318. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17319. {
  17320. tempIndex = ((gun_index==2) ? 1: 0);
  17321. }
  17322. else
  17323. {
  17324. tempIndex = gun_index;
  17325. }
  17326. for (int index = 0; index < GB_QUANTITY; index++)
  17327. {
  17328. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17329. {
  17330. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17331. }
  17332. } // END OF FOR GB_QUANTITY
  17333. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17334. }
  17335. else if(gunType[gun_index] == GUN_TYPE_DO)
  17336. {
  17337. tempIndex = gun_index;
  17338. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17339. {
  17340. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17341. {
  17342. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17343. }
  17344. }
  17345. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17346. }
  17347. else
  17348. {
  17349. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17350. {
  17351. tempIndex = 2;
  17352. }
  17353. else
  17354. {
  17355. tempIndex = gun_index;
  17356. }
  17357. for (int index = 0; index < AC_QUANTITY; index++)
  17358. {
  17359. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17360. {
  17361. 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
  17362. }
  17363. } // END OF FOR AC_QUANTITY
  17364. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17365. }
  17366. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17367. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17368. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17369. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17371. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17372. }
  17373. //2.5============================================== End SoC =========================================================
  17374. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17375. {
  17376. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17377. 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))
  17378. {
  17379. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17380. {
  17381. tempIndex = ((gun_index==2) ? 1: 0);
  17382. }
  17383. else
  17384. {
  17385. tempIndex = gun_index;
  17386. }
  17387. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17388. {
  17389. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17390. {
  17391. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17392. {
  17393. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17394. }
  17395. }
  17396. }
  17397. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17398. {
  17399. for (int index = 0; index < CCS_QUANTITY; index++)
  17400. {
  17401. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17402. {
  17403. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17404. }
  17405. }
  17406. }
  17407. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17408. {
  17409. for (int index = 0; index < GB_QUANTITY; index++)
  17410. {
  17411. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17412. {
  17413. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17414. }
  17415. }
  17416. }
  17417. else if(gunType[gun_index] == GUN_TYPE_DO)
  17418. {
  17419. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17420. {
  17421. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17422. {
  17423. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17424. }
  17425. }
  17426. }
  17427. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17428. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17429. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17430. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17431. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17432. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17433. } // END FOR DC CASE
  17434. }
  17435. //2.6====================================== Current.Import L2 ==============================================
  17436. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17437. {
  17438. // AC 3 phase L2 current
  17439. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17440. {
  17441. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17442. {
  17443. tempIndex = 2;
  17444. }
  17445. else
  17446. {
  17447. tempIndex = gun_index;
  17448. }
  17449. for (int index = 0; index < AC_QUANTITY; index++)
  17450. {
  17451. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17452. {
  17453. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17454. }
  17455. }// End of for AC_QUANTITY
  17456. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17457. }
  17458. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17459. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17461. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17462. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17463. }
  17464. //2.7====================================== Current.Import L3 ==============================================
  17465. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17466. {
  17467. // AC 3 phase L3 current
  17468. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17469. {
  17470. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17471. {
  17472. tempIndex = 2;
  17473. }
  17474. else
  17475. {
  17476. tempIndex = gun_index;
  17477. }
  17478. for (int index = 0; index < AC_QUANTITY; index++)
  17479. {
  17480. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17481. {
  17482. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17483. }
  17484. }// End of for AC_QUANTITY
  17485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17486. }
  17487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17488. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17489. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17490. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17491. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17492. }
  17493. //2.9====================================== Voltage L2 ====================================================
  17494. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17495. {
  17496. // AC 3 phase L2 volatge
  17497. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17498. {
  17499. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17500. {
  17501. tempIndex = 2;
  17502. }
  17503. else
  17504. {
  17505. tempIndex = gun_index;
  17506. }
  17507. for (int index = 0; index < AC_QUANTITY; index++)
  17508. {
  17509. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17510. {
  17511. 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
  17512. }
  17513. } // END OF FOR AC_QUANTITY
  17514. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  17515. }
  17516. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17517. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17518. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17519. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17520. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17521. }
  17522. //2.10====================================== Voltage L3 ====================================================
  17523. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17524. {
  17525. // AC 3 phase L3 volatge
  17526. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17527. {
  17528. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17529. {
  17530. tempIndex = 2;
  17531. }
  17532. else
  17533. {
  17534. tempIndex = gun_index;
  17535. }
  17536. for (int index = 0; index < AC_QUANTITY; index++)
  17537. {
  17538. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17539. {
  17540. 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
  17541. }
  17542. } // END OF FOR AC_QUANTITY
  17543. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  17544. }
  17545. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17546. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  17547. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  17548. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  17549. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17550. }
  17551. //====================== Start SoC ================================
  17552. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17553. {
  17554. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17555. 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))
  17556. {
  17557. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17558. {
  17559. tempIndex = ((gun_index==2) ? 1: 0);
  17560. }
  17561. else
  17562. {
  17563. tempIndex = gun_index;
  17564. }
  17565. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17566. {
  17567. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17568. {
  17569. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17570. {
  17571. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  17572. }
  17573. }
  17574. }
  17575. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17576. {
  17577. for (int index = 0; index < CCS_QUANTITY; index++)
  17578. {
  17579. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17580. {
  17581. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  17582. }
  17583. }
  17584. }
  17585. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17586. {
  17587. for (int index = 0; index < GB_QUANTITY; index++)
  17588. {
  17589. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17590. {
  17591. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  17592. }
  17593. }
  17594. }
  17595. else if(gunType[gun_index] == GUN_TYPE_DO)
  17596. {
  17597. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17598. {
  17599. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17600. {
  17601. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  17602. }
  17603. }
  17604. }
  17605. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17606. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  17607. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17608. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  17609. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  17610. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17611. } // END FOR DC CASE
  17612. }
  17613. //======================================== Message create ==============================================
  17614. json_object *StopTransaction = json_object_new_object();
  17615. json_object *transactionDatas = json_object_new_array();
  17616. json_object *sampledValues = json_object_new_array();
  17617. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  17618. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  17619. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  17620. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  17621. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  17622. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  17623. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  17624. {
  17625. json_object *transactionData = json_object_new_object();
  17626. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  17627. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  17628. {
  17629. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  17630. {
  17631. json_object *sampledValue = json_object_new_object();
  17632. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  17633. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  17634. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  17635. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  17636. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  17637. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  17638. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  17639. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  17640. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  17641. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  17642. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  17643. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  17644. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  17645. json_object_array_add(sampledValues, sampledValue);
  17646. }
  17647. }
  17648. json_object_object_add(transactionData, "sampledValue", sampledValues);
  17649. json_object_array_add(transactionDatas, transactionData);
  17650. }
  17651. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  17652. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  17653. ,MESSAGE_TYPE_CALL
  17654. ,guid
  17655. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  17656. json_object_put(StopTransaction);
  17657. // Check File "TempStopTransaction" Exist
  17658. if((access(TempStopTransaction,F_OK))!=-1)
  17659. {
  17660. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  17661. fclose(fopen(TempStopTransaction, "w"));
  17662. }
  17663. else
  17664. {
  17665. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  17666. FILE *log = fopen(TempStopTransaction, "w+");
  17667. if(log == NULL)
  17668. {
  17669. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  17670. return ;
  17671. }
  17672. else
  17673. {
  17674. fclose(log);
  17675. }
  17676. }
  17677. //Add TempStopTransaction | Update TempStopTransaction
  17678. // open file for writing
  17679. FILE *outfile;
  17680. outfile = fopen (TempStopTransaction, "a");
  17681. //DEBUG_INFO("data = %s\n", queuedata);
  17682. fputs(queuedata, outfile);
  17683. fputs("\n", outfile);
  17684. fclose (outfile);
  17685. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17686. OCPP_updatePeriodEnergy(gun_index);
  17687. }
  17688. void checkTempStopTransaction(int gun_index)
  17689. {
  17690. FILE *fptr1;
  17691. char ch;
  17692. char str[QUEUE_MESSAGE_LENGTH]={0};
  17693. char guid[37]={0};
  17694. char tempdata[65]={0};
  17695. char connectorStr[2]={0};
  17696. char TempStopTransaction[256];
  17697. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  17698. fptr1 = fopen(TempStopTransaction, "r");
  17699. //TempStopTransaction格式: 槍號,StopTransaction封包
  17700. if (!fptr1)
  17701. {
  17702. //printf(" File not found or unable to open the input file!!\n");
  17703. return ;
  17704. }
  17705. ch=fgetc(fptr1);
  17706. //printf(" Now the content of the file %s is : \n",fname);
  17707. rewind(fptr1);
  17708. if(ch!=EOF)
  17709. {
  17710. // copy all contents to the temporary file except the specific line
  17711. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  17712. {
  17713. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17714. if(str[0]=='\0')
  17715. {
  17716. break;
  17717. }
  17718. //TempStopTransaction格式: 槍號,StopTransaction封包
  17719. strncpy(connectorStr, str, 1);
  17720. if(atoi(connectorStr) != (gun_index+1))
  17721. {
  17722. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  17723. fclose(fptr1);
  17724. return ;
  17725. }
  17726. //random_uuid(guid);
  17727. strncpy(guid, str+6, 36); //copy guid
  17728. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  17729. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  17730. {
  17731. //DEBUG_INFO("StopTransaction mapitem pass\n");
  17732. }
  17733. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  17734. OCPP_insert_transaction_msg(NO, str);
  17735. memset(str,0,ARRAY_SIZE(str));
  17736. }
  17737. }
  17738. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  17739. fclose(fptr1);
  17740. remove(TempStopTransaction); // remove the original file
  17741. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17742. }
  17743. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  17744. {
  17745. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  17746. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  17747. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  17748. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  17749. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  17750. }
  17751. int GetWebSocketPingInterval(void)
  17752. {
  17753. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  17754. }
  17755. int GetServerSign(void)
  17756. {
  17757. return server_sign;
  17758. }
  17759. uint8_t GetOcppSecurityProfile()
  17760. {
  17761. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  17762. }
  17763. void GetOcppChargerBoxId(uint8_t *data)
  17764. {
  17765. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17766. }
  17767. void GetOcppSecurityPassword(uint8_t *data)
  17768. {
  17769. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17770. }
  17771. void SetOcppVersion(uint8_t *version)
  17772. {
  17773. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  17774. DEBUG_INFO("ocpp version: %s\n", version);
  17775. if(strstr((char*)version, "ocpp1.6") != NULL)
  17776. {
  17777. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  17778. }
  17779. else if(strstr((char*)version, "ocpp2.0") != NULL)
  17780. {
  17781. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  17782. system("pkill OcppBackend");
  17783. }
  17784. }
  17785. void SetServerSign(int value)
  17786. {
  17787. server_sign = value;
  17788. }
  17789. int GetBootNotificationInterval(void)
  17790. {
  17791. return BootNotificationInterval;
  17792. }
  17793. int GetInternetConn(void)
  17794. {
  17795. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  17796. }
  17797. int GetBackendConnectionTimeout(void)
  17798. {
  17799. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  17800. }
  17801. int isConnectorInitMode(int gun_index)
  17802. {
  17803. int tempIndex = 0;
  17804. int result = TRUE;
  17805. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17806. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17807. {
  17808. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17809. {
  17810. tempIndex = ((gun_index==2) ? 1: 0);
  17811. }
  17812. else
  17813. {
  17814. tempIndex = gun_index;
  17815. }
  17816. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17817. {
  17818. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  17819. {
  17820. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17821. } //end of the same index
  17822. }//end of for CHAdeMO_QUANTITY
  17823. }
  17824. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17825. {
  17826. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17827. {
  17828. tempIndex = ((gun_index==2) ? 1: 0);
  17829. }
  17830. else
  17831. {
  17832. tempIndex = gun_index;
  17833. }
  17834. for (int index = 0; index < CCS_QUANTITY; index++)
  17835. {
  17836. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17837. {
  17838. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17839. } //end of the same index
  17840. } // end of for CCS_QUANTITY
  17841. }
  17842. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17843. {
  17844. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17845. {
  17846. tempIndex = ((gun_index==2) ? 1: 0);
  17847. }
  17848. else
  17849. {
  17850. tempIndex = gun_index;
  17851. }
  17852. for (int index = 0; index < GB_QUANTITY; index++)
  17853. {
  17854. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17855. {
  17856. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17857. } //end of the same index
  17858. } // end of for GB_QUANTITY
  17859. }
  17860. else if(gunType[gun_index] == GUN_TYPE_DO)
  17861. {
  17862. tempIndex = gun_index;
  17863. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17864. {
  17865. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17866. {
  17867. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17868. } //end of the same index
  17869. }
  17870. }
  17871. else
  17872. {
  17873. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17874. {
  17875. tempIndex = 2;
  17876. }
  17877. else
  17878. {
  17879. tempIndex = gun_index;
  17880. }
  17881. for (int index = 0; index < AC_QUANTITY; index++)
  17882. {
  17883. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17884. {
  17885. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17886. }//end of the same index
  17887. }//end of for AC_QUANTITY
  17888. }
  17889. return result;
  17890. }
  17891. void refreshProcDogTimer()
  17892. {
  17893. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  17894. }
  17895. void InitialSystemValue(void)
  17896. {
  17897. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  17898. locallistVersion=0;
  17899. BootNotificationInterval = 0;
  17900. authorizeRetryTimes = 0;
  17901. GunStatusInterval = 10;
  17902. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  17903. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17904. //Hear Beat
  17905. HeartBeatWithNOResponse = 0;
  17906. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  17907. FirstHeartBeat = 0;
  17908. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  17909. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  17910. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  17911. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  17912. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  17913. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  17914. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  17915. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  17916. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  17917. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  17918. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  17919. //Status && ConnectorPlugIn Setting
  17920. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17921. {
  17922. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  17923. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  17924. }
  17925. for (int index = 0; index < CCS_QUANTITY; index++)
  17926. {
  17927. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  17928. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  17929. }
  17930. for (int index = 0; index < GB_QUANTITY; index++)
  17931. {
  17932. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  17933. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  17934. }
  17935. for (int index = 0; index < AC_QUANTITY; index++)
  17936. {
  17937. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  17938. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  17939. }
  17940. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17941. {
  17942. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  17943. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  17944. }
  17945. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  17946. {
  17947. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  17948. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  17949. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  17950. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  17951. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  17952. }
  17953. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  17954. refreshStartTimer(&clientTime.Heartbeat);
  17955. sleep(1);
  17956. }
  17957. void LWS_Send(char *str)
  17958. {
  17959. //=====================================================
  17960. // Check InternetConn 0: disconnected, 1: connected
  17961. //====================================================
  17962. if(GetOcppConnStatus() == 0)
  17963. {
  17964. DEBUG_INFO("offline now !!!\n");
  17965. return;
  17966. }
  17967. // Only disable isWebsocketSendable operation initiated by charger
  17968. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17969. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17970. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17971. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17972. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17973. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17974. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17975. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17976. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17977. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17978. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17979. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17980. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17981. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17982. {
  17983. isWebsocketSendable = 0;
  17984. }
  17985. pthread_mutex_lock(&lock_send);
  17986. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17987. sprintf((char *)SendBuffer, "%s", str);
  17988. SendBufLen = strlen(str);
  17989. pthread_mutex_unlock(&lock_send);
  17990. lws_callback_on_writable(wsi_client);
  17991. //lws_service(context, 0);
  17992. //sleep(1);
  17993. }
  17994. void LWS_SendNow(char *str)
  17995. {
  17996. //=====================================================
  17997. // Check InternetConn 0: disconnected, 1: connected
  17998. //====================================================
  17999. if(GetOcppConnStatus() == 0)
  18000. {
  18001. DEBUG_INFO("offline now !!!\n");
  18002. return;
  18003. }
  18004. // Only disable isWebsocketSendable operation initiated by charger
  18005. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18006. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18007. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18008. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18009. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18010. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18011. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18012. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18013. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18014. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18015. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18016. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18017. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18018. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18019. {
  18020. isWebsocketSendable = 0;
  18021. }
  18022. pthread_mutex_lock(&lock_send);
  18023. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18024. sprintf((char *)SendBuffer, "%s", str);
  18025. SendBufLen = strlen(str);
  18026. pthread_mutex_unlock(&lock_send);
  18027. lws_callback_on_writable(wsi_client);
  18028. lws_service(context, 0);
  18029. //sleep(1);
  18030. }